Open adri326 opened 6 months ago
I guess that kind of works, maybe? The syntax on the macros needs to be so that that importing new trait is not necessary, but I could see &impl log::Log
being useful for other thing than what's described here, like testing.
BTW. IIRC slog::Never
is #[doc_hidden]
, just to leave the door open to update it to !
when it's ready. But it's been many years and there's already https://doc.rust-lang.org/std/convert/enum.Infallible.html , which is supposed to perform the same function, so maybe we could switch to that already?
Both of these changes make sence.
A Log
trait alias and changing slog::Never
to std::convert::Infailable
are both good ideas.
I would like to use
slog
inside of a bootloader, meaning that I need to be able to turn off logging when necessary to save binary size, and I also want to avoid relying on static memory (andslog
seems to be the only logging library that I have found that does not have this baked in).However, I fear that if I am to use the default
Logger<Arc<SendSyncRefUnwindSafeDrain>>
, then some optimizations will be missed, especially when I want to fully turn off logging.Trying to use
Logger::root_typed
, I quickly came to an issue: it's impossible for a function to give the correct trait requirements on the drain forLogger
to be used:The only way around this that I have found so far is to require the generic parameter
D
to implementslog::SendSyncUnwindDrain<Ok = (), Err = slog::Never>
, which requires the use of thedoc_hidden
bottom type placeholder.I think a very simple solution would be to provide a trait,
Log
, which would be implemented byLogger
when the requirements forLogger::log
are satisfied. With it, the code above would simplify tofn my_function(logger: &impl slog::Log)
. If the method onLog
is called something other thanlog
(saylog_record
), then such a change would only require a minor version bump, andLogger::log
could be left as-is, with the macros callingLog::log_record
directly (assuming that until now,slog::log!
could only be used with aLogger
).