Skip to content

Conversation

@njam
Copy link
Collaborator

@njam njam commented Nov 19, 2018

See #13

Example for acceptance testing
#[macro_use]
extern crate slog;
extern crate slog_json;

use std::sync::Mutex;
use slog::Drain;
use std::io;

struct MyWriter {}

impl io::Write for MyWriter {
    fn write(&mut self, buf: &[u8]) -> io::Result<usize> {
        println!("Write: {}", String::from_utf8_lossy(buf));
        Ok(buf.len())
    }
    fn flush(&mut self) -> io::Result<()> {
        println!("Flush!");
        Ok(())
    }
}

fn main() {
    let writer = MyWriter {};
    let drain = slog_json::Json::new(writer)
        .set_flush(true)
        .build();
    let logger = slog::Logger::root(Mutex::new(drain).map(slog::Fuse), o!());

    for i in 1..3 {
        info!(logger, "Hello {}", i; "foo" => "12");
    }
}

@dpc
Copy link
Contributor

dpc commented Nov 19, 2018

I am not sure if doing the flush is always a good idea. It might slow down other people who did not use buffered writer... . Should it be an option?

@njam
Copy link
Collaborator Author

njam commented Nov 19, 2018

Makes sense. Should I turn it off by default (no flush)?

@dpc
Copy link
Contributor

dpc commented Nov 19, 2018

Yes, let's keep it the way it worked before. Otherwise, it would be somewhat of a breaking change.

@njam
Copy link
Collaborator Author

njam commented Nov 20, 2018

I agree. I've pushed a new version. Please review.

@dpc
Copy link
Contributor

dpc commented Nov 20, 2018

Welcome to the team. Please accept the invites, and release at your convenience.

@njam njam merged commit 1fe5137 into slog-rs:master Nov 21, 2018
@njam
Copy link
Collaborator Author

njam commented Nov 21, 2018

Cool, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants