Skip to content

[Feature Request] Support standalone structured error log output for external monitoring integration #2014

@yiliang114

Description

@yiliang114

Background & Motivation

Currently, qwen-code's logging system primarily serves two scenarios:

  1. Development & Debugging: The debugLogger outputs detailed logs to ~/.qwen/debug/*.txt, containing all levels (DEBUG/INFO/WARN/ERROR)
  2. Product Analytics: The Telemetry system collects usage data with support for OTLP export or Alibaba Cloud RUM

However, for users deploying qwen-code as an Agent on servers, the existing logging mechanism has the following pain points:

  • Debug logs are too verbose: Session logs mix all levels together, containing large amounts of normal operation debugging info, making them unsuitable for direct error monitoring
  • Telemetry serves a different purpose: Primarily designed for product analytics rather than operational monitoring, and requires additional collector infrastructure
  • Lack of standardized error output: Enterprise deployments typically need to integrate error logs with systems like SLS, ELK, or Datadog, but there is currently no clean, structured error log source

Feature Description

We hope qwen-code can support configuring an independent error log output channel that writes error-level logs to a specified file in a configurable format (suggested: JSON Lines) for external systems to consume.

qwen-code only handles output, not consumption — the log files can then be integrated by users with SLS, ELK, or other monitoring systems as needed.

Use Cases

Scenario Requirement
Enterprise Agent Deployment Unattended operation requires real-time error monitoring and alerting
Multi-cloud/Hybrid Cloud Need to integrate with unified logging platforms (Alibaba Cloud SLS, AWS CloudWatch, self-hosted ELK)
Multi-instance Management Multiple qwen-code instances on one server need centralized error collection
Quick Troubleshooting Production issues require fast error filtering instead of digging through verbose debug logs
Compliance Auditing Error records need to be retained for post-incident auditing

Proposed Solution

Add an errorLog configuration option with the following capabilities:

// ~/.qwen/settings.json
{
  "errorLog": {
    "enabled": true,                           // Enable/disable
    "path": "/var/log/qwen-code/errors.jsonl", // Output path, supports ~ expansion
    "format": "jsonl",                         // Format: jsonl | text

    // Optional: log rotation
    "rotation": {
      "maxSize": "100MB",
      "maxFiles": 10
    },

    // Optional: field customization
    "fields": {
      "includeStack": true,      // Include stack trace
      "includeContext": true     // Include context info
    }
  }
}

JSON Lines Format Example:

{"timestamp":"2026-02-28T10:30:00.000Z","level":"ERROR","sessionId":"abc123","errorType":"API_ERROR","message":"Request timeout","error":{"code":"TIMEOUT","message":"..."},"context":{"model":"qwen-max"}}
{"timestamp":"2026-02-28T10:35:00.000Z","level":"FATAL","sessionId":"def456","errorType":"AUTH_ERROR","message":"Authentication failed","error":{"code":401}}

Key Fields:

Field Description
timestamp ISO 8601 format
level ERROR / FATAL
sessionId Links to specific session for traceability
errorType Error classification: API_ERROR, TOOL_ERROR, AUTH_ERROR, etc.
message Brief error description
error Original error info including stack (configurable)
context Context info like current model, tool, etc. (configurable)

Alternatives Considered

Current workarounds and their drawbacks:

Workaround Drawback
Parse ~/.qwen/debug/*.txt directly Verbose content with DEBUG/INFO logs mixed in, difficult to parse
Enable telemetry and connect to collector Requires deploying additional collector, complex architecture
Fork and modify source code High maintenance cost, cannot follow official updates

Relationship with Existing Systems

┌─────────────────────────────────────────────────────────┐
│                      qwen-code                          │
├─────────────────────────────────────────────────────────┤
│  Debug Logger (existing) │  Error Logger (proposed)     │
│  ~/.qwen/debug/*.txt     │  User-defined path (disabled by default) │
│  Full logs for debugging │  Errors only for monitoring  │
├─────────────────────────────────────────────────────────┤
│  Telemetry (existing)                                   │
│  OTLP / RUM / File export                               │
│  For product analytics                                  │
└─────────────────────────────────────────────────────────┘
                           │
                           ▼
              ┌──────────────────────┐
              │   Log Consumers      │
              │  SLS / ELK / Datadog │
              └──────────────────────┘

Implementation Suggestions (Reference)

  1. Add an ErrorLogger class alongside the existing DebugLogger
  2. Call errorLogger.log() in reportError() when enabled
  3. Disabled by default to avoid impacting existing users
  4. Use JSON Lines format for native compatibility with mainstream log systems
  5. Consider integrating with mature log rotation libraries (e.g., rotating-file-stream)

Priority

Medium. This is an enhancement that doesn't affect existing functionality, but is valuable for enterprise deployment scenarios.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions