Skip to content

Commit

Permalink
Add async logger set-up (#47)
Browse files Browse the repository at this point in the history
* Allow sync and async loggers to be created respectively

* Fix and use string for map key

* Change to TYPE instead of SYNC for stating sync/async logger

* Reuse function instead of using special enum find

* Add parsing of global and named thread pools

* Add mapping of thread pool to async logger

* Implement getting async overflow policy

* Split up impl of parsing logger

* Add unit tests for basic async loggers

* Rename unit_test.cpp to others.cpp

* Add logger with sink test cases

* Add global thread pool testing

* Change all versions to 0.3.0-pre

* Add test cases for localized thread pool

* Add test case for multiple thread pools

* Add to CHANGELOG

* Fix GCC 4.9 old syntax issue

* Add async into proper testing and put into README
  • Loading branch information
guangie88 authored Nov 2, 2019
1 parent 0417a98 commit 12eda19
Show file tree
Hide file tree
Showing 16 changed files with 946 additions and 93 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## Unreleased

- Add support for async logger. This fixes
([#44](https://github.com/guangie88/spdlog_setup/issues/44))
- This makes logger accepts `type`, which takes in `sync` or `async`.
`sync` is default. Refer to the README for more details.
- Change support to `spdlog` `v1.y.z` tag release, currently tested all `v1.0.0`
to `v1.3.1` to be working. This fixes
([#26](https://github.com/guangie88/spdlog_setup/issues/26)).
Expand Down
3 changes: 2 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,10 @@ install(
endif()

# spdlog_setup_unit_test
FILE(GLOB unit_test_cpps src/unit_test/*.cpp)
if(SPDLOG_SETUP_INCLUDE_UNIT_TESTS)
add_executable(spdlog_setup_unit_test
src/unit_test/unit_test.cpp)
${unit_test_cpps})

set_property(TARGET spdlog_setup_unit_test PROPERTY CXX_STANDARD 11)

Expand Down
25 changes: 25 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,31 @@ level = "trace"
name = "console"
sinks = ["console_st", "console_mt"]
pattern = "succient"

# Async

[global_thread_pool]
queue_size = 8192
num_threads = 1

[[thread_pool]]
name = "tp"
queue_size = 4096
num_threads = 2

[[logger]]
type = "async"
name = "global_async"
sinks = ["console_mt"]
pattern = "succient"

[[logger]]
type = "async"
name = "local_async"
sinks = ["console_mt"]
pattern = "succient"
thread_pool = "tp"
overflow_policy = "overrun_oldest" # block (default) | overrun_oldest
```

### Tagged-Base Pre-TOML File Configuration
Expand Down
25 changes: 25 additions & 0 deletions config/log_conf_linux.toml
Original file line number Diff line number Diff line change
Expand Up @@ -125,3 +125,28 @@ level = "trace"
name = "console"
sinks = ["console_st", "console_mt"]
pattern = "succient"

# Async

[global_thread_pool]
queue_size = 8192
num_threads = 1

[[thread_pool]]
name = "tp"
queue_size = 4096
num_threads = 2

[[logger]]
type = "async"
name = "global_async"
sinks = ["console_mt"]
pattern = "succient"

[[logger]]
type = "async"
name = "local_async"
sinks = ["console_mt"]
pattern = "succient"
thread_pool = "tp"
overflow_policy = "overrun_oldest" # block (default) | overrun_oldest
39 changes: 39 additions & 0 deletions config/log_conf_win.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,20 @@
# check out https://github.com/gabime/spdlog/wiki/3.-Custom-formatting
global_pattern = "[%Y-%m-%dT%T%z] [%L] <%n>: %v"

[global_thread_pool]
queue_size = 8192
num_threads = 1

[[thread_pool]]
name = "tp_1"
queue_size = 4096
num_threads = 2

[[thread_pool]]
name = "tp_2"
queue_size = 2048
num_threads = 4

[[sink]]
name = "console_st"
type = "stdout_sink_st"
Expand Down Expand Up @@ -106,3 +120,28 @@ level = "trace"
name = "console"
sinks = ["console_st", "console_mt"]
pattern = "succient"

# Async

[global_thread_pool]
queue_size = 8192
num_threads = 1

[[thread_pool]]
name = "tp"
queue_size = 4096
num_threads = 2

[[logger]]
type = "async"
name = "global_async"
sinks = ["console_mt"]
pattern = "succient"

[[logger]]
type = "async"
name = "local_async"
sinks = ["console_mt"]
pattern = "succient"
thread_pool = "tp"
overflow_policy = "overrun_oldest" # block (default) | overrun_oldest
8 changes: 4 additions & 4 deletions include/spdlog_setup/conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ void from_file_with_tag_replacement(
cpptoml::parser parser(toml_ss);
const auto config = parser.parse();

details::setup_impl(config);
details::setup(config);
} catch (const setup_error &) {
throw;
} catch (const exception &e) {
Expand Down Expand Up @@ -158,7 +158,7 @@ auto from_file_and_override_with_tag_replacement(
details::merge_config_root(merged_config, override_config);
}

details::setup_impl(merged_config);
details::setup(merged_config);
return has_override;
} catch (const setup_error &) {
throw;
Expand All @@ -174,7 +174,7 @@ inline void from_file(const std::string &toml_path) {

try {
const auto config = cpptoml::parse_file(toml_path);
details::setup_impl(config);
details::setup(config);
} catch (const exception &e) {
throw setup_error(e.what());
}
Expand Down Expand Up @@ -205,7 +205,7 @@ inline auto from_file_and_override(
details::merge_config_root(merged_config, override_config);
}

details::setup_impl(merged_config);
details::setup(merged_config);
return has_override;
} catch (const exception &e) {
throw setup_error(e.what());
Expand Down
Loading

0 comments on commit 12eda19

Please sign in to comment.