|
28 | 28 | #elif _WIN32 |
29 | 29 | #include <spdlog/sinks/msvc_sink.h> |
30 | 30 | #endif |
| 31 | +#if __has_include(<systemd/sd-journal.h>) |
| 32 | +#include <spdlog/sinks/systemd_sink.h> |
| 33 | +#define _KDSPDSETUP_SYSTEMD_ |
| 34 | +#endif |
31 | 35 |
|
32 | 36 | #include <toml.hpp> |
33 | 37 |
|
@@ -93,6 +97,8 @@ static auto const linuxStrs{ std::vector<std::string>{ "syslog_sink_st", "syslog |
93 | 97 | */ |
94 | 98 | static auto const winStrs{ std::vector<std::string>{ "msvc_sink_st", "msvc_sink_mt" } }; |
95 | 99 |
|
| 100 | +static auto const systemdStrs{ std::vector<std::string>{ "systemd_sink_st", "systemd_sink_mt" } }; |
| 101 | + |
96 | 102 | /** |
97 | 103 | * @brief A simple map associating strings of `spdlog::level::level_enum` names to the enums themselves. |
98 | 104 | * Used to pass an enum to `spdlog::logger::set_level` given a string read from a TOML table. |
@@ -312,6 +318,12 @@ class SPDMaps |
312 | 318 | #define createMsvcSinkMtPtr createMsvcSinkPtr<std::mutex> |
313 | 319 | #endif |
314 | 320 |
|
| 321 | +#ifdef _KDSPDSETUP_SYSTEMD_ |
| 322 | +#define createSystemdSinkStPtr createSystemdSinkPtr<spdlog::details::null_mutex> |
| 323 | + |
| 324 | +#define createSystemdSinkMtPtr createSystemdSinkPtr<std::mutex> |
| 325 | +#endif |
| 326 | + |
315 | 327 | /** |
316 | 328 | * @brief Returns true if a string `typeStr` is present in a vector `strList`, and false if not. |
317 | 329 | * Used to identify a group to which a sink's `type` belongs when reading from a configuration file. |
@@ -574,6 +586,14 @@ auto createMsvcSinkPtr() -> std::shared_ptr<spdlog::sinks::msvc_sink<Mutex>> |
574 | 586 | } |
575 | 587 | #endif |
576 | 588 |
|
| 589 | +#ifdef _KDSPDSETUP_SYSTEMD_ |
| 590 | +template<typename Mutex> |
| 591 | +auto createSystemdSinkPtr(std::string &&ident, bool const enableFormatting) -> std::shared_ptr<spdlog::sinks::systemd_sink<Mutex>> |
| 592 | +{ |
| 593 | + return std::make_shared<spdlog::sinks::systemd_sink<Mutex>>(ident, enableFormatting); |
| 594 | +} |
| 595 | +#endif |
| 596 | + |
577 | 597 | /** |
578 | 598 | * @brief Return the result of calling KDSPDSetup::details::createFileSinkPtr with the correct template argument |
579 | 599 | * based on the value of `typeStr`. Uses macros `createFileSinkStPtr` and `createFileSinkMtPtr` for clarity. |
@@ -651,4 +671,9 @@ auto genFromWinStr(toml::string &&typeStr) -> spdlog::sink_ptr; |
651 | 671 |
|
652 | 672 | #endif |
653 | 673 |
|
| 674 | +#ifdef _KDSPDSETUP_SYSTEMD_ |
| 675 | +auto genFromSystemdStr(toml::string &&typeStr, std::string &&ident, bool const enableFormatting) -> spdlog::sink_ptr; |
| 676 | + |
| 677 | +#endif |
| 678 | + |
654 | 679 | } // namespace KDSPDSetup::details |
0 commit comments