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

..--

.github/workflows/23-Nov-2023-10397

benches/23-Nov-2023-3123

src/23-Nov-2023-4,1102,648

.cargo_vcs_info.jsonD23-Nov-202374 65

.gitignoreD23-Nov-202321 32

Android.bpD23-Nov-20232 KiB6560

CHANGELOG.mdD23-Nov-20238.6 KiB216145

Cargo.tomlD23-Nov-20232.2 KiB8877

Cargo.toml.origD23-Nov-20231.8 KiB6655

LICENSED23-Nov-202310.8 KiB202169

LICENSE-APACHED23-Nov-202310.8 KiB202169

LICENSE-MITD23-Nov-20231.1 KiB2622

METADATAD23-Nov-2023358 2019

MODULE_LICENSE_APACHE2D23-Nov-20230

OWNERSD23-Nov-202340 21

README.mdD23-Nov-20233.2 KiB8766

TEST_MAPPINGD23-Nov-20231.1 KiB5756

build.rsD23-Nov-20231 KiB4433

cargo2android.jsonD23-Nov-2023198 1111

triagebot.tomlD23-Nov-202310 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