A pretty, easy-to-use logger for Rust.

Related tags

Logging rust logging
Overview

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

Comments
  • timestamps with milliseconds

    timestamps with milliseconds

    I filed https://github.com/sebasmagri/env_logger/issues/122 a few minutes ago, then I noticed that pretty_env_logger supports timestamps and that adding milliseconds would be easy over here. This is obviously an opinionated pull request, submitted humbly. :)

    I also replaced the space with T. I like it that way because then the timestamp is one field if you're parsing with awk or something like that, and it's iso8601-preferred. But I'm willing to revert that part of the change if it's a deal breaker.

    opened by nlevitt 8
  • Update env logger

    Update env logger

    This PR updates env-logger to version 0.9 since it's been out for a few months now (and 0.8 even longer).

    The only upstream breaking change is the MSRV being increased to 1.41. However, while I don't see a MSRV for pretty_env_logger, its doubtful it will break any users as Debian stable ships a minimum of 1.41.1 and the majority of users are on newer compiler versions.

    Closes https://github.com/seanmonstar/pretty-env-logger/issues/50

    opened by complexspaces 7
  • Changing log level at runtime

    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 ?

    opened by bestouff 4
  • Lack of documentation

    Lack of documentation

    Hi,

    During work on https://github.com/rust-lang-nursery/log/ documentation, we wanted to add link to this crate as one of the most popular implementations. Unfortunately it has no documentation. Currently it does not seam to be intended for 3'rd party adoption. Would you be open to adding few sentences to docs?

    Please refer to: https://github.com/rust-lang-nursery/log/pull/188/commits/dbd3c44bc0b030c3b928635de0e059f55e8ae67b#r119920413

    opened by budziq 4
  • [WIP] Add custom option

    [WIP] Add custom option

    I like the formatted logger but I also want line number and file name. Do you think this functionality makes sense?

    If so, I can add this meta builder and implement the other builders based on this current one.

    This is just a PR to show you my intention.

    Prints something like this:

    2020-06-07T19:02:47.817Z common_handlers.rs:69 INFO server::common_handlers > Received request..

    opened by y2kappa 3
  • Question: interested in exposing the builder?

    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.

    opened by fawix 2
  • Is this project being maintained ?

    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.

    opened by patrickelectric 1
  • add test option

    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.

    opened by FreeMasen 1
  • Typo in the github metadata crates.io url

    Typo in the github metadata crates.io url

    The github metadata (the text at the top of the repo, above the readme, above the file list on the repo homepage) links to https://crates.io/pretty_env_logger, which is not a valid link; it should be https://crates.io/crates/pretty_env_logger.

    opened by FauxFaux 1
  • formatted_builder cannot error

    formatted_builder cannot error

    formatted_builder cannot error; it does not call anything which returns an error. The documentation looks like a copy-paste error.

    This will be an incompatible public API change, which might not be wanted. If not, I still suggest fixing the documentation, perhaps to:

    This function fails only if there's a problem constructing the builder. Setting the logger is not attempted.

    The function signature is pretty useless anyway, even given future errors coming into existence, as it's unlikely the builder would ever return a SetLoggerError.

    opened by FauxFaux 1
  • Added minimal docs

    Added minimal docs

    fixes https://github.com/seanmonstar/pretty-env-logger/issues/2

    Unfortunately I did not know how to add colored text example within rustdoc and README.md without embedding image.

    opened by budziq 1
  • Disable alignment of messages

    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.

    opened by F0Xde 0
  • formatted_builder() appears to do nothing

    formatted_builder() appears to do nothing

    I tried using formatted_builder() and now the RUST_LOG env var seems to be completely ignored. Is this function working?

    I also saw these comments implying that the function is broken: https://github.com/seanmonstar/pretty-env-logger/issues/41#issuecomment-682032429 https://github.com/seanmonstar/pretty-env-logger/issues/20#issuecomment-682038868

    opened by TheButlah 0
  • Re-export env_logger's optional features

    Re-export env_logger's optional features

    Re-export the atty, humantime and regex features. Some time-related features are disabled without humantime.

    I did not make termcolor optional because it seemed too interleaved with pretty_env_logger's code, and because I'm not sure it would still justify the name without this. (-:

    The biggest gain is eliminating the the regex feature/dependency, which I noticed was adding 1.1MB to my stripped release build .so file.

    The default behavior remains the same with everything enabled.

    opened by shesek 1
  • Initialize env_logger::Builder through env_logger::from_env

    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).

    opened by Luro02 2
A pretty, sensible logger for Rust - ideal for running examples and tests on a crate of choice

sensible-env-logger A pretty, sensible logger for Rust - ideal for running examples and tests on a crate of choice. This is a thin wrapper around pret

Ritvik Nag 3 Aug 9, 2022
A Rust logger with various features.

Moe Logger (>ω<) Another logger based on pretty-env-logger and env_logger. Allow writing log to file with features like formatting, file rotation. Usa

