Skip to content

Feature Request: Encode stack traces as an array #35

@1hakusai1

Description

@1hakusai1

Hi! I often use this library. It is very useful and I love it.

When the logger using JsonFormatter logs exceptions, the output is like this.

{
  "asctime": "2024-12-16 16:29:19,170",
  "levelname": "ERROR",
  "name": "my-logger",
  "message": "Unexpected Error",
  "exc_info": "Traceback (most recent call last):\n  File \"/Users/hakusai/src/hakusai/stacktrace-as-array/main.py\", line 20, in <module>\n    do_something()\n  File \"/Users/hakusai/src/hakusai/stacktrace-as-array/main.py\", line 14, in do_something\n    raise Exception(\"something wrong\")\nException: something wrong"
}

The stack trace is hard to read. It should be more readable like this.

{
  "asctime": "2024-12-16 16:48:29,666",
  "levelname": "ERROR",
  "name": "my-logger",
  "message": "Unexpected Error",
  "exc_info": [
    "Traceback (most recent call last):",
    "  File \"/Users/hakusai/src/hakusai/stacktrace-as-array/main.py\", line 20, in <module>",
    "    do_something()",
    "  File \"/Users/hakusai/src/hakusai/stacktrace-as-array/main.py\", line 14, in do_something",
    "    raise Exception(\"something wrong\")",
    "Exception: something wrong"
  ]
}

Proposal

  • Add Option such like stack_trace_as_array to JsonFormatter.
    • default: False for backward compatibility.
    • if True, The formatter encodes stack traces as an array.

If you agree this feature, I will create PR.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions