Logram has an implementation of log::Logger
.
- Import logram as library:
[dependencies]
logram = "2.0"
- 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.