diff --git a/src/bucket/atomic.rs b/src/bucket/atomic.rs index ebfed39..4bc0372 100755 --- a/src/bucket/atomic.rs +++ b/src/bucket/atomic.rs @@ -239,7 +239,7 @@ impl AtomicBucket { } /// Set this bucket's aggregated metrics flush output. - #[deprecated(since = "0.7.2", note = "Use sink()")] + #[deprecated(since = "0.7.2", note = "Use drain()")] pub fn set_drain(&self, new_drain: impl Output + Send + Sync + 'static) { self.drain(new_drain) } diff --git a/src/output/stream.rs b/src/output/stream.rs index 7b18a24..d34cd14 100755 --- a/src/output/stream.rs +++ b/src/output/stream.rs @@ -14,7 +14,7 @@ use output::format::{Formatting, LineFormat, SimpleFormat}; use queue::queue_out; use std::cell::RefCell; -use std::fs::File; +use std::fs::{File, OpenOptions}; use std::io::{self, Write}; use std::path::Path; use std::rc::Rc; @@ -58,8 +58,26 @@ impl Stream { impl Stream { /// Write metric values to a file. - pub fn to_file(file: &Path) -> error::Result> { - Ok(Stream::write_to(File::open(file)?)) + pub fn to_file>(file: P) -> error::Result> { + let file = OpenOptions::new() + .write(true) + .create(true) + .append(true) + .open(file)?; + Ok(Stream::write_to(file)) + } + + /// Write to a new file. + /// + /// Creates a new file to dump data into. If `clobber` is set to true, it allows overwriting + /// existing file, if false, the attempt will result in an error. + pub fn to_new_file>(file: P, clobber: bool) -> error::Result> { + let file = OpenOptions::new() + .write(true) + .create(true) + .create_new(!clobber) + .open(file)?; + Ok(Stream::write_to(file)) } }