Giter VIP home page Giter VIP logo

pretty-env-logger's Introduction

pretty-env-logger

Crates.io Docs MIT/APACHE-2.0 Travis CI

A simple logger built on top of env_logger. It is configured via an environment variable and writes to standard error with nice colored output for log levels.

example output

Usage

Add the dependency to your Cargo.toml:

[dependencies]
log = "0.4"
pretty_env_logger = "0.4"

Add some usage to your application:

extern crate pretty_env_logger;
#[macro_use] extern crate log;

fn main() {
    pretty_env_logger::init();
    info!("such information");
    warn!("o_O");
    error!("much error");
}

Then run your app with the environmental variable set:

RUST_LOG=trace cargo run

License

Licensed under either of

pretty-env-logger's People

Contributors

bbigras avatar benlemasurier avatar budziq avatar complexspaces avatar eijebong avatar fawix avatar golem131 avatar k3yavi avatar lewisbelcher avatar mercutiodesign avatar nlevitt avatar nvll avatar praveenperera avatar reillysiemens avatar seanmonstar avatar systemcluster avatar valpackett avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

pretty-env-logger's Issues

format_module_path(false) doesn't work anymore

Given the following code where logme just calls log::warn!("warning")`
image

gives the following output, despite format_module_path(false) since 0.5.0
image

Compared to 0.4.0 (which behaves as I would expect):
image

Re-export env_logger crate

This line should be added to src/lib.rs:

pub use env_logger;

so crates using pretty-env-logger do not have to add env_logger to their own dependencies (if they want to customize logging with pretty_env_logger::formatted_builder).

Please bump env_logger dependency to 0.9

It would be nice to have more options for configuring an env_logger Builder when using pretty_env_logger::formatted_builder() such as parse_env() or parse_default_env() to make it easier to be able to configure a logger with defaults in case RUST_LOG hasn't been set.

Initialize env_logger::Builder through env_logger::from_env

Executing this code

use log::{trace, debug, info, warn, error};

fn main() {
    pretty_env_logger::formatted_builder().init();

    trace!("a trace example");
    debug!("deboogging");
    info!("such information");
    warn!("o_O");
    error!("boom");
}

with

RUST_LOG=trace cargo run

prints

 ERROR terminal_image > boom

and this is quite confusing, because I expected it to print all log levels (it ignores the environment variable).

add test option

the env_logger package provides env_logger::builder().is_test(true).try_init() which allows logs to be captured. It would be nice to expose this in this crate as well.

Changing log level at runtime

I'm using pretty-env-logger (through quicli) for a long-lived daemon, and I would need to dynamically change its log level at runtime (my daemon sends logs via network, and something "in the cloud" may ask it to log more or less).
How is it possible to do that ? Or if not possible currently, would it be possible as a feature ?

Cargo main function logging

When I put the example in main.rs. Ran with RUST_LOG=main=trace cargo run. Nothing was print out. It is an issue with pretty_env_logger or cargo itself? Because running RUST_LOG=trace cargo run will print out everything, which is not what we want.

Question: interested in exposing the builder?

@seanmonstar I just created a fork of your logger to expose the env_logger::Builder - I like the formatting but was needing more control over the logger... I also added some more examples.

If you are interested in merging the changes I can send you a pull request for review.

Indirect dependency on regex

Thanks for this crate!

You are currently using env_logger with default features. This includes the regex crate with default features which adds about 1.3MB to a binaries size (see rust-lang/regex#613).

Could you maybe add (and proxy) the features of env_logger so that a consumer of your crate can disable the default features (ie "regex")?

Something along the lines of the following would help:

[features]
default = ["termcolor", "atty", "humantime", "regex"]
termcolor = ["env_logger/termcolor"]
atty = ["env_logger/atty"]
humantime = ["env_logger/humantime"]
regex = ["env_logger/regex"]

Is this project being maintained ?

It appears that there are a bunch of staled issues and PRs, if it's not maintained anymore, the repository should be archived or transferred to someone, avoiding unnecessary creation of PRs and issues.

pretty_env_logger v0.3.0 fails to compile

We (Fedora Rust SIG) would appreciate if you would not use deny warnings in code, but rather use it from CI (-D warnings).

BUILDSTDERR:      Running `/usr/bin/rustc --crate-name pretty_env_logger src/lib.rs --color never --crate-type lib --emit=dep-info,link -C opt-level=3 -C metadata=13a6cbd344d92b81 -C extra-filename=-13a6cbd344d92b81 --out-dir /builddir/build/BUILD/pretty_env_logger-0.3.0/target/release/deps -L dependency=/builddir/build/BUILD/pretty_env_logger-0.3.0/target/release/deps --extern chrono=/builddir/build/BUILD/pretty_env_logger-0.3.0/target/release/deps/libchrono-842eeac55f65145c.rlib --extern env_logger=/builddir/build/BUILD/pretty_env_logger-0.3.0/target/release/deps/libenv_logger-aafab70dab9d3a16.rlib --extern log=/builddir/build/BUILD/pretty_env_logger-0.3.0/target/release/deps/liblog-afd98fddddc8f6a6.rlib -Copt-level=3 -Cdebuginfo=2 -Clink-arg=-Wl,-z,relro,-z,now`
BUILDSTDERR: error: use of deprecated item 'env_logger::Builder::parse': use `parse_filters` instead.
BUILDSTDERR:    --> src/lib.rs:126:17
BUILDSTDERR:     |
BUILDSTDERR: 126 |         builder.parse(&s);
BUILDSTDERR:     |                 ^^^^^
BUILDSTDERR:     |
BUILDSTDERR: note: lint level defined here
BUILDSTDERR:    --> src/lib.rs:1:9
BUILDSTDERR:     |
BUILDSTDERR: 1   | #![deny(warnings)]
BUILDSTDERR:     |         ^^^^^^^^
BUILDSTDERR:     = note: #[deny(deprecated)] implied by #[deny(warnings)]
BUILDSTDERR: error: use of deprecated item 'env_logger::Builder::parse': use `parse_filters` instead.
BUILDSTDERR:    --> src/lib.rs:145:17
BUILDSTDERR:     |
BUILDSTDERR: 145 |         builder.parse(&s);
BUILDSTDERR:     |                 ^^^^^
BUILDSTDERR: error: aborting due to 2 previous errors
BUILDSTDERR: error: Could not compile `pretty_env_logger`.

Disable alignment of messages

Is it possible to disable the automatic alignment of log messages? This often causes huge space as soon as there is one significantly longer target, so I would rather completely disable it and print > message here directly after the target with only a single space in between.

#5 is still open, but I don't know whether it refers to this or something different.

[Feature Request] Default log level

In env_logger it's possible to provide a default log level by using:

env_logger::from_env(Env::default().default_filter_or("info")).init();

Would you consider adding this feature (or maybe accepting a PR)?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.