Skip to content

Commit

Permalink
Add back to_new_file changes
Browse files Browse the repository at this point in the history
  • Loading branch information
fralalonde committed Apr 9, 2019
1 parent 6a20533 commit f16e9fb
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/bucket/atomic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
24 changes: 21 additions & 3 deletions src/output/stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -58,8 +58,26 @@ impl<W: Write + Send + Sync + 'static> Stream<W> {

impl Stream<File> {
/// Write metric values to a file.
pub fn to_file(file: &Path) -> error::Result<Stream<File>> {
Ok(Stream::write_to(File::open(file)?))
pub fn to_file<P: AsRef<Path>>(file: P) -> error::Result<Stream<File>> {
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<P: AsRef<Path>>(file: P, clobber: bool) -> error::Result<Stream<File>> {
let file = OpenOptions::new()
.write(true)
.create(true)
.create_new(!clobber)
.open(file)?;
Ok(Stream::write_to(file))
}
}

Expand Down

0 comments on commit f16e9fb

Please sign in to comment.