Struct chase::Chaser [] [src]

pub struct Chaser {
    pub line: Line,
    pub path: PathBuf,
    pub initial_no_file_wait: Duration,
    pub initial_no_file_attempts: Option<usize>,
    pub rotation_check_wait: Duration,
    pub rotation_check_attempts: Option<usize>,
    pub not_rotated_wait: Duration,
}

Your entry point for following a file.

Fields

Line to start chasing from

Path of the file you want to chase

When we start running and there is no file and/or file info to be read, how long to wait before retrying

When we start running and there is no file and/or file info to be read, how many times to keep trying. None means no limit.

When we trying to detect a file rotation and there is no file and/or file info to be read, how long to wait before retrying

When we trying to detect a file rotation and there is no file and/or file info to be read, how many times to keep trying. None means no limit.

After we read a file to its end, how long to wait before trying to read the next line again.

Methods

impl Chaser
[src]

[src]

Creates a new Chaser with default options

impl Chaser
[src]

[src]

Start chasing a file synchronously.

The provided callback function will be invoked whenever a line is read.

let temp_dir = TempDir::new("chase-test-sync-docs").unwrap();
let file_path = temp_dir.path().join("test.log");
let mut chaser = Chaser::new(&file_path);

let mut file_write = OpenOptions::new()
  .write(true)
  .append(true)
  .create(true)
  .open(&file_path)
  .unwrap();

write!(file_write, "Hello, world 1\n").unwrap();
write!(file_write, "Hello, world 2\n").unwrap();
write!(file_write, "Hello, world 3\n").unwrap();

let mut seen = Vec::with_capacity(3);

// This is a synchronous loop; so we need to exit manually
chaser.run(|line, _, _| {
    seen.push(line.to_string());
    if seen.len() < 3 {
        Ok(Control::Continue)
    } else {
        Ok(Control::Stop)
    }
}).unwrap();

assert_eq!(seen, vec!["Hello, world 1".to_string(), "Hello, world 2".to_string(), "Hello, world 3".to_string()]);
drop(file_write);
temp_dir.close().unwrap();Run

impl Chaser
[src]

[src]

Consume the given Chaser and returns a Stream from which you can read attempts to read lines from the file

let temp_dir = TempDir::new("chase-test-stream-docs").unwrap();
let file_path = temp_dir.path().join("test.log");
let chaser = Chaser::new(&file_path);

let mut file_write = OpenOptions::new()
  .write(true)
  .append(true)
  .create(true)
  .open(&file_path)
  .unwrap();

write!(file_write, "Hello, world 1\n").unwrap();
write!(file_write, "Hello, world 2\n").unwrap();

let (stream, _) = chaser.run_stream().unwrap();

let accumulated = stream
.take(3) // we'll add another one after this is declared to show things are really async
.fold(String::new(), |mut acc, (line, _, _)| {
acc.push_str(&line);
future::ok(acc)
});

write!(file_write, "Hello, world 3\n").unwrap();
assert_eq!(
    accumulated.wait(),
    Ok("Hello, world 1Hello, world 2Hello, world 3".to_string())
);

drop(file_write);
temp_dir.close().unwrap();Run

impl Chaser
[src]

[src]

Consumes the given chaser and gives you back a standard lib Channel to read from

let temp_dir = TempDir::new("chase-test-channel-docs").unwrap();
let file_path = temp_dir.path().join("test.log");
let chaser = Chaser::new(&file_path);

let mut file_write = OpenOptions::new()
  .write(true)
  .append(true)
  .create(true)
  .open(&file_path)
  .unwrap();

write!(file_write, "Hello, world 1\n").unwrap();
write!(file_write, "Hello, world 2\n").unwrap();

let mut seen = String::new();

let (receiver, _) = chaser.run_channel().unwrap();

seen.push_str(&receiver.recv().unwrap().0);
seen.push_str(&receiver.recv().unwrap().0);

assert_eq!(seen.as_str(), "Hello, world 1Hello, world 2");

write!(file_write, "Hello, world 3\n").unwrap();
seen.push_str(&receiver.recv().unwrap().0);
assert_eq!(seen.as_str(), "Hello, world 1Hello, world 2Hello, world 3");

drop(receiver);
drop(file_write);
temp_dir.close().unwrap();Run

Trait Implementations

impl Debug for Chaser
[src]

[src]

Formats the value using the given formatter.

impl Clone for Chaser
[src]

[src]

Returns a copy of the value. Read more

1.0.0
[src]

Performs copy-assignment from source. Read more