Re-think logging in smithay #362
Replies: 4 comments
-
I imagine the cost of maintaining a logging abstraction in smithay is a prospect which some people may not like since it adds more code to have to maintain. In my opinion one of the other crates would do a better job and remove this issue of needing more abstraction. Assuming the Although I feel we will probably suffer as similar issue to having slog in public api with one of the other crates as well, just don't know to what extent those crates are religious about bumping versions and not allowing breaking changes. |
Beta Was this translation helpful? Give feedback.
-
To reduce dependencies and allow producing smaller binaries, it would be useful to be able to build with no logging support whatsoever. |
Beta Was this translation helpful? Give feedback.
-
I feel like Example layer implementation from tracy_full, tracy profiler integration. Example implementation form user's point of view: use smithay::logs::SmithayLayer;
tracing::subscriber::set_global_default(
tracing_subsriber::registry::with(SmithayLayer);
); |
Beta Was this translation helpful? Give feedback.
-
This can be closed now :-) |
Beta Was this translation helpful? Give feedback.
-
Logging in smithay is currently implemented using
slog
.While it has been a decent choice at the time, it has grown to be a little cumbersome in some regards.
(This is mostly an aggregation of arguments raised regarding this issue in a recent discussion over at our Matrix channel.)
Logger
to be passed around and stored.slog
discourages the use ofslog_scope
in libraries for good reasonNone
instead of anlogger
, that is still translated into an actual logger instance, that needs to be passed around in smithays internals.However slog also has a set of desirable advantages:
log
ecosystem. Whatever might takes it's place, should support that as wellcontexts
in the following discussion.slog noticeably lacks in the following regards:
Notice at this point, that contexts can be simulated via scopes, by using the same scope for every call to the same struct, while contexts fail to emulate the latter due to their static nature.
This sounds like a clear argument for scopes as they can emulated all of slogs functionality, without explicitly passing a logger. But the static nature of contexts has it's own advantages. Often the scopes context is actually static and the user might prefer to pass in the context once on struct creation, instead of setting a matching scope for every method call (which in turn the user would have to store themselves or construct on every call, we would mostly delegate the problem for static contexts).
So a strong contender for a slog successor would allow:
contexts
in the public api /None
arguments) in other parts of smithaylog
.Notice that emulating contexts with scopes can be very easy, if a scope-based logging library would allow snapshoting and storing the current scope on object creation.
This solution even gets rid of any
Context
argument in the public api, but introduces a bit of implicit api (which can be viewed as an issue, but is arguably negligible given smithay's usually very strongly typed api).Also note that any scope-api that is based on an existing library, will cause side-effects for users of smithay, that use said library on their own. Effectively any library like this will be part of an implicit public api. If this may lead to undesired side-effects and should possibly be avoided, but that has not yet been debated.
Possible candidates are (not exhaustive):
log
itself.log
has an ongoing issue on structural logging support. With that in place context/scope apis could be easily hand-writting and deployed on top of log.tracing
is a very new library from the tokio-universe.async
-rust programs, this is a standalone logging library with a strong focus onSpan
s.Span
s are essentially, what is described in our scope-concept.Span
s can be stored, which means emulating a context can be done implicitly as outlined above.tracing
has some compatibility withlog
, but that seems to be mostly focused on passinglog
-messages intotracing
and not the other way around. (to be investigated)tracing
s origin, the api needs to be examined careful, which has not been done yet.tracing
has a vast ecosystem already with error backtraces, flamegraphs and more just to name a few.tracing
sSpan
s on their own.slog_scope
. We could throw caution to the wind and just ignore slog's recommendation and useslog_scope
to get rid of theLogger
arguments.log
slog-scope
on their own.Beta Was this translation helpful? Give feedback.
All reactions