From 148e6f7b00b89850d46624170b82a932d0302575 Mon Sep 17 00:00:00 2001 From: Marijn Haverbeke Date: Sun, 17 Apr 2011 16:29:18 +0200 Subject: Make log the log level configurable per module This overloads the meaning of RUST_LOG to also allow 'module.submodule' or 'module.somethingelse=2' forms. The first turn on all logging for a module (loglevel 3), the second sets its loglevel to 2. Log levels are: 0: Show only errors 1: Errors and warnings 2: Errors, warnings, and notes 3: Everything, including debug logging Right now, since we only have one 'log' operation, everything happens at level 1 (warning), so the only meaningful thing that can be done with the new RUST_LOG support is disable logging (=0) for some modules. TODOS: * Language support for logging at a specific level * Also add a log level field to tasks, query the current task as well as the current module before logging (log if one of them allows it) * Revise the C logging API to conform to this set-up (globals for per-module log level, query the task level before logging, stop using a global mask) Implementation notes: Crates now contain two extra data structures. A 'module map' that contains names and pointers to the module-log-level globals for each module in the crate that logs, and a 'crate map' that points at the crate's module map, as well as at the crate maps of all external crates it depends on. These are walked by the runtime (in rust_crate.cpp) to set the currect log levels based on RUST_LOG. These module log globals are allocated as-needed whenever a log expression is encountered, and their location is hard-coded into the logging code, which compares the current level to the log statement's level, and skips over all logging code when it is lower. --- src/rt/rust_log.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/rt/rust_log.cpp') diff --git a/src/rt/rust_log.cpp b/src/rt/rust_log.cpp index 3017b549263..076c4b0ae7a 100644 --- a/src/rt/rust_log.cpp +++ b/src/rt/rust_log.cpp @@ -9,6 +9,7 @@ #include #include +// FIXME somehow unify this with the parsing happening in rust_crate.cpp static uint32_t read_type_bit_mask() { uint32_t bits = rust_log::ULOG | rust_log::ERR; @@ -18,14 +19,13 @@ read_type_bit_mask() { str[0] = ','; strcpy(str + 1, env_str); - bits = 0; + bits = rust_log::ULOG; bits |= strstr(str, ",err") ? rust_log::ERR : 0; bits |= strstr(str, ",mem") ? rust_log::MEM : 0; bits |= strstr(str, ",comm") ? rust_log::COMM : 0; bits |= strstr(str, ",task") ? rust_log::TASK : 0; bits |= strstr(str, ",up") ? rust_log::UPCALL : 0; bits |= strstr(str, ",dom") ? rust_log::DOM : 0; - bits |= strstr(str, ",ulog") ? rust_log::ULOG : 0; bits |= strstr(str, ",trace") ? rust_log::TRACE : 0; bits |= strstr(str, ",dwarf") ? rust_log::DWARF : 0; bits |= strstr(str, ",cache") ? rust_log::CACHE : 0; -- cgit 1.4.1-3-g733a5