• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..03-May-2022-

.github/workflows/H03-May-2022-8479

src/H03-May-2022-4,4882,898

tests/H03-May-2022-11090

.cargo-checksum.jsonH A D03-May-202289 11

.cargo_vcs_info.jsonH A D16-Jul-202074 65

.gitignoreH A D26-Apr-201921 32

CHANGELOG.mdH A D16-Jul-20207.3 KiB187125

Cargo.tomlH A D16-Jul-20201.7 KiB7163

Cargo.toml.orig-cargoH A D16-Jul-20201.4 KiB5948

LICENSE-APACHEH A D26-Apr-201910.8 KiB202169

LICENSE-MITH A D26-Apr-20191.1 KiB2622

README.mdH A D08-Jul-20203.2 KiB8766

build.rsH A D08-Jul-2020357 158

triagebot.tomlH A D22-May-202010 21

README.md

1log
2===
3
4A Rust library providing a lightweight logging *facade*.
5
6[![Build status](https://img.shields.io/github/workflow/status/rust-lang/log/CI/master)](https://github.com/rust-lang/log/actions)
7[![Latest version](https://img.shields.io/crates/v/log.svg)](https://crates.io/crates/log)
8[![Documentation](https://docs.rs/log/badge.svg)](https://docs.rs/log)
9![License](https://img.shields.io/crates/l/log.svg)
10
11* [`log` documentation](https://docs.rs/log)
12
13A logging facade provides a single logging API that abstracts over the actual
14logging implementation. Libraries can use the logging API provided by this
15crate, and the consumer of those libraries can choose the logging
16implementation that is most suitable for its use case.
17
18
19## Minimum supported `rustc`
20
21`1.31.0+`
22
23This version is explicitly tested in CI and may be bumped in any release as needed. Maintaining compatibility with older compilers is a priority though, so the bar for bumping the minimum supported version is set very high. Any changes to the supported minimum version will be called out in the release notes.
24
25## Usage
26
27## In libraries
28
29Libraries should link only to the `log` crate, and use the provided macros to
30log whatever information will be useful to downstream consumers:
31
32```toml
33[dependencies]
34log = "0.4"
35```
36
37```rust
38use log::{info, trace, warn};
39
40pub fn shave_the_yak(yak: &mut Yak) {
41    trace!("Commencing yak shaving");
42
43    loop {
44        match find_a_razor() {
45            Ok(razor) => {
46                info!("Razor located: {}", razor);
47                yak.shave(razor);
48                break;
49            }
50            Err(err) => {
51                warn!("Unable to locate a razor: {}, retrying", err);
52            }
53        }
54    }
55}
56```
57
58## In executables
59
60In order to produce log output, executables have to use a logger implementation compatible with the facade.
61There are many available implementations to choose from, here are some of the most popular ones:
62
63* Simple minimal loggers:
64    * [`env_logger`](https://docs.rs/env_logger/*/env_logger/)
65    * [`simple_logger`](https://github.com/borntyping/rust-simple_logger)
66    * [`simplelog`](https://github.com/drakulix/simplelog.rs)
67    * [`pretty_env_logger`](https://docs.rs/pretty_env_logger/*/pretty_env_logger/)
68    * [`stderrlog`](https://docs.rs/stderrlog/*/stderrlog/)
69    * [`flexi_logger`](https://docs.rs/flexi_logger/*/flexi_logger/)
70* Complex configurable frameworks:
71    * [`log4rs`](https://docs.rs/log4rs/*/log4rs/)
72    * [`fern`](https://docs.rs/fern/*/fern/)
73* Adaptors for other facilities:
74    * [`syslog`](https://docs.rs/syslog/*/syslog/)
75    * [`slog-stdlog`](https://docs.rs/slog-stdlog/*/slog_stdlog/)
76    * [`android_log`](https://docs.rs/android_log/*/android_log/)
77    * [`win_dbg_logger`](https://docs.rs/win_dbg_logger/*/win_dbg_logger/)
78* For WebAssembly binaries:
79    * [`console_log`](https://docs.rs/console_log/*/console_log/)
80
81Executables should choose a logger implementation and initialize it early in the
82runtime of the program. Logger implementations will typically include a
83function to do this. Any log messages generated before the logger is
84initialized will be ignored.
85
86The executable itself may use the `log` crate to log as well.
87