diff options
| author | Alex Crichton <alex@alexcrichton.com> | 2013-08-28 01:33:48 -0700 |
|---|---|---|
| committer | Alex Crichton <alex@alexcrichton.com> | 2013-09-25 16:30:05 -0700 |
| commit | eb2b25dd6d38157213742b048fad63fa4ceec691 (patch) | |
| tree | e41f9af78454e8f6641dead395274419d843ab63 /src/libstd/logging.rs | |
| parent | af25f58ac3da45899ed65b3af965150c8a90dcda (diff) | |
Refactor the logging system for fewer allocations
This lifts various restrictions on the runtime, for example the character limit when logging a message. Right now the old debug!-style macros still involve allocating (because they use fmt! syntax), but the new debug2! macros don't involve allocating at all (unless the formatter for a type requires allocation.
Diffstat (limited to 'src/libstd/logging.rs')
| -rw-r--r-- | src/libstd/logging.rs | 25 |
1 files changed, 14 insertions, 11 deletions
diff --git a/src/libstd/logging.rs b/src/libstd/logging.rs index 1a463a499cb..342d0828f82 100644 --- a/src/libstd/logging.rs +++ b/src/libstd/logging.rs @@ -10,11 +10,11 @@ //! Logging +use fmt; use option::*; use os; use rt; use rt::logging::{Logger, StdErrLogger}; -use send_str::SendStrOwned; /// Turns on logging to stdout globally pub fn console_on() { @@ -37,7 +37,17 @@ pub fn console_off() { rt::logging::console_off(); } -fn newsched_log_str(msg: ~str) { +#[cfg(stage0)] +#[doc(hidden)] +pub fn log(_level: u32, s: ~str) { + // this is a terrible approximation, but it gets the job done (for stage0 at + // least) + ::io::println(s); +} + +#[allow(missing_doc)] +#[cfg(not(stage0))] +pub fn log(_level: u32, args: &fmt::Arguments) { use rt::task::Task; use rt::local::Local; @@ -46,20 +56,13 @@ fn newsched_log_str(msg: ~str) { match optional_task { Some(local) => { // Use the available logger - (*local).logger.log(SendStrOwned(msg)); + (*local).logger.log(args); } None => { // There is no logger anywhere, just write to stderr let mut logger = StdErrLogger; - logger.log(SendStrOwned(msg)); + logger.log(args); } } } } - -// XXX: This will change soon to not require an allocation. This is an unstable -// api which should not be used outside of the macros in ext/expand. -#[doc(hidden)] -pub fn log(_level: u32, msg: ~str) { - newsched_log_str(msg); -} |
