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

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

Open
allevo opened this issue Apr 27, 2019 · 7 comments
Open

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

allevo opened this issue Apr 27, 2019 · 7 comments

Comments

@allevo
Copy link

allevo commented Apr 27, 2019

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
Copy link
Owner

elichai commented Apr 28, 2019

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
Copy link
Owner

elichai commented Apr 28, 2019

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
Copy link
Author

allevo commented Apr 28, 2019

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
Copy link
Owner

elichai commented Apr 30, 2019

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

@elichai
Copy link
Owner

elichai commented Apr 30, 2019

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

@allevo
Copy link
Author

allevo commented Apr 30, 2019

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
Copy link
Owner

elichai commented May 1, 2019

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.

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

2 participants