Class ToolLogger

java.lang.Object
org.machanism.machai.ai.provider.ToolLogger

class ToolLogger extends Object
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 Classes
    Modifier and Type
    Class
    Description
    (package private) static enum 
    Defines the types of operations whose activity can be logged.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private static final String
    Format used when a tool is invoked.
    private static final String
    Format used when a tool invocation fails.
    (package private) static org.slf4j.Logger
    Logger used to write tool execution messages.
    private static final String
    Format used when a tool returns a result.
    Category assigned to messages emitted by this logger.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Creates an instance of ToolLogger.
  • Method Summary

    Modifier and Type
    Method
    Description
    private String
    abbreviate(String valueOf)
    Abbreviates long log strings to keep logs concise and clean.
    (package private) void
    logError(String name, File dir, Throwable targetException)
    Logs errors that occurred during tool method execution.
    (package private) void
    logInput(String name, com.fasterxml.jackson.databind.JsonNode props, File dir)
    Logs tool invocation input details.
    (package private) void
    logResult(String name, File dir, Object result)
    Logs tool invocation execution results.
    private String
    Utility method that safely serializes any payload object into a JSON string format.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • logger

      static org.slf4j.Logger logger
      Logger used to write tool execution messages.
    • CALL_MSG

      private static final String CALL_MSG
      Format used when a tool is invoked.
      See Also:
    • RETURNS_MSG

      private static final String RETURNS_MSG
      Format used when a tool returns a result.
      See Also:
    • ERROR_MSG

      private static final String ERROR_MSG
      Format used when a tool invocation fails.
      See Also:
    • type

      private ToolLogger.Type type
      Category assigned to messages emitted by this logger.
  • Constructor Details

    • ToolLogger

      public ToolLogger(ToolLogger.Type type, FunctionTools tools)
      Creates an instance of ToolLogger.
      Parameters:
      type - category assigned to messages emitted by this logger
      tools - the tools instance creating this logger; retained for API compatibility
  • Method Details

    • logError

      void logError(String name, File dir, Throwable targetException)
      Logs errors that occurred during tool method execution.
      Parameters:
      name - the name of the tool
      dir - the active project directory context
      targetException - the exception thrown by the target tool
    • logInput

      void logInput(String name, com.fasterxml.jackson.databind.JsonNode props, File dir)
      Logs tool invocation input details.
      Parameters:
      name - the name of the tool
      props - JSON node representing tool properties
      dir - the active project directory context
    • abbreviate

      private String abbreviate(String valueOf)
      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_LENG characters
    • logResult

      void logResult(String name, File dir, Object result)
      Logs tool invocation execution results.
      Parameters:
      name - the name of the tool
      dir - the active project directory context
      result - the resulting object returned by the tool function
    • writeValueAsString

      private String writeValueAsString(Object result)
      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