Skip to content

Commit

Permalink
feat(how-tos): add loggin support
Browse files Browse the repository at this point in the history
  • Loading branch information
bsorrentino committed Sep 6, 2024
1 parent 4e9a763 commit 27c7afd
Show file tree
Hide file tree
Showing 4 changed files with 121 additions and 68 deletions.
51 changes: 37 additions & 14 deletions how-tos/logging.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"execution_count": 8,
"metadata": {},
"outputs": [],
"source": [
"String userHomeDir = System.getProperty(\"user.home\");\n",
"String localRespoUrl = \"file://\" + userHomeDir + \"/.m2/repository/\";\n",
"String langchain4jVersion = \"0.33.0\""
"String slf4jVersion = \"2.0.9\""
]
},
{
Expand All @@ -28,28 +28,51 @@
"outputs": [],
"source": [
"%dependency /add org.bsc.langgraph4j:langgraph4j-core-jdk8:1.0-SNAPSHOT\n",
"%dependency /add dev.langchain4j:langchain4j:\\{langchain4jVersion}\n",
"%dependency /add dev.langchain4j:langchain4j-open-ai:\\{langchain4jVersion}\n",
"%dependency /add org.slf4j:slf4j-jdk14:\\{slf4jVersion}\n",
"\n",
"%dependency /resolve"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Initialize Logger "
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [],
"source": [
"var lm = java.util.logging.LogManager.getLogManager();\n",
"lm.checkAccess(); \n",
"try( var file = new java.io.FileInputStream(\"./logging.properties\")) {\n",
" lm.readConfiguration( file );\n",
" java.util.logging.Logger.getLogger(\"\").addHandler(new java.util.logging.ConsoleHandler());\n",
"}"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Test Logger"
]
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import java.io.FileInputStream;\n",
"import java.io.IOException;\n",
"import java.util.logging.LogManager;\n",
"import java.util.logging.Logger;\n",
"\n",
"try( FileInputStream configFile = new FileInputStream(\"./logging.properties\") ) {\n",
" var lm = LogManager.getLogManager();\n",
" lm.checkAccess();\n",
" lm.readConfiguration(configFile);\n",
"}\n"
"var log = org.slf4j.LoggerFactory.getLogger(org.bsc.langgraph4j.CompiledGraph.class);\n",
"\n",
"\n",
"log.trace( \"this is a trace message {}\", \"TRACE2\");\n",
"log.info( \"this is a info message {}\", \"INFO1\");\n"
]
}
],
Expand Down
13 changes: 8 additions & 5 deletions how-tos/logging.properties
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
# Set the default logging level to INFO
.level = INFO

# Set the logging level to FINER for the package a.b.c
org.bsc.langgraph4j.level = FINE
.level = SEVERE

# Specify the handlers that will handle the log messages
handlers= java.util.logging.FileHandler
handlers = java.util.logging.ConsoleHandler

# Configure the ConsoleHandler
java.util.logging.ConsoleHandler.level = ALL
java.util.logging.ConsoleHandler.formatter = java.util.logging.SimpleFormatter

# Configure the FileHandler
java.util.logging.FileHandler.pattern = log.txt
Expand All @@ -19,3 +20,5 @@ java.util.logging.FileHandler.level = ALL
# Configure the SimpleFormatter to include date, source, logger name, level, and message
java.util.logging.SimpleFormatter.format = %1$tY-%1$tm-%1$td %1$tH:%1$tM:%1$tS %4$s %2$s %5$s%6$s%n

# Set the logging level to FINER for the package a.b.c
org.bsc.langgraph4j.level = INFO
56 changes: 38 additions & 18 deletions how-tos/persistence.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
"cells": [
{
"cell_type": "code",
"execution_count": null,
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"String userHomeDir = System.getProperty(\"user.home\");\n",
"String localRespoUrl = \"file://\" + userHomeDir + \"/.m2/repository/\";\n",
"String langchain4jVersion = \"0.33.0\""
"String langchain4jVersion = \"0.34.0\""
]
},
{
Expand All @@ -34,6 +34,26 @@
"%dependency /resolve"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Initialize Logger"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
"var lm = java.util.logging.LogManager.getLogManager();\n",
"lm.checkAccess(); \n",
"try( var file = new java.io.FileInputStream(\"./logging.properties\")) {\n",
" lm.readConfiguration( file );\n",
"}"
]
},
{
"cell_type": "markdown",
"metadata": {},
Expand Down Expand Up @@ -90,7 +110,7 @@
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": 5,
"metadata": {},
"outputs": [],
"source": [
Expand Down Expand Up @@ -141,7 +161,7 @@
},
{
"cell_type": "code",
"execution_count": 5,
"execution_count": 6,
"metadata": {},
"outputs": [],
"source": [
Expand Down Expand Up @@ -222,7 +242,7 @@
},
{
"cell_type": "code",
"execution_count": 6,
"execution_count": 7,
"metadata": {},
"outputs": [],
"source": [
Expand Down Expand Up @@ -267,7 +287,7 @@
},
{
"cell_type": "code",
"execution_count": 7,
"execution_count": 8,
"metadata": {},
"outputs": [],
"source": [
Expand Down Expand Up @@ -300,7 +320,7 @@
},
{
"cell_type": "code",
"execution_count": 8,
"execution_count": 9,
"metadata": {},
"outputs": [
{
Expand All @@ -316,7 +336,7 @@
"name": "stdout",
"output_type": "stream",
"text": [
"AiMessage { text = null toolExecutionRequests = [ToolExecutionRequest { id = \"call_R0yDPSkxhjiBoqNLyyXOICLU\", name = \"execQuery\", arguments = \"{\"query\":\"London weather forecast for tomorrow\"}\" }] }\n"
"AiMessage { text = null toolExecutionRequests = [ToolExecutionRequest { id = \"call_zjycvQgyY3wAzI9nJXo2aHrQ\", name = \"execQuery\", arguments = \"{\"query\":\"London weather forecast for tomorrow\"}\" }] }\n"
]
}
],
Expand Down Expand Up @@ -350,7 +370,7 @@
},
{
"cell_type": "code",
"execution_count": 9,
"execution_count": 10,
"metadata": {},
"outputs": [],
"source": [
Expand Down Expand Up @@ -423,7 +443,7 @@
},
{
"cell_type": "code",
"execution_count": 10,
"execution_count": 11,
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -453,7 +473,7 @@
},
{
"cell_type": "code",
"execution_count": 11,
"execution_count": 12,
"metadata": {},
"outputs": [
{
Expand All @@ -462,7 +482,7 @@
"text": [
"__START__\n",
"agent\n",
"{messages=[AiMessage { text = \"Remember my name?\" toolExecutionRequests = null }, AiMessage { text = \"I'm sorry, but I don't have the ability to remember personal details or previous interactions. How can I assist you today?\" toolExecutionRequests = null }]}\n",
"{messages=[AiMessage { text = \"Remember my name?\" toolExecutionRequests = null }, AiMessage { text = \"I don't have the ability to remember personal information or previous interactions. Each session is independent, and I don't retain any data from one interaction to the next. How can I assist you today?\" toolExecutionRequests = null }]}\n",
"__END__\n"
]
}
Expand Down Expand Up @@ -496,7 +516,7 @@
},
{
"cell_type": "code",
"execution_count": 12,
"execution_count": 13,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -515,7 +535,7 @@
},
{
"cell_type": "code",
"execution_count": 13,
"execution_count": 14,
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -550,7 +570,7 @@
},
{
"cell_type": "code",
"execution_count": 14,
"execution_count": 15,
"metadata": {},
"outputs": [
{
Expand All @@ -559,7 +579,7 @@
"text": [
"__START__\n",
"agent\n",
"AiMessage { text = \"Of course, Bartolo! How can I help you today?\" toolExecutionRequests = null }\n",
"AiMessage { text = \"Of course, Bartolo! How can I assist you today?\" toolExecutionRequests = null }\n",
"__END__\n"
]
}
Expand Down Expand Up @@ -591,7 +611,7 @@
},
{
"cell_type": "code",
"execution_count": 15,
"execution_count": 16,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -602,7 +622,7 @@
},
{
"cell_type": "code",
"execution_count": 16,
"execution_count": 17,
"metadata": {},
"outputs": [
{
Expand Down
Loading

0 comments on commit 27c7afd

Please sign in to comment.