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

Support for record format #22

Closed
rohitjoshi opened this issue Mar 14, 2019 · 4 comments · Fixed by #57
Closed

Support for record format #22

rohitjoshi opened this issue Mar 14, 2019 · 4 comments · Fixed by #57

Comments

@rohitjoshi
Copy link

How do I format a record as Timestamp|Level|Module:Line|Msg
e.g.
2019-03-14T07:13:58.740|INFO|abc::network_server:97|Starting connection handler child loop

@sile
Copy link
Owner

sile commented Mar 16, 2019

sloggers only supports the formats defined by slog_term::CompactFormat and slog_term::FullFormat.
To keep this crate simple, sloggers probably does not provide custom message format functionality.
If you need it (or any other elaborate features), it is recommended to use slog directly.

@rohitjoshi
Copy link
Author

Thanks. Any suggestions on how to override? I have been using slog with implementing log trait for a drain but missing some of the common capabilities of sloggers. E.g. log rotate, keep num of files, compression etc

@sile
Copy link
Owner

sile commented Mar 17, 2019

I tried adding BuildWithCustomFormat for this purpose (in custom-format branch).
It can be used as follows:

#[macro_use]
extern crate slog;
extern crate sloggers;

use sloggers::BuildWithCustomFormat; // Added
use sloggers::terminal::{TerminalLoggerBuilder, Destination};

let mut builder = TerminalLoggerBuilder::new();
builder.destination(Destination::Stderr);

let logger = builder.build_with_custom_format(|decorator| {
    let drain  = ...;  // Create your own drain that uses `decorator` (slog_term::Decorator).
    Ok(drain)
})).unwrap();
info!(logger, "Hello World!");

Is it sufficient for you?

@rohitjoshi
Copy link
Author

Thanks, I will give a try. Appreciate 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

Successfully merging a pull request may close this issue.

2 participants