1 unstable release

Uses old Rust 2015

0.1.0 Feb 10, 2018

#37 in #msg

Download history 57/week @ 2024-07-19 52/week @ 2024-07-26 60/week @ 2024-08-02 36/week @ 2024-08-09 31/week @ 2024-08-16 20/week @ 2024-08-23 35/week @ 2024-08-30 38/week @ 2024-09-06 46/week @ 2024-09-13 63/week @ 2024-09-20 40/week @ 2024-09-27 23/week @ 2024-10-04 47/week @ 2024-10-11 127/week @ 2024-10-18 43/week @ 2024-10-25 52/week @ 2024-11-01

270 downloads per month
Used in lstty

MIT license

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