elichai / log-derive

A procedural macro for auto logging output of functions
https://docs.rs/log-derive
Apache License 2.0
189 stars 12 forks source link

If function has a logger as parameter use it! #14

Open allevo opened 5 years ago

allevo commented 5 years ago

I've a function like this

fn get_something(log: Logger) -> Result<bool, Error> {
  Ok(true)
}

I would like to use this awesome lib in order to log the error using the first parameter. For more generic usage

 #[logfn(Err = "Error", fmt = "Failed Sending Packet: {:?}", logger = "my_obj.log")]
fn get_something(my_obj: MyObj) -> Result<bool, Error> {
  Ok(true)
}

If you are interested, I may send a PR!

elichai commented 5 years ago

that's a nice add. I would hope there's a better UX to do this, but idk if that's possible.

Something like: #[logfn(Err = "Error", fmt = "Failed Sending Packet: {:?}", my_obj)] or similiar (without adding a new attribute)

elichai commented 5 years ago

I hope i'll have time this week to test this and maybe also release a new version (already changed some stuff and a bit of the API)

but if you want to play with this and update me that's more than welcome :)

allevo commented 5 years ago

I'm not so familiar with quore! macro. I've tried to implement but some compile errors appears. Could you suggest me some tools for debugging?

Thanks

elichai commented 5 years ago

Oh, wait, you want to pass a logger not an attribute.

elichai commented 5 years ago

Is the Logger behaving the some as rust's log? Can you show me a real example of this?

allevo commented 5 years ago

Actually I'm using https://docs.rs/sloggers/0.3.2/sloggers/ because I would have different loggers. An example of usage can be found here: https://github.com/slog-rs/misc/blob/master/examples/features.rs. The primary feature of this kind of logger is the child: you can create a logger adding some info to it. That infos are printed in every log line.

I would like to use that kind of instance here.

Are you interested?

elichai commented 5 years ago

hmmmm this is a totally different facade. I'm using log and you want slog compatibility. this won't be easily done without feature gating or a separate crate.