TARAXA
Loading...
Searching...
No Matches
logging.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <spdlog/async.h>
4#include <spdlog/spdlog.h>
5
6#include <string>
7
9
10namespace taraxa::logger {
11
12using Logger = std::shared_ptr<spdlog::logger>;
13
14class Logging {
15 public:
16 static Logging& get() {
17 static Logging instance;
18 return instance;
19 }
20
27 void Init(const LoggingConfig& logging_config, bool global_init = false);
28
34 void Deinit(bool global_init = false);
35
42 Logger CreateChannelLogger(const std::string& channel);
43
44 private:
45 Logging() = default;
46 ~Logging() = default;
47 Logging(const Logging&) = delete;
48 Logging& operator=(const Logging&) = delete;
49
50 // Logging config
52
53 // Sinks for all loggers
54 std::vector<spdlog::sink_ptr> all_loggers_sinks_;
55 // Sinks only for specific loggers
56 std::unordered_map<std::string /* logger channel name*/, std::vector<spdlog::sink_ptr>> specific_loggers_sinks_;
57
58 // Logging threadpool
59 // Using one worker thread decouples the application's logging calls from the
60 // actual I/O, reducing blocking in the main application threads. However, the throughput is limited by the single
61 // worker thread's capacity
62 std::shared_ptr<spdlog::details::thread_pool> logging_tp_;
63
64 bool initialized_{false};
65
66 // If logging is initialized with global_init flag, deinitialize only if called with global_init flag too
68};
69
71
72} // namespace taraxa::logger
Definition logging.hpp:14
bool global_initialized_
Definition logging.hpp:67
Logging & operator=(const Logging &)=delete
bool initialized_
Definition logging.hpp:64
void Init(const LoggingConfig &logging_config, bool global_init=false)
Initializes logging according to the provided logging_config.
Definition logging.cpp:56
static Logging & get()
Definition logging.hpp:16
Logger CreateChannelLogger(const std::string &channel)
Creates (or returns existing) channel logger.
Definition logging.cpp:135
std::vector< spdlog::sink_ptr > all_loggers_sinks_
Definition logging.hpp:54
Logging(const Logging &)=delete
LoggingConfig logging_config_
Definition logging.hpp:51
std::unordered_map< std::string, std::vector< spdlog::sink_ptr > > specific_loggers_sinks_
Definition logging.hpp:56
void Deinit(bool global_init=false)
Deinit logger.
Definition logging.cpp:119
std::shared_ptr< spdlog::details::thread_pool > logging_tp_
Definition logging.hpp:62
Definition logging.hpp:10
std::shared_ptr< spdlog::logger > Logger
Definition logging.hpp:12
LoggingConfig CreateDefaultLoggingConfig()
Definition logging.cpp:168
Definition logging_config.hpp:12