Skip to content

Implement Log for Box<Log>#414

Merged
sfackler merged 1 commit into
rust-lang:masterfrom
lionel-faber:boxed-impl
Sep 21, 2020
Merged

Implement Log for Box<Log>#414
sfackler merged 1 commit into
rust-lang:masterfrom
lionel-faber:boxed-impl

Conversation

@lionel-faber
Copy link
Copy Markdown
Contributor

Hi there! I was trying to wrap a Box<dyn Log> returned from flexi logger into async_log but I was unable to do so since the Log trait was not implemented for Box<dyn Log>.

One option was to create a wrapper struct:

struct LoggerWrapper(Box<dyn Log>);

impl Log for LoggerWrapper {
    fn enabled(&self, metadata: &Metadata) -> bool {
        self.0.enabled(metadata)
    }

    fn log(&self, record: &Record) {
        self.0.log(record)
    }

    fn flush(&self) {
        self.0.flush();
    }
}

It was suggested to me that it might be beneficial to have the implementation in the log crate so I've added the implementation in this pull request.

Would you accept this change? I will be happy to make any changes or modifications if necessary.

Comment thread src/lib.rs Outdated
}

#[cfg(feature = "std")]
impl Log for std::boxed::Box<dyn Log> {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be made more general to impl<T> Log for Box<T> where T: ?Sized + Log { ... }

@sfackler sfackler merged commit 7396e38 into rust-lang:master Sep 21, 2020
@lionel-faber lionel-faber deleted the boxed-impl branch September 22, 2020 07:25
EFanZh pushed a commit to EFanZh/log that referenced this pull request Jul 23, 2023
(cargo-release) version 0.2.1

Co-authored-by: github-actions <github-actions@github.com>
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

Successfully merging this pull request may close these issues.

2 participants