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

Configuration file directly in the crate #70

Closed
fdubois1 opened this issue Jun 13, 2018 · 4 comments
Closed

Configuration file directly in the crate #70

fdubois1 opened this issue Jun 13, 2018 · 4 comments

Comments

@fdubois1
Copy link

It would be nice if we could init log4rs with a file in the crate.

It exists "std::include_str!" to get the content of a file then log4rs could read it. I know that it is possible to configure it by code by building the config ourself, but would be useful to just add a yaml file to my crate and init log4rs with it.

Does it make sense ?
Thanks

@sfackler
Copy link
Collaborator

You can deserialize the string into a RawConfig and then build the logger out of that: https://docs.rs/log4rs/0.8.0/log4rs/file/struct.RawConfig.html

@fdubois1
Copy link
Author

But to be honest, I don't see how to build the RawConfig. I saw in init_file that rawConfig is built like this : let config = format.parse(&source)?;

But Format type is private. I don't see how I can build that RawConfig object. Sorry if it is a dumb question and thanks for your help.

@sfackler
Copy link
Collaborator

RawConfig implements Deserialize (it unfortunately doesn't show up in rustdoc), so you'd just do serde_yaml::from_string::<RawConfig>(my_config).

@fdubois1
Copy link
Author

Ah, awesome, thanks a lot for your help !!!

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