Class ExecutionLogger

java.lang.Object
ai.nervemind.app.service.ExecutionLogger

@Service public class ExecutionLogger extends Object
Structured logging service for workflow execution. Provides JSON-formatted log entries with context and timing.
  • Constructor Details

    • ExecutionLogger

      public ExecutionLogger()
      Constructs a new ExecutionLogger and initializes the JSON mapper.
  • Method Details

    • startExecution

      public void startExecution(String executionId, String workflowId, String workflowName)
      Start logging for an execution.
      Parameters:
      executionId - the execution ID
      workflowId - the workflow ID
      workflowName - the workflow name
    • endExecution

      public void endExecution(String executionId, boolean success, Object result)
      End logging for an execution.
      Parameters:
      executionId - the execution ID
      success - true if execution succeeded
      result - the execution result
    • nodeStart

      public void nodeStart(String executionId, String nodeId, String nodeType, String nodeName)
      Log node execution start.
      Parameters:
      executionId - the execution ID
      nodeId - the node ID
      nodeType - the node type
      nodeName - the node name
    • nodeEnd

      public void nodeEnd(String executionId, String nodeId, String nodeType, long durationMs, boolean success)
      Log node execution end.
      Parameters:
      executionId - the execution ID
      nodeId - the node ID
      nodeType - the node type
      durationMs - execution duration in milliseconds
      success - true if node execution succeeded
    • nodeSkip

      public void nodeSkip(String executionId, String nodeId, String reason)
      Log node skip (conditional).
      Parameters:
      executionId - the execution ID
      nodeId - the node ID
      reason - the reason for skipping
    • dataFlow

      public void dataFlow(String executionId, String fromNode, String toNode, int dataSize)
      Log data flow between nodes.
      Parameters:
      executionId - the execution ID
      fromNode - source node ID
      toNode - target node ID
      dataSize - size of data passed
    • variable

      public void variable(String executionId, String operation, String variableName, Object value)
      Log variable operation.
      Parameters:
      executionId - the execution ID
      operation - the variable operation
      variableName - the variable name
      value - the variable value
    • nodeInput

      public void nodeInput(String executionId, String nodeId, String nodeName, Map<String,Object> input)
      Log node input data for traceability.
      Parameters:
      executionId - the execution ID
      nodeId - the node ID
      nodeName - the node name
      input - the node input data
    • nodeOutput

      public void nodeOutput(String executionId, String nodeId, String nodeName, Map<String,Object> output)
      Log node output data for traceability.
      Parameters:
      executionId - the execution ID
      nodeId - the node ID
      nodeName - the node name
      output - the node output data
    • expressionEval

      public void expressionEval(String executionId, String nodeId, String expression, Object result, boolean success)
      Log expression evaluation for debugging templating and interpolation.
      Parameters:
      executionId - the execution ID
      nodeId - the node ID
      expression - the expression that was evaluated
      result - the evaluation result
      success - true if evaluation succeeded
    • error

      public void error(String executionId, String nodeId, Exception e)
      Log error with full details including input context and source location.
      Parameters:
      executionId - the execution ID
      nodeId - the node ID
      e - the exception that occurred
    • errorWithContext

      public void errorWithContext(String executionId, String nodeId, String nodeName, Map<String,Object> inputAtError, Exception e)
      Log error with full details including input context and source location. Enhanced version that captures the input data at the time of error.
      Parameters:
      executionId - the execution ID
      nodeId - the node ID
      nodeName - the node name (optional)
      inputAtError - the input data at the time of error (optional)
      e - the exception that occurred
    • retry

      public void retry(String executionId, String nodeId, int attempt, int maxRetries, long delayMs, String reason)
      Log retry attempt.
      Parameters:
      executionId - the execution ID
      nodeId - the node ID
      attempt - the current attempt number
      maxRetries - the maximum number of retries
      delayMs - the delay before next attempt
      reason - the reason for retry
    • rateLimit

      public void rateLimit(String executionId, String bucketId, boolean throttled, long waitMs)
      Log rate limiting event.
      Parameters:
      executionId - the execution ID
      bucketId - the rate limit bucket ID
      throttled - whether the request was throttled
      waitMs - the wait time in milliseconds
    • performance

      public void performance(String executionId, String metric, long value, String unit)
      Log performance metric.
      Parameters:
      executionId - the execution ID
      metric - the metric name
      value - the metric value
      unit - the unit of measurement
    • custom

      public void custom(String executionId, ExecutionLogger.LogLevel level, String message, Map<String,Object> context)
      Custom log entry.
      Parameters:
      executionId - the execution identifier
      level - the log level
      message - the log message
      context - additional context data
    • getLogEntries

      public List<ExecutionLogger.LogEntry> getLogEntries(String executionId)
      Get all log entries for an execution.
      Parameters:
      executionId - the execution ID
      Returns:
      list of log entries
    • getLogEntries

      public List<ExecutionLogger.LogEntry> getLogEntries(String executionId, ExecutionLogger.LogLevel minLevel, ExecutionLogger.LogCategory category)
      Get filtered log entries.
      Parameters:
      executionId - the execution ID
      minLevel - minimum log level
      category - log category
      Returns:
      list of filtered log entries
    • getSummary

      public ExecutionLogger.ExecutionSummary getSummary(String executionId)
      Get execution summary.
      Parameters:
      executionId - the execution ID
      Returns:
      the execution summary, or null if not found
    • exportToJson

      public String exportToJson(String executionId) throws com.fasterxml.jackson.core.JsonProcessingException
      Export logs to JSON.
      Parameters:
      executionId - the execution ID
      Returns:
      JSON string of logs
      Throws:
      com.fasterxml.jackson.core.JsonProcessingException - if serialization fails
    • exportToFile

      public void exportToFile(String executionId, Path filePath) throws IOException
      Export logs to a file.
      Parameters:
      executionId - the execution ID
      filePath - the destination file path
      Throws:
      IOException - if file writing fails
    • addHandler

      public void addHandler(ai.nervemind.common.service.ExecutionLogHandler handler)
      Add a log handler.
      Parameters:
      handler - the log handler to add
    • removeHandler

      public void removeHandler(ai.nervemind.common.service.ExecutionLogHandler handler)
      Remove a log handler.
      Parameters:
      handler - the log handler to remove
    • clearExecution

      public void clearExecution(String executionId)
      Clear logs for an execution.
      Parameters:
      executionId - the execution ID to clear
    • clearAll

      public void clearAll()
      Clear all logs.