Comments (9)
I'd be interested in implementing this once it's decided.
I took a quick look to see if there were any common traits (e.g. Clone
, Hash
) that are easy to derive with the current code. I don't think any of them can be derived for Logger
because of the format
field which is Box<Fn(&mut Write, &Record) -> io::Result<()> + Sync + Send>
. I believe it'd need to use a generic type in order to specify that type in the box is Clone
, Hash
, etc.
In any case, I'm not sure there's specific use case for Logger
and/or Builder
implementing any of these common traits. But I thought it couldn't hurt to see if we could get them for free. :}
from env_logger.
I think you're right @jimmycuadra. You don't usually interact with the Logger
directly anyways.
Are we happy to close this one?
from env_logger.
There is one question to follow my previous comment: Why is the format
field specified the way that it is instead of using a generic type? There must be some history here that I don't know, and that comes from the log crate itself and not env_logger. Depending on the reason it was done this way, maybe it would be worth considering using a generic type instead so more traits like Clone
could be implemented when the concrete type does as well.
from env_logger.
Oh right. I think it's a trait object to keep the signature of Logger
simpler. I don't think we could make it generic unless we also offer a simple way to get the filtering for custom loggers built off env_logger
without having to juggle generics. But having separate filtering for custom loggers and a generic Logger
type is something I'd totally be on board with.
If we were going to make it generic then I think we should introduce a trait for formatting and blanket implement it for closures along with a well-typed default implementation, maybe even making it a default parameter on Logger
, something like:
trait LogFormat {
fn fmt(&self, record: Record, w: &mut Write);
}
struct DefaultFormat;
impl LogFormat for DefaultFormat { ... }
impl<F> LogFormat for F where F: Fn(&mut Write, Record) { ... }
struct Logger<F = DefaultFormat> { ... }
What do you think?
from env_logger.
That looks good to me. Is this something we should bring up on the log crate's issue tracker? AFAIK they're ready to ship another version of the crate and there isn't any additional design work planned, but I haven't been involved up to this point so I don't know whether this is worth bringing up or trying to change.
from env_logger.
What's the proposed log change?
from env_logger.
@sfackler there's no proposed change to log
as far as I'm aware. Just env_logger::Logger
.
from env_logger.
I spent some time playing around with this and I don't think a generic type is going to work out on the Logger
here. The main issue is that we can't change that generic type in the builder without returning a new value, but since we're using &mut self
receivers that doesn't work. There are also some inference issues with the blanket impl for Fn
on a formatting trait, which is a bit unfortunate but makes sense.
So I think it was worth exploring, but it doesn't seem like a big enough win to cause a lot of churn over. I would still like us to have some alternative way to build your own logger using env_logger
's filter parsing that doesn't mean we need a Silent
variant on Target
though.
from env_logger.
I'm going to go ahead and close this, leaving the current set of trait impls as-is.
Please let me know if there's more you think we should do here.
from env_logger.
Related Issues (20)
- MSRV break due to is_terminal 0.4.8 HOT 1
- `WriteStyle` is ignored when used with `Target::Pipe`
- Replace is-terminal dep with std::io::IsTerminal HOT 7
- `Target::Pipe` does not auto-flush like std{out/err}
- about doc HOT 2
- Cargo.lock is not meant to be checked in for libraries HOT 4
- Trivial: the systemd example misuses RUST_LOG_STYLE HOT 1
- method not found in `&mut Formatter` HOT 1
- can't see any logs when using #[windows_subsystem = "windows"] HOT 4
- Missing changelog for 0.10.1 HOT 1
- Remove deprecated APIs
- Missing recent releases on github? HOT 1
- logger crate catches Clion stop signal HOT 1
- Provide a way to disable automatic flushing when using `Target::Pipe` HOT 1
- Feature Deprecation Without Warning or Migration HOT 3
- env_logger doesn't output anything HOT 4
- Issue with `anstream` optional dependency HOT 1
- Empty changelog for 0.11.2 HOT 1
- [feat] support star matching HOT 3
- delete me HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from env_logger.