Skip to content

Commit

Permalink
Merge branch 'master' into feature/log-line-number-and-filename
Browse files Browse the repository at this point in the history
  • Loading branch information
davidbarsky authored Dec 22, 2021
2 parents 7afbe52 + 6dd9d23 commit 989e07f
Show file tree
Hide file tree
Showing 10 changed files with 333 additions and 143 deletions.
32 changes: 32 additions & 0 deletions examples/examples/appender-multifile.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
//! This example demonstrates the use of multiple files with
//! `tracing-appender`'s `RollingFileAppender`
//!
use tracing_appender::rolling;
use tracing_subscriber::fmt::writer::MakeWriterExt;

#[path = "fmt/yak_shave.rs"]
mod yak_shave;

fn main() {
// Log all `tracing` events to files prefixed with `debug`. Since these
// files will be written to very frequently, roll the log file every minute.
let debug_file = rolling::minutely("./logs", "debug");
// Log warnings and errors to a separate file. Since we expect these events
// to occur less frequently, roll that file on a daily basis instead.
let warn_file = rolling::daily("./logs", "warnings").with_max_level(tracing::Level::WARN);
let all_files = debug_file.and(warn_file);

tracing_subscriber::fmt()
.with_writer(all_files)
.with_ansi(false)
.with_max_level(tracing::Level::TRACE)
.init();

yak_shave::shave_all(6);
tracing::info!("sleeping for a minute...");

std::thread::sleep(std::time::Duration::from_secs(60));

tracing::info!("okay, time to shave some more yaks!");
yak_shave::shave_all(10);
}
1 change: 1 addition & 0 deletions tracing-appender/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ rust-version = "1.51.0"
[dependencies]
crossbeam-channel = "0.5.0"
time = { version = "0.3", default-features = false, features = ["formatting"] }
parking_lot = { optional = true, version = "0.11.2" }

[dependencies.tracing-subscriber]
path = "../tracing-subscriber"
Expand Down
4 changes: 2 additions & 2 deletions tracing-appender/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ This crate can be used in a few ways to record spans/events:
- Using *any* type implementing [`std::io::Write`][write] in a
non-blocking fashion.
- Using [`NonBlocking`][non_blocking] and [`RollingFileAppender`][file_appender]
together to write to write to log files in a non-blocking fashion.
together to write to log files in a non-blocking fashion.

## Rolling File Appender

Expand Down Expand Up @@ -137,7 +137,7 @@ fn main() {
[tracing]: https://docs.rs/tracing/latest/tracing/
[make_writer]: https://docs.rs/tracing-subscriber/latest/tracing_subscriber/fmt/trait.MakeWriter.html
[write]: https://doc.rust-lang.org/std/io/trait.Write.html
[non_blocking]: https://docs.rs/tracing-appender/latest/tracing_appender/non_blocking/indexx.html
[non_blocking]: https://docs.rs/tracing-appender/latest/tracing_appender/non_blocking/index.html
[rolling]: https://docs.rs/tracing-appender/latest/tracing_appender/rolling/index.html
[guard]: https://docs.rs/tracing-appender/latest/tracing_appender/non_blocking/struct.WorkerGuard.html
[file_appender]: https://docs.rs/tracing-appender/latest/tracing_appender/rolling/struct.RollingFileAppender.html
Expand Down
105 changes: 0 additions & 105 deletions tracing-appender/src/inner.rs

This file was deleted.

4 changes: 2 additions & 2 deletions tracing-appender/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,14 +153,14 @@ use crate::non_blocking::{NonBlocking, WorkerGuard};

use std::io::Write;

mod inner;

pub mod non_blocking;

pub mod rolling;

mod worker;

pub(crate) mod sync;

/// Convenience function for creating a non-blocking, off-thread writer.
///
/// See the [`non_blocking` module's docs][mod@non_blocking]'s for more details.
Expand Down
Loading

0 comments on commit 989e07f

Please sign in to comment.