Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -250,9 +250,9 @@ jobs:
journalctl --no-pager -o json -t native_linux | jq -e -s $'.[1].PRIORITY == "3" and .[1].CODE_FILE == null and .[1].CODE_LINE == null and .[1].TID != null'

journalctl --no-pager -o json -t native_linux_srcloc | jq -e -s $'.[0].MESSAGE == "[demo] [info] info message from spdlog-rs\'s JournaldSink\n"'
journalctl --no-pager -o json -t native_linux_srcloc | jq -e -s $'.[0].PRIORITY == "6" and .[0].CODE_FILE == "linux.rs" and .[0].CODE_LINE == "15" and .[0].TID != null'
journalctl --no-pager -o json -t native_linux_srcloc | jq -e -s $'.[0].PRIORITY == "6" and .[0].CODE_FILE == "linux.rs" and .[0].CODE_LINE != null and .[0].TID != null'
journalctl --no-pager -o json -t native_linux_srcloc | jq -e -s $'.[1].MESSAGE == "[demo] [error] error message from spdlog-rs\'s JournaldSink { error_code=114514 }\n"'
journalctl --no-pager -o json -t native_linux_srcloc | jq -e -s $'.[1].PRIORITY == "3" and .[1].CODE_FILE == "linux.rs" and .[1].CODE_LINE == "16" and .[1].TID != null'
journalctl --no-pager -o json -t native_linux_srcloc | jq -e -s $'.[1].PRIORITY == "3" and .[1].CODE_FILE == "linux.rs" and .[1].CODE_LINE != null and .[1].TID != null'

test-native-windows:
strategy:
Expand Down
20 changes: 10 additions & 10 deletions spdlog/benches/spdlog-rs/cmp_cpp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ extern crate test;
#[path = "../common/mod.rs"]
mod common;

use std::{env, sync::Arc, thread, time::Instant};
use std::{env, thread, time::Instant};

