Skip to content

Commit

Permalink
Add shortcut methods StdStreamSinkBuilder::{stdout,stderr}
Browse files Browse the repository at this point in the history
  • Loading branch information
SpriteOvO committed Jan 25, 2025
1 parent 3b81097 commit ff21f40
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
6 changes: 3 additions & 3 deletions spdlog/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ use std::{

use cfg_if::cfg_if;
use error::EnvLevelError;
use sink::{Sink, StdStream, StdStreamSink};
use sink::{Sink, StdStreamSink};
use sync::*;

/// The statically resolved log level filter.
Expand Down Expand Up @@ -388,13 +388,13 @@ static DEFAULT_LOGGER: OnceCell<ArcSwap<Logger>> = OnceCell::new();
fn default_logger_ref() -> &'static ArcSwap<Logger> {
DEFAULT_LOGGER.get_or_init(|| {
let stdout = StdStreamSink::builder()
.std_stream(StdStream::Stdout)
.stdout()
.level_filter(LevelFilter::MoreVerbose(Level::Warn))
.build()
.unwrap();

let stderr = StdStreamSink::builder()
.std_stream(StdStream::Stderr)
.stderr()
.level_filter(LevelFilter::MoreSevereEqual(Level::Warn))
.build()
.unwrap();
Expand Down
24 changes: 24 additions & 0 deletions spdlog/src/sink/std_stream_sink.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,30 @@ pub struct StdStreamSinkBuilder<ArgSS> {
}

impl<ArgSS> StdStreamSinkBuilder<ArgSS> {
/// Specifies the target standard stream as stdout.
///
/// This is equivalent to `std_stream(StdStream::Stdout)`.
#[must_use]
pub fn stdout(self) -> StdStreamSinkBuilder<StdStream> {
StdStreamSinkBuilder {
common_builder_impl: self.common_builder_impl,
std_stream: StdStream::Stdout,
style_mode: self.style_mode,
}
}

/// Specifies the target standard stream as stderr.
///
/// This is equivalent to `std_stream(StdStream::Stderr)`.
#[must_use]
pub fn stderr(self) -> StdStreamSinkBuilder<StdStream> {
StdStreamSinkBuilder {
common_builder_impl: self.common_builder_impl,
std_stream: StdStream::Stderr,
style_mode: self.style_mode,
}
}

/// Specifies the target standard stream.
///
/// This parameter is **required**.
Expand Down

0 comments on commit ff21f40

Please sign in to comment.