Rui Li 4 Sep 24, 2021
Another Key Logger Yet. Rust.

Another Key Logger Yet. Rust. For my very first experience of working with Rust, I decided to manage the keyboard, this time by logging and writing th

(Not) Kearash 0 May 3, 2022
A loki logger for the log facade

Loki Logger A loki logger for the log facade. Examples extern crate log; extern crate loki_logger; use log::LevelFilter; #[tokio::main] async fn main

Thomas Nicollet 11 Dec 24, 2022
HTTP request logger

nosy - HTTP request logger How hard can it be to build your own HTTP request logger in Rust? Well, not that easy if you've never written a webapp in R

Manuel Hutter 1 Nov 26, 2021
A standalone, `#![no_std]`-friendly `Logger` crate.

A standalone, #![no_std]-friendly Logger crate. Based on the design of the logger built into the bootloader crate and meant to be used in OS kernels.

Kenny Strawn 1 Feb 6, 2022
Rall is an incredibly simple and intuitive logger

Really...? Another Logging Library? Yes! :P rall is an incredibly simple and intuitive logger, consider this crate a failure if you can't get setup wi

Hamothy 4 Sep 5, 2022
A dead simple logger that works globally and across threads.

Woody A logger for Rust that's *actually* easy to use. Features Easy to use: Just import the macros and you're good to go. No need to configure anythi

Travis A. Wagner 11 Apr 13, 2023
Logging implementation for Rust

log A Rust library providing a lightweight logging facade. log documentation A logging facade provides a single logging API that abstracts over the ac

The Rust Programming Language 1.6k Dec 29, 2022
Structured, contextual, extensible, composable logging for Rust

Getting started Introduction FAQ Crate list slog-rs - The Logging for Rust Introduction (please read) slog is an ecosystem of reusable components for

slog-rs 1.4k Jan 3, 2023
A highly configurable logging framework for Rust

log4rs log4rs is a highly configurable logging framework modeled after Java's Logback and log4j libraries. Warning If you are using the file rotation

null 753 Jan 8, 2023
Application level tracing for Rust.

Website | Chat | Documentation (master branch) Overview tracing is a framework for instrumenting Rust programs to collect structured, event-based diag

Tokio 3.3k Jan 3, 2023
Task-based logging for rust

task_log task_log is a task-based logger. Installing Just add task_log = 0.1.4 to your Cargo.toml's dependency section. Example Let's get right to the

Matt Gleich 2 Feb 28, 2022
💬 A couple of functions to make logging in Rust easier.

Rust logging ⛔ ?? A couple of functions to make logging in Rust easier. Installation ?? Just add the code of code.rs to your project. You can copy/pas

Skwal 2 Apr 7, 2022
A rust library for creating and managing logs of arbitrary binary data

A rust library for creating and managing logs of arbitrary binary data. Presently it's used to collect sensor data. But it should generally be helpful in cases where you need to store timeseries data, in a nearly (but not strictly) append-only fashion.

Yusuf Simonson 1 May 9, 2022
A cool log library built using rust-lang

RustLog A cool log library built using rust-lang Installation: Cargo.toml rustlog = { git = "https://github.com/krishpranav/rustlog" } log = "0.4.17"

Krisna Pranav 2 Jul 21, 2022
A pretty, easy-to-use logger for Rust.

pretty-env-logger A simple logger built on top of env_logger. It is configured via an environment variable and writes to standard error with nice colo

Sean McArthur 390 Dec 29, 2022
Easy c̵̰͠r̵̛̠ö̴̪s̶̩̒s̵̭̀-t̶̲͝h̶̯̚r̵̺͐e̷̖̽ḁ̴̍d̶̖̔ ȓ̵͙ė̶͎ḟ̴͙e̸̖͛r̶̖͗ë̶̱́ṉ̵̒ĉ̷̥e̷͚̍ s̷̹͌h̷̲̉a̵̭͋r̷̫̊ḭ̵̊n̷̬͂g̵̦̃ f̶̻̊ơ̵̜ṟ̸̈́ R̵̞̋ù̵̺s̷̖̅ţ̸͗!̸̼͋

Rust S̵̓i̸̓n̵̉ I̴n̴f̶e̸r̵n̷a̴l mutability! Howdy, friendly Rust developer! Ever had a value get m̵̯̅ð̶͊v̴̮̾ê̴̼͘d away right under your nose just when

null 294 Dec 23, 2022
A pretty, sensible logger for Rust - ideal for running examples and tests on a crate of choice

sensible-env-logger A pretty, sensible logger for Rust - ideal for running examples and tests on a crate of choice. This is a thin wrapper around pret

Ritvik Nag 3 Aug 9, 2022
An easy to use library for pretty print tables of Rust structs and enums.

tabled An easy to use library for pretty printing tables of Rust structs and enums. Table of Contents Usage Settings Style Themes ASCII Psql Github Ma

Maxim Zhiburt 1.3k Jan 9, 2023