From e1739d04abd6efd4c7dbe742f04ba394e87af576 Mon Sep 17 00:00:00 2001 From: Jacek Chmiel Date: Sun, 17 Jun 2018 12:24:29 +0200 Subject: [PATCH 1/3] Change log dependency to 0.4.x Log dependency introduces several naming changes in API. Besides that the most significant change for us is lifetime change for record location strings from 'static to 'a. This requires more changes in slog and then in slog-async. log -> slog message transition is implemented and working (alongisde with slog and slog-async changes). slog -> log message transition is not implemented yet properly (it is compiling though). --- lib.rs | 74 +++++++++++++++++++++++++++++----------------------------- 1 file changed, 37 insertions(+), 37 deletions(-) diff --git a/lib.rs b/lib.rs index cb8595c..d801bac 100644 --- a/lib.rs +++ b/lib.rs @@ -53,7 +53,7 @@ extern crate slog; extern crate slog_scope; extern crate log; -use log::LogMetadata; +use log::Metadata; use std::{io, fmt}; use slog::Level; @@ -61,44 +61,45 @@ use slog::KV; struct Logger; -fn log_to_slog_level(level: log::LogLevel) -> Level { +fn log_to_slog_level(level: log::Level) -> Level { match level { - log::LogLevel::Trace => Level::Trace, - log::LogLevel::Debug => Level::Debug, - log::LogLevel::Info => Level::Info, - log::LogLevel::Warn => Level::Warning, - log::LogLevel::Error => Level::Error, + log::Level::Trace => Level::Trace, + log::Level::Debug => Level::Debug, + log::Level::Info => Level::Info, + log::Level::Warn => Level::Warning, + log::Level::Error => Level::Error, } } impl log::Log for Logger { - fn enabled(&self, _: &LogMetadata) -> bool { + fn enabled(&self, _: &Metadata) -> bool { true } - fn log(&self, r: &log::LogRecord) { + fn log(&self, r: &log::Record) { let level = log_to_slog_level(r.metadata().level()); let args = r.args(); let target = r.target(); - let module = r.location().__module_path; - let file = r.location().__file; - let line = r.location().line(); let s = slog::RecordStatic { location: &slog::RecordLocation { - file: file, - line: line, + file: r.file().unwrap_or(""), + line: 0, column: 0, - function: "", - module: module, + function: "", + module: r.module_path().unwrap_or(""), }, - level: level, + level, tag: target, }; slog_scope::with_logger(|logger| logger.log(&slog::Record::new(&s, args, b!()))) } + + fn flush(&self) { + //nothing buffered + } } /// Register `slog-stdlog` as `log` backend. @@ -131,10 +132,8 @@ impl log::Log for Logger { /// } /// ``` pub fn init() -> Result<(), log::SetLoggerError> { - log::set_logger(|max_log_level| { - max_log_level.set(log::LogLevelFilter::max()); - Box::new(Logger) - }) + log::set_max_level(log::LevelFilter::max()); + log::set_boxed_logger(Box::new(Logger)) } /// Drain logging `Record`s into `log` crate @@ -198,26 +197,27 @@ impl slog::Drain for StdLog { fn log(&self, info: &slog::Record, logger_values: &slog::OwnedKVList) -> io::Result<()> { let level = match info.level() { - slog::Level::Critical | slog::Level::Error => log::LogLevel::Error, - slog::Level::Warning => log::LogLevel::Warn, - slog::Level::Info => log::LogLevel::Info, - slog::Level::Debug => log::LogLevel::Debug, - slog::Level::Trace => log::LogLevel::Trace, + slog::Level::Critical | slog::Level::Error => log::Level::Error, + slog::Level::Warning => log::Level::Warn, + slog::Level::Info => log::Level::Info, + slog::Level::Debug => log::Level::Debug, + slog::Level::Trace => log::Level::Trace, }; let target = info.tag(); - let location = log::LogLocation { - __module_path: info.module(), - __file: info.file(), - __line: info.line(), - }; - - let lazy = LazyLogString::new(info, logger_values); - // Please don't yell at me for this! :D - // https://github.com/rust-lang-nursery/log/issues/95 - log::__log(level, target, &location, format_args!("{}", lazy)); - + //FIXME: can't make this work... +// let lazy = LazyLogString::new(info, logger_values); + + let r = log::RecordBuilder::new() + .level(level) + .target(target) + .module_path(Some(info.module())) + .file(Some(info.file())) + .line(Some(info.line())) +// .args(format_args!("{}", "xxx")) + .build(); + log::logger().log(&r); Ok(()) } } From 336d157ed08f255ab95dc0e04e4d7cb12df32ad0 Mon Sep 17 00:00:00 2001 From: Jacek Chmiel Date: Sun, 17 Jun 2018 12:55:39 +0200 Subject: [PATCH 2/3] bump log to 0.4.2 --- Cargo.toml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index a6582ad..8d359d9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,9 +16,10 @@ path = "lib.rs" [dependencies] slog = "2" slog-scope = "4" -log = "0.3.6" +log = {version = "0.4.2", features = ["std"] } crossbeam = "0.2.9" [dev-dependencies] slog-term = "2" slog-async = "2" + From bab9165bc90a0e1ffd25219262769da09e5fb9a4 Mon Sep 17 00:00:00 2001 From: Jacek Chmiel Date: Tue, 19 Jun 2018 10:21:22 +0200 Subject: [PATCH 3/3] temporary crates-io patch --- Cargo.toml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Cargo.toml b/Cargo.toml index 8d359d9..92cdf4c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -23,3 +23,6 @@ crossbeam = "0.2.9" slog-term = "2" slog-async = "2" +[patch.crates-io] +slog = { git = "https://github.com/jacekchmiel/slog", branch = "log-0.4-support" } +slog-async = { git = "https://github.com/jacekchmiel/slog-async", branch = "log-0.4-support" } \ No newline at end of file