StepflowStepflow

Logging

Structured logging with Stepflow

Logging

Stepflow provides a structured logger that automatically attaches workflow context (execution ID, workflow ID, step name) to your logs.

StepflowLogger

The StepflowLogger class is the core of the logging system. It supports multiple handlers and child loggers.

import { createLogger, consoleLogHandler } from "@stepflowjs/observability";

const logger = createLogger({
  config: {
    level: "info",
    enabled: true,
  },
  handlers: [consoleLogHandler],
});

logger.info("Workflow started", { userId: "123" });

Log Levels

Stepflow supports the following log levels:

  • debug: Detailed information for debugging.
  • info: General operational information.
  • warn: Warning messages for non-critical issues.
  • error: Error messages for critical failures.
logger.debug("Processing data...");
logger.info("User signed up");
logger.warn("Rate limit approaching");
logger.error("Database connection failed", { error: err.message });

Child Loggers

You can create child loggers that inherit the configuration of the parent but add additional context to every log entry.

const executionLogger = logger.child({
  executionId: "exec_123",
  workflowId: "welcome-email",
});

// This log will automatically include executionId and workflowId
executionLogger.info("Sending email");

Log Handlers

Log handlers are functions that process log entries. You can add multiple handlers to a logger.

import { type LogHandler } from "@stepflowjs/observability";

const customHandler: LogHandler = (entry) => {
  // Send log to external service
};

logger.addHandler(customHandler);

Console Log Handler

The consoleLogHandler is a built-in handler that formats and prints logs to the console.

import { consoleLogHandler } from "@stepflowjs/observability";

Configuration

OptionTypeDefaultDescription
levelLogLevel"info"Minimum log level to emit
enabledbooleantrueWhether logging is enabled

On this page