Support arbitrary stdout/stderr/logger handles
This will allow capturing of common things like logging messages, stdout prints (using stdio println), and failure messages (printed to stderr). Any new prints added to libstd should be funneled through these task handles to allow capture as well. Additionally, this commit redirects logging back through a `Logger` trait so the log level can be usefully consumed by an arbitrary logger. This commit also introduces methods to set the task-local stdout handles: * std::io::stdio::set_stdout * std::io::stdio::set_stderr * std::io::logging::set_logger These methods all return the previous logger just in case it needs to be used for inspection. I plan on using this infrastructure for extra::test soon, but we don't quite have the primitives that I'd like to use for it, so it doesn't migrate extra::test at this time. Closes #6369
This commit is contained in:
@@ -55,7 +55,9 @@
|
||||
|
||||
use any::Any;
|
||||
use comm::{Chan, Port};
|
||||
use io::Writer;
|
||||
use kinds::Send;
|
||||
use logging::Logger;
|
||||
use option::{None, Some, Option};
|
||||
use result::{Result, Ok, Err};
|
||||
use rt::local::Local;
|
||||
@@ -103,7 +105,10 @@ pub struct TaskOpts {
|
||||
watched: bool,
|
||||
notify_chan: Option<Chan<TaskResult>>,
|
||||
name: Option<SendStr>,
|
||||
stack_size: Option<uint>
|
||||
stack_size: Option<uint>,
|
||||
logger: Option<~Logger>,
|
||||
stdout: Option<~Writer>,
|
||||
stderr: Option<~Writer>,
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -138,22 +143,6 @@ pub fn task() -> TaskBuilder {
|
||||
}
|
||||
|
||||
impl TaskBuilder {
|
||||
fn consume(mut self) -> TaskBuilder {
|
||||
let gen_body = self.gen_body.take();
|
||||
let notify_chan = self.opts.notify_chan.take();
|
||||
let name = self.opts.name.take();
|
||||
TaskBuilder {
|
||||
opts: TaskOpts {
|
||||
watched: self.opts.watched,
|
||||
notify_chan: notify_chan,
|
||||
name: name,
|
||||
stack_size: self.opts.stack_size
|
||||
},
|
||||
gen_body: gen_body,
|
||||
can_not_copy: None,
|
||||
}
|
||||
}
|
||||
|
||||
/// Cause the parent task to collect the child's exit status (and that of
|
||||
/// all transitively-watched grandchildren) before reporting its own.
|
||||
pub fn watched(&mut self) {
|
||||
@@ -250,26 +239,12 @@ impl TaskBuilder {
|
||||
*/
|
||||
pub fn spawn(mut self, f: proc()) {
|
||||
let gen_body = self.gen_body.take();
|
||||
let notify_chan = self.opts.notify_chan.take();
|
||||
let name = self.opts.name.take();
|
||||
let x = self.consume();
|
||||
let opts = TaskOpts {
|
||||
watched: x.opts.watched,
|
||||
notify_chan: notify_chan,
|
||||
name: name,
|
||||
stack_size: x.opts.stack_size
|
||||
};
|
||||
let f = match gen_body {
|
||||
Some(gen) => {
|
||||
gen(f)
|
||||
}
|
||||
None => {
|
||||
f
|
||||
}
|
||||
Some(gen) => gen(f),
|
||||
None => f
|
||||
};
|
||||
|
||||
let t: ~Task = Local::take();
|
||||
t.spawn_sibling(opts, f);
|
||||
t.spawn_sibling(self.opts, f);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -316,7 +291,10 @@ impl TaskOpts {
|
||||
watched: true,
|
||||
notify_chan: None,
|
||||
name: None,
|
||||
stack_size: None
|
||||
stack_size: None,
|
||||
logger: None,
|
||||
stdout: None,
|
||||
stderr: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user