slog
slog copied to clipboard
Expansion of log macro depends on autoderef, which may pick Drain instead of Logger
use slog::Drain; // required to call .fuse() on logger
let log: Arc<slog::Logger> = log;
slog::error!(log, "WTF");
Gives:
|
115 | slog::error!(log, "WTF");
| ^^^^^^^^^^^^^^^^^^^^^^^^^ expected (), found enum `std::result::Result`
|
= note: expected type `()`
found type `std::result::Result<(), slog::private::NeverStruct>`
This is because log.log()
finds <log as Drain>::log()
rather than <log as Logger>::log()
.
This compiles:
let log: &slog::Logger = &log;
slog::error!(log, "WTF");
but it's PITA, because I have to use Arc
to share the logger in my application, and typecasting before every use of the macros kills the convenience.
The best thing would be for log!()
expansion to do let log: &slog::Logger = &log;
itself instead of expecting log.log()
to do that implicitly.
Or alternatively, have log!()
call slog::Logger::log(&log, ...)
I have to use Arc to share the logger in my application
Logger
is basically a wrapper over Arc
, so that's weird.
I think it's a good idea anywa, please PR. :)