1 unstable release

Uses old Rust 2015

0.1.0 Feb 10, 2018

#40 in #msg

Download history 2/week @ 2024-01-25 8/week @ 2024-02-08 54/week @ 2024-02-15 51/week @ 2024-02-22 27/week @ 2024-02-29 29/week @ 2024-03-07 58/week @ 2024-03-14 120/week @ 2024-03-21 53/week @ 2024-03-28 45/week @ 2024-04-04 19/week @ 2024-04-11 25/week @ 2024-04-18 33/week @ 2024-04-25 29/week @ 2024-05-02 38/week @ 2024-05-09

127 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