std: Fix newsched logging truncation

The truncation needs to be done in the console logger in order
to catch all the logging output, and because truncation only matters
when outputting to the console.
This commit is contained in:
Brian Anderson 2013-08-04 21:54:59 -07:00
parent 6c12ca3ac2
commit d123df26ff
2 changed files with 17 additions and 14 deletions

View File

@ -85,16 +85,6 @@ pub fn log_type<T>(level: u32, object: &T) {
fn newsched_log_str(msg: ~str) {
use rt::task::Task;
use rt::local::Local;
use str::StrSlice;
use container::Container;
// Truncate the string
let buf_bytes = 256;
let msg = if msg.len() > buf_bytes {
msg.slice(0, buf_bytes) + "[...]"
} else {
msg
};
unsafe {
match Local::try_unsafe_borrow::<Task>() {

View File

@ -10,6 +10,7 @@
use either::*;
use libc;
use str::StrSlice;
pub trait Logger {
fn log(&mut self, msg: Either<~str, &'static str>);
@ -35,10 +36,22 @@ impl Logger for StdErrLogger {
s
}
};
let dbg = ::libc::STDERR_FILENO as ::io::fd_t;
dbg.write_str(s);
dbg.write_str("\n");
dbg.flush();
// Truncate the string
let buf_bytes = 256;
if s.len() > buf_bytes {
let s = s.slice(0, buf_bytes) + "[...]";
print(s);
} else {
print(s)
};
fn print(s: &str) {
let dbg = ::libc::STDERR_FILENO as ::io::fd_t;
dbg.write_str(s);
dbg.write_str("\n");
dbg.flush();
}
}
}