Skip to content

Latest commit

 

History

History
57 lines (46 loc) · 1.57 KB

lib.md

File metadata and controls

57 lines (46 loc) · 1.57 KB

Usage with log

Logram has an implementation of log::Logger.

  1. Import logram as library:
[dependencies]
logram = "2.0"
  1. Initialize the logram:
use logram;
use log::{warn, info, Level};

fn main() {
    logram::init(
        Level::Error, // log level
        String::from("1496993932:AAFrF5aTnQEeruljp3ZHqVUSkgVS9Ra_aT8"), // bot token
        String::from("79098882"), // chat ID
        None, // proxy url, if needed
    )
    .unwrap();

    info!("Application started");

    if cfg!(target_os = "windows") {
        warn!("Oh, shi...");
    }
}

Or you can use the logram's log::Logger implementation itself in the composite logger, e.g. multi_log:

use log::{debug, error, info, trace, warn, Level, LevelFilter};
use logram::TelegramLogger;
use simplelog::{self, SimpleLogger};
use multi_log::MultiLogger;

fn main() {
    let simple_logger = SimpleLogger::new(LevelFilter::Warn, simplelog::Config::default());
    let logram = TelegramLogger::new(
        Level::Info,
        String::from("1496993932:AAFrF5aTnQEeruljp3ZHqVUSkgVS9Ra_aT8"),
        String::from("79098882"),
        None,
    )
    .unwrap();

    MultiLogger::init(vec![simple_logger, Box::new(logram)], Level::Info).unwrap();

    debug!("some debug message");
    error!("well, I'm a useless example of code, sad");
}

Warning: log records with target starts with tokio_reactor, hyper, mio, want or reqwest will be skipped, because limitations in log.