1 unstable release
Uses old Rust 2015
0.1.0 | Feb 10, 2018 |
---|
#38 in #msg
302 downloads per month
Used in lstty
14KB
246 lines
logging
A logging fascility inspired by the python logging framework.
This library implements named herachical loggers which have message handlers associated with them.
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() {
logging::debug("app started");
let log = logging::get("myapp");
log.add_handler(logging::ConsoleHandler::new());
log.add_handler(Arc::new(Box::new(MyOwnHandler {})));
log.info("created".to_owned());
{
let sub_log = logging::get("myapp.special");
sub_log.debug("some other stuff");
}
}
TODO
- Add support for yaml configuration files.
- Rotating file handler.
lib.rs
:
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");
}
Dependencies
~74KB