-
-
Notifications
You must be signed in to change notification settings - Fork 225
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Is there any way to accomplish indentation? #367
Comments
It would be possible to implement for the same use cases (e.g. add a |
@hynek That sounds like a great idea. Would you be interested in reviewing a patch? |
I'm afraid this is a little bit more complicated! I mean you can easily implement it for yourself by wrapping For In other words: there is no assumption about in which order log entries arrive and indenting would make no sense. E.g.
Now it looks like event3 is related to event1/thread 1. The question here is: should structlog move more into the CLI space and how? Should we maybe add |
Thanks for the clear and detailed reply. Regarding indentation and threads. That's a good point. Of course, indentation would ideally be associated with each thread. But I can see your point about how that would be visually confusing. Still seems superior to having begin/end log messages though. I'm not sure what you mean by CLI space. |
By CLI space I mean providing tools that are specifically meant to be used in CLI tools with respective assumptions and limitations, like the fastlog you linked before. |
@hynek Did you mean to close this as completed? If so, how should we use this new feature? I can't find a related pull request. |
@NeilGirdhar , I ran into this just now and here's what I ended up doing in case it helps. class PrettyJSONRenderer(structlog.dev.ConsoleRenderer):
"""
Custom Renderer for Structlog which pretty-prints JSON for 'extra' field.
Inherits the ConsoleRenderer from structlog.dev and replaces the value of 'extra'
key in event dictionary with a pretty-printed JSON string.
"""
def __call__(self, _, __, event_dict):
if "extra" in event_dict:
event_dict["extra"] = json.dumps(event_dict["extra"], indent=2, default=str)
return super().__call__(_, __, event_dict) |
Is it possible to have indentation like in https://github.com/Gbps/fastlog?
The text was updated successfully, but these errors were encountered: