#google-cloud #logging #stackdriver #log

stackdriver_logger

A logger for Google's Stackdriver with a cli-friendly fallback for local development

16 releases (8 breaking)

0.8.2 Dec 20, 2022
0.8.1 Nov 14, 2022
0.8.0 Jul 29, 2020
0.7.0 Feb 12, 2020
0.1.4 Jul 31, 2018

#235 in Debugging

Download history 625/week @ 2023-11-20 932/week @ 2023-11-27 1002/week @ 2023-12-04 893/week @ 2023-12-11 502/week @ 2023-12-18 138/week @ 2023-12-25 626/week @ 2024-01-01 907/week @ 2024-01-08 479/week @ 2024-01-15 742/week @ 2024-01-22 718/week @ 2024-01-29 902/week @ 2024-02-05 552/week @ 2024-02-12 362/week @ 2024-02-19 811/week @ 2024-02-26 885/week @ 2024-03-04

2,622 downloads per month

MIT/Apache

19KB
302 lines

Stackdriver logger

A logger for Google's Stackdriver.
By default, in debug mode, we fall back to pretty_env_logger.
In release mode, we output JSON formatted logs compatible with Stackdriver.

Usage

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

fn main() {
    stackdriver_logger::init_with_cargo!();

    trace!("trace log");
    debug!("debug log");
    info!("info log");
    warn!("warn log");
    error!("error log");
}

Note that the init_with_cargo! macro will include your Cargo.toml in the resulting binary. If you don't want that, check out the docs, a few more initializers are available.

Behavior

When using the above macro, you don't have anything else to do. For other initializers, you may need to provide two environment variables : SERVICE_NAME and SERVICE_VERSION. We're using Cargo's CARGO_PKG_NAME and CARGO_PKG_VERSION as a fallback, but these are only available if you run your application via Cargo.
Check out the docs to see which initializers require environment variables.

Enabling logging

This library accepts a RUST_LOG env variable, it works exactly like in env_logger.
By default, everything is disabled except for error!. To enable all logs for your application :

RUST_LOG=your_application cargo run

For more details, take a look at the env_logger docs.

Feature flags

By default, this crate enables all env_logger defaults features and always pulls pretty_env_logger.
These crates have some heavy dependencies like regex.
If you want smaller builds in production, and don't use fancy env_logger features, you can disable default features for stackdriver_logger like so :

stackdriver_logger = { version = "*", default-features = false, features = ["prod"] }

License

Licensed under either of

Dependencies

~4–12MB
~106K SLoC