Expand description
The logosaurus crate provides a logging implementation that works with the log
crate. The
crate and the logger are modeled after the Go standard library’s log package.
The primary type is Logger
, which represents a logging object. Use
init
to globally initialize a logger with the log
crate.
Every log message is output on a separate line: if the message being printed does not end in a newline, the logger will add one.
The default logger writes logs to stderr using this format:
WARN 2020/10/02 21:27:03 hello, world
§Examples
§Using the default logger
use log::{debug};
use logosaurus::{Logger};
fn main() {
logosaurus::init(Logger::default()).unwrap();
debug!("hello, world"); // DEBUG 2020/10/02 21:27:03 hello, world
}
§Using a custom logger
use log::{self, debug};
use logosaurus::{Logger, L_STD, L_SHORT_FILE, L_MICROSECONDS};
use std::io;
fn main() {
let logger = Logger::builder(io::stdout())
.set_level(log::LevelFilter::Debug)
.set_flags(L_STD | L_SHORT_FILE | L_MICROSECONDS)
.set_prefix("myprogram: ")
.build();
logosaurus::init(logger).unwrap();
debug!("hello, world"); // myprogram: DEBUG 2020/10/02 21:27:03.123123 main.rs:12: hello, world
}
Structs§
- Logger
- Represents a logging object that writes to a specified output. It can be used simultaneously from multiple threads; it guarantees to serialize writes.
- Logger
Builder - Builder for
Logger
.
Constants§
- L_DATE
- Date in local time zone: 2009/01/23.
- L_LEVEL
- Log level printed in capitalized form: INFO, TRACE, etc. Padded to width 5.
- L_
LONG_ FILE - Module, file name, and line number:
foo src/file.rs:3
. - L_
MICROSECONDS - Microsecond resolution: 17:05:23.023123; assumes
L_TIME
. - L_
MSG_ PREFIX - Move the “prefix” from the beginning of the header to the end of the header, just before the message.
- L_NONE
- No header.
- L_
SHORT_ FILE - Final file name element and line number:
file.rs:3
. - L_STD
- Initial values for the default logger constructed with
Logger::default()
. - L_TIME
- Time in local time zone: 17:05:23.
- L_UTC
- If
L_DATE
orL_TIME
is set, use UTC rather than the local time.
Functions§
Type Aliases§
- Flag
- Formatting flags for the header in log output.
See the
L_*
constants.