Log structured things
See original GitHub issueI 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
- We can use the pythons
- 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:
- Created 3 years ago
- Comments:12 (8 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@xeor @benhowes Good news:
loguru
now supports “structured logging” out of the box!The
**kwargs
arguments are automatically added to theextra
dict. This can be disabled using.opt(capture=False)
. 👍@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 ifopt(record=True)
but this is the only one. Special cases should be kept to a minimum in order to avoid possible edge cases likelogger.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.