use clap::Parser;
use spdlog::{
Expand Down Expand Up @@ -36,38 +36,38 @@ fn bench_threaded_logging(threads: usize, iters: usize) {
info!("**********************************************************************");

let logger = build_test_logger(|b| {
b.sink(Arc::new(
b.sink(
FileSink::builder()
.path(common::BENCH_LOGS_PATH.join("FileSink.log"))
.truncate(true)
.build()
.build_arc()
.unwrap(),
))
)
.name("basic_mt")
});
bench_mt(logger, threads, iters);

let logger = build_test_logger(|b| {
b.sink(Arc::new(
b.sink(
RotatingFileSink::builder()
.base_path(common::BENCH_LOGS_PATH.join("RotatingFileSink_FileSize.log"))
.rotation_policy(RotationPolicy::FileSize(FILE_SIZE))
.max_files(ROTATING_FILES)
.build()
.build_arc()
.unwrap(),
))
)
.name("rotating_mt")
});
bench_mt(logger, threads, iters);

let logger = build_test_logger(|b| {
b.sink(Arc::new(
b.sink(
RotatingFileSink::builder()
.base_path(common::BENCH_LOGS_PATH.join("RotatingFileSink_Daily.log"))
.rotation_policy(RotationPolicy::Daily { hour: 0, minute: 0 })
.build()
.build_arc()
.unwrap(),
))
)
.name("daily_mt")
});
bench_mt(logger, threads, iters);
Expand Down
39 changes: 19 additions & 20 deletions spdlog/benches/spdlog-rs/cmp_cpp_async.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ extern crate test;
#[path = "../common/mod.rs"]
mod common;

use std::{cmp, env, num::NonZeroUsize, sync::Arc, thread, time::Instant};
use std::{cmp, env, num::NonZeroUsize, thread, time::Instant};

use clap::Parser;
use spdlog::{
Expand All @@ -32,25 +32,24 @@ fn bench(

let queue_size = NonZeroUsize::new(queue_size).unwrap();
for _ in 0..iters {
let thread_pool = Arc::new(ThreadPool::builder().capacity(queue_size).build().unwrap());

let file_sink = Arc::new(
FileSink::builder()
.path(common::BENCH_LOGS_PATH.join(file_name))
.truncate(true)
.build()
.unwrap(),
);

let async_sink = Arc::new(
AsyncPoolSink::builder()
.thread_pool(thread_pool)
.overflow_policy(policy)
.sink(file_sink)
.error_handler(|err| panic!("an error occurred: {err}"))
.build()
.unwrap(),
);
let thread_pool = ThreadPool::builder()
.capacity(queue_size)
.build_arc()
.unwrap();

let file_sink = FileSink::builder()
.path(common::BENCH_LOGS_PATH.join(file_name))
.truncate(true)
.build_arc()
.unwrap();

let async_sink = AsyncPoolSink::builder()
.thread_pool(thread_pool)
.overflow_policy(policy)
.sink(file_sink)
.error_handler(|err| panic!("an error occurred: {err}"))
.build_arc()
.unwrap();

let logger = Logger::builder()
.sink(async_sink)
Expand Down
14 changes: 5 additions & 9 deletions spdlog/benches/spdlog-rs/kv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ extern crate test;
#[path = "../common/mod.rs"]
mod common;

use std::sync::Arc;

use spdlog::{prelude::*, sink::*};
use test::Bencher;

Expand All @@ -18,13 +16,11 @@ use test_utils::*;

fn logger(name: &str) -> Logger {
let path = common::BENCH_LOGS_PATH.join(format!("kv_{name}.log"));
let sink = Arc::new(
FileSink::builder()
.path(path)
.truncate(true)
.build()
.unwrap(),
);
let sink = FileSink::builder()
.path(path)
.truncate(true)
.build_arc()
.unwrap();
build_test_logger(|b| b.sink(sink))
}

Expand Down
56 changes: 25 additions & 31 deletions spdlog/benches/spdlog-rs/spdlog_rs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,14 @@ impl Mode {
match self {
Self::Sync => sink,
Self::Async => {
let thread_pool = Arc::new(ThreadPool::builder().build().unwrap());

Arc::new(
AsyncPoolSink::builder()
.thread_pool(thread_pool)
.overflow_policy(OverflowPolicy::DropIncoming)
.sink(sink)
.build()
.unwrap(),
)
let thread_pool = ThreadPool::builder().build_arc().unwrap();

AsyncPoolSink::builder()
.thread_pool(thread_pool)
.overflow_policy(OverflowPolicy::DropIncoming)
.sink(sink)
.build_arc()
.unwrap()
}
}
}
Expand Down Expand Up @@ -82,31 +80,27 @@ fn bench_any(bencher: &mut Bencher, mode: Mode, sink: Arc<dyn Sink>) {
}

fn bench_file_inner(bencher: &mut Bencher, mode: Mode) {
let sink: Arc<dyn Sink> = Arc::new(
FileSink::builder()
.path(mode.path("file"))
.truncate(true)
.build()
.unwrap(),
);
let sink = FileSink::builder()
.path(mode.path("file"))
.truncate(true)
.build_arc()
.unwrap();
bench_any(bencher, mode, sink);
}

fn bench_rotating_inner(bencher: &mut Bencher, rotation_policy: RotationPolicy) {
let sink = Arc::new(
RotatingFileSink::builder()
.base_path(Mode::Sync.path(match rotation_policy {
RotationPolicy::FileSize(_) => "rotating_file_size",
RotationPolicy::Daily { .. } => "rotating_daily",
RotationPolicy::Hourly => "rotating_hourly",
RotationPolicy::Period { .. } => "rotating_period",
}))
.rotation_policy(rotation_policy)
.max_files(common::ROTATING_FILES)
.rotate_on_open(true)
.build()
.unwrap(),
);
let sink = RotatingFileSink::builder()
.base_path(Mode::Sync.path(match rotation_policy {
RotationPolicy::FileSize(_) => "rotating_file_size",
RotationPolicy::Daily { .. } => "rotating_daily",
RotationPolicy::Hourly => "rotating_hourly",
RotationPolicy::Period { .. } => "rotating_period",
}))
.rotation_policy(rotation_policy)
.max_files(common::ROTATING_FILES)
.rotate_on_open(true)
.build_arc()
.unwrap();
bench_any(bencher, Mode::Sync, sink);
}

Expand Down
58 changes: 25 additions & 33 deletions spdlog/examples/02_file.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::{env, sync::Arc, time::Duration};
use std::{env, time::Duration};

use spdlog::{
prelude::*,
Expand All @@ -18,8 +18,8 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
fn configure_file_logger() -> Result<(), Box<dyn std::error::Error>> {
let path = env::current_exe()?.with_file_name("file.log");

let file_sink = Arc::new(FileSink::builder().path(path).build()?);
let new_logger = Arc::new(Logger::builder().sink(file_sink).build()?);
let file_sink = FileSink::builder().path(path).build_arc()?;
let new_logger = Logger::builder().sink(file_sink).build_arc()?;
spdlog::set_default_logger(new_logger);

info!("this log will be written to the file `all.log`");
Expand All @@ -30,13 +30,11 @@ fn configure_file_logger() -> Result<(), Box<dyn std::error::Error>> {
fn configure_rotating_daily_file_logger() -> Result<(), Box<dyn std::error::Error>> {
let path = env::current_exe()?.with_file_name("rotating_daily.log");

let file_sink = Arc::new(
RotatingFileSink::builder()
.base_path(path)
.rotation_policy(RotationPolicy::Daily { hour: 0, minute: 0 })
.build()?,
);
let new_logger = Arc::new(Logger::builder().sink(file_sink).build()?);
let file_sink = RotatingFileSink::builder()
.base_path(path)
.rotation_policy(RotationPolicy::Daily { hour: 0, minute: 0 })
.build_arc()?;
let new_logger = Logger::builder().sink(file_sink).build_arc()?;
spdlog::set_default_logger(new_logger);

info!("this log will be written to the file `rotating_daily.log`, and the file will be rotated daily at 00:00");
Expand All @@ -47,13 +45,11 @@ fn configure_rotating_daily_file_logger() -> Result<(), Box<dyn std::error::Erro
fn configure_rotating_size_file_logger() -> Result<(), Box<dyn std::error::Error>> {
let path = env::current_exe()?.with_file_name("rotating_size.log");

let file_sink = Arc::new(
RotatingFileSink::builder()
.base_path(path)
.rotation_policy(RotationPolicy::FileSize(1024))
.build()?,
);
let new_logger = Arc::new(Logger::builder().sink(file_sink).build()?);
let file_sink = RotatingFileSink::builder()
.base_path(path)
.rotation_policy(RotationPolicy::FileSize(1024))
.build_arc()?;
let new_logger = Logger::builder().sink(file_sink).build_arc()?;
spdlog::set_default_logger(new_logger);

info!("this log will be written to the file `rotating_size.log`, and the file will be rotated when its size reaches 1024 bytes");
Expand All @@ -64,13 +60,11 @@ fn configure_rotating_size_file_logger() -> Result<(), Box<dyn std::error::Error
fn configure_rotating_hourly_file_logger() -> Result<(), Box<dyn std::error::Error>> {
let path = env::current_exe()?.with_file_name("rotating_hourly.log");

let file_sink = Arc::new(
RotatingFileSink::builder()
.base_path(path)
.rotation_policy(RotationPolicy::Hourly)
.build()?,
);
let new_logger = Arc::new(Logger::builder().sink(file_sink).build()?);
let file_sink = RotatingFileSink::builder()
.base_path(path)
.rotation_policy(RotationPolicy::Hourly)
.build_arc()?;
let new_logger = Logger::builder().sink(file_sink).build_arc()?;
spdlog::set_default_logger(new_logger);

info!("this log will be written to the file `rotating_hourly.log`, and the file will be rotated every hour");
Expand All @@ -81,15 +75,13 @@ fn configure_rotating_hourly_file_logger() -> Result<(), Box<dyn std::error::Err
fn configure_rotating_period_file_logger() -> Result<(), Box<dyn std::error::Error>> {
let path = env::current_exe()?.with_file_name("rotating_period.log");

let file_sink = Arc::new(
RotatingFileSink::builder()
.base_path(path)
.rotation_policy(RotationPolicy::Period(Duration::from_secs(
60 * 90, // 90 minutes
)))
.build()?,
);
let new_logger = Arc::new(Logger::builder().sink(file_sink).build()?);
let file_sink = RotatingFileSink::builder()
.base_path(path)
.rotation_policy(RotationPolicy::Period(Duration::from_secs(
60 * 90, // 90 minutes
)))
.build_arc()?;
let new_logger = Logger::builder().sink(file_sink).build_arc()?;
spdlog::set_default_logger(new_logger);

info!("this log will be written to the file `rotating_period.log`, and the file will be rotated every 1.5 hours");
Expand Down
16 changes: 7 additions & 9 deletions spdlog/examples/03_logger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,13 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {

// Or completely replace it with a new one.
let path = env::current_exe()?.with_file_name("all.log");
let file_sink = Arc::new(FileSink::builder().path(path).build()?);
let file_sink = FileSink::builder().path(path).build_arc()?;

let new_logger = Arc::new(
Logger::builder()
.level_filter(LevelFilter::All)
.flush_level_filter(LevelFilter::MoreSevereEqual(Level::Warn))
.sink(file_sink.clone())
.build()?,
);
let new_logger = Logger::builder()
.level_filter(LevelFilter::All)
.flush_level_filter(LevelFilter::MoreSevereEqual(Level::Warn))
.sink(file_sink.clone())
.build_arc()?;
new_logger.set_flush_period(Some(Duration::from_secs(3)));
spdlog::set_default_logger(new_logger);

Expand All @@ -42,7 +40,7 @@ struct AppDatabase {
impl AppDatabase {
fn new(all_log_sink: Arc<dyn Sink>) -> Result<Self, Box<dyn std::error::Error>> {
let path = env::current_exe()?.with_file_name("db.log");
let db_file_sink = Arc::new(FileSink::builder().path(path).build()?);
let db_file_sink = FileSink::builder().path(path).build_arc()?;

let logger = Logger::builder()
.name("database")
Expand Down
16 changes: 7 additions & 9 deletions spdlog/examples/07_async.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::{env, sync::Arc};
use std::env;

use spdlog::{
prelude::*,
Expand All @@ -7,17 +7,15 @@ use spdlog::{

fn main() -> Result<(), Box<dyn std::error::Error>> {
let path = env::current_exe()?.with_file_name("async.log");
let file_sink = Arc::new(FileSink::builder().path(path).build()?);
let file_sink = FileSink::builder().path(path).build_arc()?;

// AsyncPoolSink is a combined sink which wraps other sinks
let async_pool_sink = Arc::new(AsyncPoolSink::builder().sink(file_sink).build()?);
let async_pool_sink = AsyncPoolSink::builder().sink(file_sink).build_arc()?;

let async_logger = Arc::new(
Logger::builder()
.sink(async_pool_sink)
.flush_level_filter(LevelFilter::All)
.build()?,
);
let async_logger = Logger::builder()
.sink(async_pool_sink)
.flush_level_filter(LevelFilter::All)
.build_arc()?;

info!(logger: async_logger, "Hello, async!");

Expand Down
Loading
Loading