From cc6ec8df95fbd8163b7c2c6c34469fb96b704e66 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Sat, 8 Mar 2014 22:11:44 -0800 Subject: log: Introduce liblog, the old std::logging This commit moves all logging out of the standard library into an external crate. This crate is the new crate which is responsible for all logging macros and logging implementation. A few reasons for this change are: * The crate map has always been a bit of a code smell among rust programs. It has difficulty being loaded on almost all platforms, and it's used almost exclusively for logging and only logging. Removing the crate map is one of the end goals of this movement. * The compiler has a fair bit of special support for logging. It has the __log_level() expression as well as generating a global word per module specifying the log level. This is unfairly favoring the built-in logging system, and is much better done purely in libraries instead of the compiler itself. * Initialization of logging is much easier to do if there is no reliance on a magical crate map being available to set module log levels. * If the logging library can be written outside of the standard library, there's no reason that it shouldn't be. It's likely that we're not going to build the highest quality logging library of all time, so third-party libraries should be able to provide just as high-quality logging systems as the default one provided in the rust distribution. With a migration such as this, the change does not come for free. There are some subtle changes in the behavior of liblog vs the previous logging macros: * The core change of this migration is that there is no longer a physical log-level per module. This concept is still emulated (it is quite useful), but there is now only a global log level, not a local one. This global log level is a reflection of the maximum of all log levels specified. The previously generated logging code looked like: if specified_level <= __module_log_level() { println!(...) } The newly generated code looks like: if specified_level <= ::log::LOG_LEVEL { if ::log::module_enabled(module_path!()) { println!(...) } } Notably, the first layer of checking is still intended to be "super fast" in that it's just a load of a global word and a compare. The second layer of checking is executed to determine if the current module does indeed have logging turned on. This means that if any module has a debug log level turned on, all modules with debug log levels get a little bit slower (they all do more expensive dynamic checks to determine if they're turned on or not). Semantically, this migration brings no change in this respect, but runtime-wise, this will have a perf impact on some code. * A `RUST_LOG=::help` directive will no longer print out a list of all modules that can be logged. This is because the crate map will no longer specify the log levels of all modules, so the list of modules is not known. Additionally, warnings can no longer be provided if a malformed logging directive was supplied. The new "hello world" for logging looks like: #[phase(syntax, link)] extern crate log; fn main() { debug!("Hello, world!"); } --- src/libterm/lib.rs | 12 ------------ src/libterm/terminfo/parser/compiled.rs | 26 -------------------------- 2 files changed, 38 deletions(-) (limited to 'src/libterm') diff --git a/src/libterm/lib.rs b/src/libterm/lib.rs index ca142ab8697..089c1668bf3 100644 --- a/src/libterm/lib.rs +++ b/src/libterm/lib.rs @@ -156,8 +156,6 @@ impl Terminal { if s.is_ok() { try!(self.out.write(s.unwrap())); return Ok(true) - } else { - warn!("{}", s.unwrap_err()); } } Ok(false) @@ -177,8 +175,6 @@ impl Terminal { if s.is_ok() { try!(self.out.write(s.unwrap())); return Ok(true) - } else { - warn!("{}", s.unwrap_err()); } } Ok(false) @@ -199,8 +195,6 @@ impl Terminal { if s.is_ok() { try!(self.out.write(s.unwrap())); return Ok(true) - } else { - warn!("{}", s.unwrap_err()); } } Ok(false) @@ -237,12 +231,6 @@ impl Terminal { }); if s.is_ok() { return self.out.write(s.unwrap()) - } else if self.num_colors > 0 { - warn!("{}", s.unwrap_err()); - } else { - // if we support attributes but not color, it would be nice to still warn!() - // but it's not worth testing all known attributes just for this. - debug!("{}", s.unwrap_err()); } Ok(()) } diff --git a/src/libterm/terminfo/parser/compiled.rs b/src/libterm/terminfo/parser/compiled.rs index e9d71d1c2f7..8ba3ad53121 100644 --- a/src/libterm/terminfo/parser/compiled.rs +++ b/src/libterm/terminfo/parser/compiled.rs @@ -195,27 +195,15 @@ pub fn parse(file: &mut io::Reader, assert!(names_bytes > 0); - debug!("names_bytes = {}", names_bytes); - debug!("bools_bytes = {}", bools_bytes); - debug!("numbers_count = {}", numbers_count); - debug!("string_offsets_count = {}", string_offsets_count); - debug!("string_table_bytes = {}", string_table_bytes); - if (bools_bytes as uint) > boolnames.len() { - error!("expected bools_bytes to be less than {} but found {}", boolnames.len(), - bools_bytes); return Err(~"incompatible file: more booleans than expected"); } if (numbers_count as uint) > numnames.len() { - error!("expected numbers_count to be less than {} but found {}", numnames.len(), - numbers_count); return Err(~"incompatible file: more numbers than expected"); } if (string_offsets_count as uint) > stringnames.len() { - error!("expected string_offsets_count to be less than {} but found {}", stringnames.len(), - string_offsets_count); return Err(~"incompatible file: more string offsets than expected"); } @@ -229,26 +217,19 @@ pub fn parse(file: &mut io::Reader, try!(file.read_byte()); // consume NUL - debug!("term names: {:?}", term_names); - let mut bools_map = HashMap::new(); if bools_bytes != 0 { for i in range(0, bools_bytes) { let b = try!(file.read_byte()); if b < 0 { - error!("EOF reading bools after {} entries", i); return Err(~"error: expected more bools but hit EOF"); } else if b == 1 { - debug!("{} set", bnames[i]); bools_map.insert(bnames[i].to_owned(), true); } } } - debug!("bools: {:?}", bools_map); - if (bools_bytes + names_bytes) % 2 == 1 { - debug!("adjusting for padding between bools and numbers"); try!(file.read_byte()); // compensate for padding } @@ -257,14 +238,11 @@ pub fn parse(file: &mut io::Reader, for i in range(0, numbers_count) { let n = try!(file.read_le_u16()); if n != 0xFFFF { - debug!("{}\\#{}", nnames[i], n); numbers_map.insert(nnames[i].to_owned(), n); } } } - debug!("numbers: {:?}", numbers_map); - let mut string_map = HashMap::new(); if string_offsets_count != 0 { @@ -273,13 +251,9 @@ pub fn parse(file: &mut io::Reader, string_offsets.push(try!(file.read_le_u16())); } - debug!("offsets: {:?}", string_offsets); - let string_table = try!(file.read_bytes(string_table_bytes as uint)); if string_table.len() != string_table_bytes as uint { - error!("EOF reading string table after {} bytes, wanted {}", string_table.len(), - string_table_bytes); return Err(~"error: hit EOF before end of string table"); } -- cgit 1.4.1-3-g733a5