-
Notifications
You must be signed in to change notification settings - Fork 255
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
implement indentation #80
Conversation
Are there any existing logging frameworks that support a feature like this? This seems to me like something that individual loggers (e.g. |
That would be possible, but then you need to have some kind of handle to the logger, which you can't really get without putting an arc into the logger |
|
yea that would work, but then libraries need to know about the logger that's going to be used. libraries set the indentation level, executables use it to print indented (or not if they don't care) |
My concern is that control over indentation is a very niche use case. Again, I am not aware of any logging framework that supports something like this. In addition, having a single indentation level for the entire process seems like it'd have some serious issues with logging coming from multiple threads as they're all trying to first adjust the indentation and then log. |
Ok, the thread thing is a serious issue. But we can fix that with a tls. Just because no logging framework has done it doesn't mean it's niche/rare. I've seen a few handwritten implementations. Whenever you have some sort of recursion or hierarchy, regular logging will become confusing. I have wished for indentation or something for a while when debugging rustc |
this looks nice! though i see the usage limited to debugging/understanding a single threaded application with a console/file based logger. isn't the more general idea of what you really want sort of this? |
@xitep yea, except that I don't want the logging statement to add the indentation, but the logger, so that even logging statements that don't know about indentation are indented. I doesn't matter to me whether it's numbers or indentation, that's a decision of the logger. |
I don't doubt that this is a thing you would find useful, but I also don't want this library to become the union of all features that anyone has ever found useful. I would also note that rustc does not use this library, but rather its own version. |
I know, but that is another issue. I have an idea: A This basically allows any kind of user extension, without cluttering the crate with additional features. |
I updated this PR to a general "settings" version. |
ping @sfackler
I can totally see that. The indentation part can be removed entirely, since it can be done in user code with the other changes. The main question is whether settings of any kind should be allowed, and whether the design I proposed is feasible. |
I'm a bit concerned about identifying settings by string names - it seems like there's a high chance of naming conflicts between settings used by various logging backends, and of typos on the user side when interacting with them. Something type-based might be better? It might be too annoying to need to have to pull in some crate with a single struct in it though. I'm still not sure that there will be a wide enough set of settings shared between the various logging frameworks that calling cc @rust-lang/libs |
Good points, especially about separating out settings into an extra crate. I'll post here when I have something to show |
Can this be done in a logger implementation instead of directly in the log crate? Indentation is a property of the 'view' layer in my opinion, not the log lines themselves. Just as an off-the cuff-idea, a custom logger crate could support a thread-local indentation level that was stored independently of the main logging information. So you might write something like:
|
I implemented it in the log_settings crate. Working on getting docs uploaded...
I want other crates logs using the log crate to be indented, too. So the logger needs to read the value and crates that are indentation aware can change the indentation. Right now it's very rudimentary, but I'm considering adding something like you suggested. |
@oli-obk Seems to me that you're hitting the ceiling of what's possible with non-structured logging. Have you seen slog's compact term logger format example (screenshot on https://github.com/slog-rs/slog)? Even if it's not exactly what you desire, you would have much easier time fitting your exact use-case into |
Cool! I'll have a look at it. |
fixes #79
This is a feature I'll definitely use in serde-xml, and probably implement it for json, too. Basically anything that processes tree-structures benefits enormously from it.
example run with miri: