Package org.machanism.machai.ai.provider
Class ToolLogger
java.lang.Object
org.machanism.machai.ai.provider.ToolLogger
Internal logging utility for tool inputs, results, and execution errors.
At info level, payloads are abbreviated to keep log output readable. At debug level, complete serialized payloads and failure stack traces are included.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescription(package private) static enumDefines the types of operations whose activity can be logged. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final StringFormat used when a tool is invoked.private static final StringFormat used when a tool invocation fails.(package private) static org.slf4j.LoggerLogger used to write tool execution messages.private static final StringFormat used when a tool returns a result.private ToolLogger.TypeCategory assigned to messages emitted by this logger. -
Constructor Summary
ConstructorsConstructorDescriptionToolLogger(ToolLogger.Type type, FunctionTools tools) Creates an instance of ToolLogger. -
Method Summary
Modifier and TypeMethodDescriptionprivate Stringabbreviate(String valueOf) Abbreviates long log strings to keep logs concise and clean.(package private) voidLogs errors that occurred during tool method execution.(package private) voidLogs tool invocation input details.(package private) voidLogs tool invocation execution results.private StringwriteValueAsString(Object result) Utility method that safely serializes any payload object into a JSON string format.
-
Field Details
-
logger
static org.slf4j.Logger loggerLogger used to write tool execution messages. -
CALL_MSG
Format used when a tool is invoked.- See Also:
-
RETURNS_MSG
Format used when a tool returns a result.- See Also:
-
ERROR_MSG
Format used when a tool invocation fails.- See Also:
-
type
Category assigned to messages emitted by this logger.
-
-
Constructor Details
-
ToolLogger
Creates an instance of ToolLogger.- Parameters:
type- category assigned to messages emitted by this loggertools- the tools instance creating this logger; retained for API compatibility
-
-
Method Details
-
logError
Logs errors that occurred during tool method execution.- Parameters:
name- the name of the tooldir- the active project directory contexttargetException- the exception thrown by the target tool
-
logInput
Logs tool invocation input details.- Parameters:
name- the name of the toolprops- JSON node representing tool propertiesdir- the active project directory context
-
abbreviate
Abbreviates long log strings to keep logs concise and clean.- Parameters:
valueOf- the source string representation- Returns:
- the abbreviated string trimmed to
AbstractAIProvider.LOG_LINE_LENGcharacters
-
logResult
Logs tool invocation execution results.- Parameters:
name- the name of the tooldir- the active project directory contextresult- the resulting object returned by the tool function
-
writeValueAsString
Utility method that safely serializes any payload object into a JSON string format.- Parameters:
result- the object to serialize- Returns:
- a serialized JSON string, or the fallback string value of the object on failure
-