Created
March 13, 2016 16:10
-
-
Save oholiab/6d27ffa15f31eafa37bb to your computer and use it in GitHub Desktop.
Redirect logging to stdout (or other file) example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#[macro_use] | |
extern crate log; | |
extern crate env_logger; | |
extern crate gag; | |
use gag::Redirect; | |
use std::fs::File; | |
use std::os::unix::io::FromRawFd; | |
const STDOUT: i32 = 1; | |
// const STDERR: i32 = 2; | |
fn main() { | |
unsafe { | |
let stdout = File::from_raw_fd(STDOUT); | |
env_logger::init().unwrap(); | |
let redirect = Redirect::stderr(stdout); | |
error!("Hello, stdout!"); | |
drop(redirect); | |
error!("Hello, stderr!"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment