Skip to content
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

Expansion of log macro depends on autoderef, which may pick Drain instead of Logger #205

Open
kornelski opened this issue Mar 17, 2019 · 3 comments

Comments

@kornelski
Copy link

kornelski commented Mar 17, 2019

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.

@tmccombs
Copy link
Contributor

Or alternatively, have log!() call slog::Logger::log(&log, ...)

@dpc
Copy link
Collaborator

dpc commented Mar 18, 2019

I have to use Arc to share the logger in my application

Logger is basically a wrapper over Arc, so that's weird.

@dpc
Copy link
Collaborator

dpc commented Mar 18, 2019

I think it's a good idea anywa, please PR. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants