Skip to main content
The Orion.js Logger is a powerful, flexible logging utility built on top of Winston. It provides structured logging capabilities with customizable formats, transports, and context tracking.

Installation

Basic Usage

Critical Logging Pattern

The first argument must always be a static string. All variables should be passed in the object as the second argument.
This pattern is required because:
  • Log aggregation tools can group logs by the static message
  • Searching logs by message becomes predictable
  • Variable data is properly indexed and queryable

Error Logging Pattern

When logging errors, the error object must be in a parameter named error in the second argument object:
This ensures:
  • Stack traces are properly captured
  • Error serialization works correctly
  • Log analysis tools can extract error details

Features

Log Levels

The logger supports the standard log levels:
  • error: For error conditions
  • warn: For warning conditions
  • info: For informational messages
  • debug: For debugging information

Automatic Contextual Information

Each log message automatically includes:
  • Timestamp
  • Log level
  • File name where the log was triggered (automatically detected)
  • OpenTelemetry trace and span IDs (when available)

Formatting

The logger supports two main output formats:
  1. Text Format (for development):
    • Colorized output
    • Human-readable formatting
    • Activated when ORION_DEV=1 environment variable is set
  2. JSON Format (for production):
    • Structured JSON logs
    • Ideal for log aggregation and analysis
    • Default in production environments

OpenTelemetry Integration

The logger automatically detects and includes OpenTelemetry trace and span IDs when available, enabling correlation between logs and traces.

Advanced Configuration

Setting Log Level

Adding Custom Transports

Complete Logger Configuration

Best Practices

  1. Use Static Message Strings: The first argument must be a static string for proper log aggregation:
  2. Pass Error Objects Correctly: Use the error property name:
  3. Add Context: Use logger.addContext(module) at the top of your files to automatically include file information.
  4. Use Appropriate Levels:
    • debug: Detailed information useful during development
    • info: Normal application behavior, milestones
    • warn: Unexpected but handled issues
    • error: Errors that prevent proper operation
  5. Include Relevant Data: Pass structured objects with relevant context:

Common Patterns

Service Logging

Migration Logging