Skip to content

Commit

Permalink
test "{tid}" pattern bug
Browse files Browse the repository at this point in the history
  • Loading branch information
nneesshh committed Jul 7, 2023
1 parent c48e767 commit 78e92c2
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 30 deletions.
8 changes: 4 additions & 4 deletions spdlog-macros/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ categories = ["development-tools::debugging"]
proc-macro = true

[dependencies]
nom = "7.1.1"
proc-macro2 = "1.0.47"
quote = "1.0.21"
syn = { version = "1.0.103", features = ["full"] }
nom = "7"
proc-macro2 = "1"
quote = "1"
syn = { version = "1", features = ["full"] }
54 changes: 28 additions & 26 deletions spdlog/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ all-features = true
name = "spdlog"

[features]
default = ["log", "multi-thread", "source-location"]

level-off = []
level-critical = []
level-error = []
Expand All @@ -38,20 +40,20 @@ libsystemd = ["libsystemd-sys"]
multi-thread = ["crossbeam"]

[dependencies]
arc-swap = "1.5.1"
atomic = "0.5.1"
cfg-if = "1.0.0"
chrono = "0.4.22"
crossbeam = { version = "0.8.2", optional = true }
flexible-string = { version = "0.1.0", optional = true }
if_chain = "1.0.2"
arc-swap = "1"
atomic = "0.5"
cfg-if = "1"
chrono = "0.4"
crossbeam = { version = "0.8", optional = true }
flexible-string = { version = "0.1", optional = true }
if_chain = "1"
is-terminal = "0.4"
log = { version = "0.4", optional = true }
once_cell = "1.16.0"
spdlog-macros = { version = "0.1.0", path = "../spdlog-macros" }
spin = "0.9.8"
static_assertions = "1.1.0"
thiserror = "1.0.37"
once_cell = "1"
spdlog-macros = { version = "0.1", path = "../spdlog-macros" }
spin = "0.9"
static_assertions = "1"
thiserror = "1"

[target.'cfg(windows)'.dependencies]
winapi = { version = "0.3.9", features = ["consoleapi", "debugapi", "handleapi", "processenv", "processthreadsapi", "winbase", "wincon"] }
Expand All @@ -60,26 +62,26 @@ winapi = { version = "0.3.9", features = ["consoleapi", "debugapi", "handleapi",
libc = "0.2"

[target.'cfg(target_os = "linux")'.dependencies]
libsystemd-sys = { version = "0.9.3", optional = true }
libsystemd-sys = { version = "0.9", optional = true }

[dev-dependencies]
clap = { version = "3.2.23", features = ["derive"] }
crossbeam = "0.8.2"
regex = "1.7.0"
clap = { version = "3", features = ["derive"] }
crossbeam = "0.8"
regex = "1"

# The following dependencies are used for benchmarks
log = "=0.4.17"
slog = "=2.7.0"
sloggers = "=2.1.1"
log4rs = "=1.2.0"
fern = "=0.6.1"
flexi_logger = "=0.24.1"
tracing = "=0.1.37"
tracing-subscriber = "=0.3.16"
tracing-appender = "=0.2.2"
log = "=0.4"
slog = "=2"
sloggers = "=2"
log4rs = "=1"
fern = "=0.6"
flexi_logger = "=0.24"
tracing = "=0.1"
tracing-subscriber = "=0.3"
tracing-appender = "=0.2"

[build-dependencies]
rustc_version = "0.4.0"
rustc_version = "0.4"

[[bench]]
name = "compare_with_cpp_spdlog"
Expand Down
51 changes: 51 additions & 0 deletions spdlog/examples/05_custom_formatter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ fn main() {

// 2. When you need to implement more complex formatting logic
impl_manually();

// 3.
use_pattern_formatter_by_async_sink();
}

fn use_pattern_formatter() {
Expand Down Expand Up @@ -75,3 +78,51 @@ fn impl_manually() {

info!("format by `MyFormatter` (impl manually)");
}

fn use_pattern_formatter_by_async_sink() {
use spdlog::{
formatter::{pattern, PatternFormatter},
prelude::*,
};

let sss_sink: std::sync::Arc<dyn spdlog::sink::Sink> = std::sync::Arc::new(
spdlog::sink::StdStreamSink::builder()
.std_stream(spdlog::sink::StdStream::Stdout)
.style_mode(spdlog::terminal_style::StyleMode::Never)
.build()
.unwrap(),
);

let async_sink = std::sync::Arc::new(
spdlog::sink::AsyncPoolSink::builder()
.sink(sss_sink)
.build()
.unwrap(),
);

let logger: std::sync::Arc<spdlog::Logger> =
std::sync::Arc::new(spdlog::Logger::builder().sink(async_sink).build().unwrap());

spdlog::set_default_logger(logger);

// Building a pattern formatter with a pattern.
//
// The `pattern!` macro will parse the template string at compile-time.
// See the documentation of `pattern!` macro for more usage.
let new_formatter: Box<PatternFormatter<_>> = Box::new(PatternFormatter::new(pattern!(
"{datetime} - {^{level}} - {payload}{eol}{tid}"
)));

// Setting the new formatter for each sink of the default logger.
for sink in spdlog::default_logger().sinks() {
sink.set_formatter(new_formatter.clone())
}

info!("format by `PatternFormatter`");
spdlog::default_logger().flush();

for _ in 1.. {
std::thread::sleep(std::time::Duration::from_millis(100));
spdlog::default_logger().flush();
}
}

0 comments on commit 78e92c2

Please sign in to comment.