log-derive icon indicating copy to clipboard operation
log-derive copied to clipboard

If function has a logger as parameter use it!

Open allevo opened this issue 5 years ago • 7 comments

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!

allevo avatar Apr 27 '19 17:04 allevo

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 avatar Apr 28 '19 09:04 elichai

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 :)

elichai avatar Apr 28 '19 09:04 elichai

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

allevo avatar Apr 28 '19 13:04 allevo

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

elichai avatar Apr 30 '19 15:04 elichai

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

elichai avatar Apr 30 '19 15:04 elichai

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?

allevo avatar Apr 30 '19 19:04 allevo

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.

elichai avatar May 01 '19 09:05 elichai