-
Notifications
You must be signed in to change notification settings - Fork 18
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
An ability to make a combined logger #8
Comments
Another question, Both file_logger and terminal_logger contains one Async, thus opened two threads. Can we avoid that, something like only create one root Async(thread) for all child Drains. |
Part of the reason why core I am the author of If you require non-trivial logging setup requirements for your apps, maybe you should just revert back to Note that you can still use Anyway, it's just my quick opinion, nothing that I feel strong about. Also the exact line, where there is "too much complexity" so new users get confused would be entirely for the authors of |
I agree with this opinion. FYI, it is possible to construct combined loggers by a scalable (or generic) way as follows: extern crate serde;
#[macro_use]
extern crate serde_derive;
#[macro_use]
extern crate slog;
extern crate sloggers;
extern crate toml;
use slog::{Drain, Duplicate, Logger};
use sloggers::{Config, LoggerConfig};
#[derive(Deserialize)]
struct CombinedLoggerConfig {
loggers: Vec<LoggerConfig>,
}
fn main() {
let conf = r#"
[[loggers]]
type = "terminal"
format = "compact"
source_location = "none"
timezone = "local"
destination = "stdout"
level = "info"
[[loggers]]
type = "file"
format = "full"
source_location = "none"
timezone = "local"
level = "info"
path = "railprofiles.log"
truncate = false
"#;
let combined_logger_config: CombinedLoggerConfig = toml::from_str(conf).unwrap();
let mut combined_logger = None;
for logger_config in combined_logger_config.loggers {
let logger = logger_config.build_logger().unwrap();
if let Some(pred) = combined_logger.take() {
combined_logger = Some(Logger::root(Duplicate::new(logger, pred).fuse(), o!()));
} else {
combined_logger = Some(logger);
}
}
let combined_logger = combined_logger.take().unwrap();
info!(combined_logger, "Hello World!");
} |
Using the current version of If this is necessary, it may be a good means to add a flag to |
I'd like sloggers to be able to configure and instantiate a logger that logs both to
terminal_logger
andfile_logger
.An example of expected configuration file:
Luckily, it is already possible to do it with this code (just stub shown):
This approach works for me so far, so this is more like a "what if" issue for me.
The interesting questions are
The text was updated successfully, but these errors were encountered: