question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Log message formatting options

See original GitHub issue

The raven client had a defined log handler which let you use python’s built in logging configuration mechanisms to control how log messages looked when they were passed to sentry, however the new python-sdk does not appear to have any equivalent option. I have a number of apps where I have log messages managed by structlog, where structlog hooks into python’s logging and formatts everything nicely with pretty readable colours, nicely formatted timestamps, before it gets sent to stdout, however the combination of how python-sdk hooks into logging, and the formatting of these messages means that the new sentry-sdk logging integration/handling makes an absolute mess of things producing unhelpful results in sentry.io like dozens of variations of [2m2019-01-03T07:16:00.573607Z[0m [[31m[1merror [0m] [1mcan_send_message is Fals... each with one recorded error event, instead of a single can_send_message is False with the correct count of error events.

What is the mechanism for the sentry-sdk to work with python’s logging formatters and libraries such as structlog?

Issue Analytics

  • State:open
  • Created 5 years ago
  • Reactions:12
  • Comments:26 (10 by maintainers)

github_iconTop GitHub Comments

2reactions
odannyccommented, Mar 29, 2019

@untitaker Thank you!

I actually got it sort of working now. Before I was using the structlog format… Which basically has a event key which contains the message. Now I changed it so [json-python-logger](https://github.com/madzak/python-json-logger) takes care of outputting the json - which has the message in a message key. This now displays correctly in Sentry BUT doesn’t display the exception stack trace. For example:

{
  "message": "something bad happened",
  "request_id": "asdf",
  "exception": "[an exception stacktrace in here]"
}

The sentry python lib will not look at exception key in this case and format it correctly in Sentry

2reactions
Keramblockcommented, Mar 22, 2019

Have same issue

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to I format my log message - java - Stack Overflow
Even with just JDK logging, you can use a custom Formatter to handle formatting of log messages with parameters. For (a simplistic) example:...
Read more >
Log Formats – a (Mostly) Complete Guide - Graylog
Log Formats – a (Mostly) Complete Guide · WHAT IS A LOG FORMAT? · USING A SYSLOG SERVER · JSON LOG FORMAT ·...
Read more >
logging — Logging facility for Python — Python 3.11.1 ...
Logs a message with level DEBUG on this logger. The msg is the message format string, and the args are the arguments which...
Read more >
Tip: Use a Human-Readable Logging Format - Reflectoring
A guide to create a logging format that can be scanned at a single glance.
Read more >
Console log formatting - .NET - Microsoft Learn
The Json console formatter, by default, logs each message in a single line. In order to make it more readable while configuring the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found