From ac2a24ecc9df66279a7b6df478593b34e1d2449f Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Mon, 6 Jan 2014 10:26:11 -0800 Subject: 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 --- src/libnative/lib.rs | 2 +- src/libnative/task.rs | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) (limited to 'src/libnative') diff --git a/src/libnative/lib.rs b/src/libnative/lib.rs index 9c30e94194d..31395216f2b 100644 --- a/src/libnative/lib.rs +++ b/src/libnative/lib.rs @@ -34,7 +34,7 @@ pub mod io; pub mod task; // XXX: this should not exist here -#[cfg(stage0)] +#[cfg(stage0, nativestart)] #[lang = "start"] pub fn lang_start(main: *u8, argc: int, argv: **u8) -> int { use std::cast; diff --git a/src/libnative/task.rs b/src/libnative/task.rs index 661358a64e9..ad3cbc7db92 100644 --- a/src/libnative/task.rs +++ b/src/libnative/task.rs @@ -55,11 +55,15 @@ pub fn spawn(f: proc()) { pub fn spawn_opts(opts: TaskOpts, f: proc()) { let TaskOpts { watched: _watched, - notify_chan, name, stack_size + notify_chan, name, stack_size, + logger, stderr, stdout, } = opts; let mut task = ~Task::new(); task.name = name; + task.logger = logger; + task.stderr = stderr; + task.stdout = stdout; match notify_chan { Some(chan) => { let on_exit = proc(task_result) { chan.send(task_result) }; -- cgit 1.4.1-3-g733a5