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

Provide a method to easily set log level names #33

Open
gpanders opened this issue Sep 19, 2024 · 0 comments
Open

Provide a method to easily set log level names #33

gpanders opened this issue Sep 19, 2024 · 0 comments

Comments

@gpanders
Copy link

gpanders commented Sep 19, 2024

The add_default_keys() method sets the level field to use the short version version of log fields (e.g. ERRO for Error). If a user does not want to use the short field names, they must essentially re-implement add_default_keys() themselves.

That is,

let drain = slog_json::Json::default(std::io::stderr())

now becomes

let drain = slog_json::Json::new(std::io::stderr())
    .add_key_value(slog::o!(
        "ts" => slog::FnValue(move |_: &slog::Record| {
            time::OffsetDateTime::now_utc()
            .format(&time::format_description::well_known::Rfc3339)
            .ok()
        }),
        "level" => slog::FnValue(move |rinfo: &slog::Record| {
            rinfo.level().as_str()
        }),
        "msg" => slog::PushFnValue(move |record: &slog::Record, ser| {
            ser.emit(record.msg())
        }),
    ))
    .build();

which also requires adding a (top level) dependency on the time crate.

I would like to be able to use the default keys, but be able to choose the strings used for the log levels. Example API:

let drain = slot_json::Json::new(std::io::stderr())
    .add_default_keys()
    .with_log_levels(["off", "critical", "error", "warn", "info", "debug", "trace"])
    .build();
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

1 participant