-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Add generic function loggerstream
#28229
Conversation
IO stream of the current logger.
What if a logger doesn't have an underlying |
Return |
One idea might be another macro for unformatted logging, perhaps? I’m still wondering how this works when the logger emits structerd messages (e.g. maybe it writes rows to a table or something? Your RDBMS won’t handle an arbitrary stream of text...). |
I don't think loggers should have that feature but if it's important to you and others I think a better option could maybe be Bypassing the logger's own output mechanisms would make it more difficult for non-stdlib logging libraries to work consistently. |
Sometimes you just wanna dump something to the logger stream to get it logged. |
Why that and not either printing to stdout or logging? |
Why is that not |
That requires logger to implement all functions that take an
Mainly being able to control some formatting myself. For example to make |
Have you considered building |
There might be other advantages to building |
Yes, that was my first idea. But IIUC that can only work for "top-level" applications. A user should be able to redirect the logger stream from Pkg. Case in point;
|
Following on from that - what confuses me about this Issue most is that any given logger may be associated with any number (including zero) of output streams. |
Sure... of course a user could overide the default logger. We could potentially do something as simple as, say, having Basically, I'd try to work with the philosophy of the new system instead of trying to circumvent the logger's control and understanding of its output streams. |
But they can't? As I tried to show with the example, if Pkg has its own logger, then a user can't opt in to using their own logger.
Yea, I'm all for this, but as the system currently works it does not seem to be an option for packages to write their own loggers like this? |
This issue with coupling loggers to log output is why we made Memento. You're right that the system as it stands can't support those operations, which I agree are necessary. That said, this PR's code pretends the loggers have properties they don't have. Either we should give them those properties (e.g., explicitly introduce a method for printing unformatted output) or change the design. |
I guess a package that implements their own logger can use something like:
which then uses |
Sorry, I didn't see this one! I don't think we can really have
Not exactly. The current system is mostly frontend (ie, the macros), with a very minimal backend ( For the record I've been thinking a lot about composition of log filtering and I agree that the current model of installing an entirely new logger with The design difficulties largely come down to the task-centric design of the system which makes it rather different from other systems which exist already (eg, log4j and python's logging libs). This also means that having PARTR merged would help rather a lot in the next design iteration. Some parts (filters) can be concurrent, but some parts (appenders) need to have single threaded components... |
Should we open an issue about this then? The current system is only useful for end users, but pretty useless for packages. |
Yes though I think we're at the stage where we really should split out stdlib/Logging into a new |
@fredrikekre I've been thinking a lot about how to make the logging system composable for consuming log records. Obviously I need use cases to motivate the design. Could you comment on the outcomes you were trying to achieve for |
Yes, to be able to fully control the formatting basically. Right now Pkg just prints to
No. |
I'm not entirely sure that
(where the application is Pkg in this case) is the right model here. That seems like it's going to force the logging system in the middle to do lots of kind of pointless and unfortunate things. Why not model it this way instead:
In other words, instead of trying to make the logging system produce arbitrary pretty output for the end user as a result of logging events, just produce the pretty output directly and log events at the same time silently. Yes, it's twice as much "event logging code" on the application side, but it should be easy enough to abstract that into a single call for each event that does both things. I guess the main ask for that is that a given package should be able to say "I'm going to take care of letting the user know about events and problems, I just want silent logging as a record." Is that possible already, @c42f? At the per-package level? |
@StefanKarpinski Filtering log events on a per-module level is definitely supported by the data model. We don't have anything explicit to inform downstream loggers that the messages should somehow be "silent", though just mutating the event stream by setting the level to # filter/map log stream from `some_pkg_internals`; first display them to the user, then downgrade
# the level of those messages to debug. Then forward to whatever `current_logger` was installed
# further up the call stack.
filterlogs(DowngradeMessages((Pkg,Info)=>Debug)) ∘ DisplayPkgMessages()) do
$some_pkg_internals()
end The big question of course being where to put such a Side note — I'm still feeling queasy about the categorical (type) vs ordinal (severity/verbosity) nature of log levels. Mutating the event category using |
Add generic function
loggerstream
to get the IO stream of the current logger. Sometimes you just wannaprint
something directly to the current logging stream, instead of going through@info
etc. With this PR you can do e.g.to print raw stuff to the loggerstream.