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 structured things

See original GitHub issue

I am choosing between loguru or structlog for a new project. I’ve settled now on loguru, but there is one thing that really bothers me is how to log structured objects like dicts.

I found https://github.com/Delgan/loguru/issues/2, which ended up being labeled as wont-fix.

Just throwing it out, but before I start making a PR for an idea, what is the thoughts about something like this for a solution:

  • Using pipe for structured logs, example a_dict | logger.info('message here')
    • We can use the pythons __ror__ function to implement something that looks like a unix-pipe
    • logger.info can work as normal, no api changes
    • The structured log can be handled by a function, a serializer to make it into a log-line
  • Maybe also a_var = some_func() | logger.info('a_var assigned')
    • If the logger/pipe construct returns the output back, this idea can be used in normal assignments as well.

I didn’t start to write much code yet, but I think this might be possible to implement.

Thoughts?

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:12 (8 by maintainers)

github_iconTop GitHub Comments

6reactions
Delgancommented, May 17, 2020

@xeor @benhowes Good news: loguru now supports “structured logging” out of the box!

The **kwargs arguments are automatically added to the extra dict. This can be disabled using .opt(capture=False). 👍

1reaction
Delgancommented, May 7, 2020

@benhowes I intentionally chose not to have any “magical” arguments. The logging functions must matches the behavior of str.format(*args, **kwargs), nothing more, nothing less. There is one special case that happens if opt(record=True) but this is the only one. Special cases should be kept to a minimum in order to avoid possible edge cases like logger.info("Value: {bind}", bind=123).

If you’re worried about the overhead introduced by bind(), don’t be. 🙂 There are things internally that are quite heavier when a message is logged. Hopefully, it will be drastically improved once I find time to re-implement it in C.

Read more comments on GitHub >

github_iconTop Results From Across the Web

What Is Structured Logging and How to Use It - Loggly
We have properties that indicate what action occurred and the identifications of the relevant objects, such as the user and the report created....
Read more >
What Is Structured Logging and Why Developers Need It
Log files are one of the most valuable assets that a developer has. Usually, when something goes wrong in production the first thing...
Read more >
Structured Logging: Definition, Format, Benefits, and More
Objects rather than strings make up structured logs. Variables, data structures, methods, and functions can all be found in an object.
Read more >
Log-structured storage - Julia Evans
A log-structured storage engine is a little like our Bash script – you write new stuff to the end of the log, and...
Read more >
Damn Cool Algorithms: Log structured storage - Nick's Blog
The basic organization of a log structured storage system is, as the name implies, a log - that is, an append-only sequence of...
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