Expand description
A logging fascility inspired by the python logging framework.
This library implements named herachical loggers which have message handlers associated with them.
The framework is intended more for people who want to set log levels for there application without the need to recompile the software.
§features
- Thread safe.
- Easy to extend.
- Log handlers can be added and removed at runtime.
- Log levels can be changed at runtime.
§behavior
- Via default there is no log handler added.
- The default log level of all loggers is
DEFAULT
. - Log messages bubble up to their parents and will be logged by all intermediate handlers.
§usage
extern crate logging;
use std::sync::Arc;
struct MyOwnHandler {}
impl logging::Handler for MyOwnHandler {
fn emit(&self, msg: &logging::Message) {
print!("{:7} | {}", msg.name, msg.msg);
}
}
fn main() {
// you will see nothing, because no handler added yet
logging::debug("app started");
logging::root().add_handler(Arc::new(Box::new(MyOwnHandler {})));
let log = logging::get("myapp");
log.add_handler(logging::ConsoleHandler::new());
// will be printed by both handlers
log.info("created".to_owned());
{
let sub_log = logging::get("myapp.special");
sub_log.debug("some other stuff");
}
log.level = logging::Level::WARN;
// will not be printed by the handler of `myapp`.
log.info("unly plain not in color");
}
Structs§
- Console
Handler - Colorfull console logging
- File
Handler - Logging to a file
- Message
- A message to be logged.
- _Logger
- A logger node.
Enums§
- Level
- The aviable logging levels.
Traits§
- Handler
- Handels an emitted message.
Functions§
- debug
- Convenient debug log to the root logger.
- error
- Convenient error log to the root logger.
- fatal
- Convenient fatal log to the root logger.
- get
- Gets a Logger instance by it’s name.
- info
- Convenient info log to the root logger.
- root
- Gets the root logger.
- warn
- Convenient warn log to the root logger.
Type Aliases§
- Logger
- A logger instance.