Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
logger_config.hpp
Go to the documentation of this file.
1#pragma once
2#include <fc/log/logger.hpp>
3#include <fc/log/appender.hpp>
4#include <mutex>
5#include <string>
6#include <unordered_map>
7#include <vector>
8
9namespace fc {
10 class path;
12 appender_config(const string& name = "",
13 const string& type = "",
14 variant args = variant()) :
15 name(name),
16 type(type),
17 args(fc::move(args)),
18 enabled(true)
19 {}
20 string name;
21 string type;
23 bool enabled;
24 };
25
28 string name;
31 std::optional<log_level> level;
32 bool enabled;
35 std::vector<string> appenders;
36 };
37
40 std::vector<string> includes;
41 std::vector<appender_config> appenders;
42 std::vector<logger_config> loggers;
43 };
44
45 struct log_config {
46
47 template<typename T>
48 static bool register_appender(const fc::string& type) {
49 return register_appender( type, std::make_shared<detail::appender_factory_impl<T>>() );
50 }
51
52 static bool register_appender( const fc::string& type, const appender_factory::ptr& f );
53
54 static logger get_logger( const fc::string& name );
55 static void update_logger( const fc::string& name, logger& log );
56
57 static void initialize_appenders( boost::asio::io_service& ios );
58
59 static bool configure_logging( const logging_config& l );
60
61 private:
62 static log_config& get();
63
64 friend class logger;
65
66 std::mutex log_mutex;
67 std::unordered_map<std::string, appender_factory::ptr> appender_factory_map;
68 std::unordered_map<std::string, appender::ptr> appender_map;
69 std::unordered_map<std::string, logger> logger_map;
70 };
71
73 bool configure_logging( const logging_config& l );
74
75 void set_os_thread_name( const string& name );
76 void set_thread_name( const string& name );
77 const string& get_thread_name();
78}
79
81FC_REFLECT( fc::appender_config, (name)(type)(args)(enabled) )
82FC_REFLECT( fc::logger_config, (name)(parent)(level)(enabled)(additivity)(appenders) )
83FC_REFLECT( fc::logging_config, (includes)(appenders)(loggers) )
std::string name
std::shared_ptr< appender_factory > ptr
Definition appender.hpp:19
wraps boost::filesystem::path to provide platform independent path manipulation.
stores null, int64, uint64, double, bool, string, std::vector<variant>, and variant_object's.
Definition variant.hpp:191
namespace sysio::chain
Definition authority.cpp:3
std::string string
Definition string.hpp:10
std::optional< fc::string > ostring
Definition url.hpp:10
void set_thread_name(const string &name)
const string & get_thread_name()
void set_os_thread_name(const string &name)
void configure_logging(const fc::path &log_config)
#define FC_REFLECT(TYPE, MEMBERS)
Specializes fc::reflector for TYPE.
Definition reflect.hpp:311
appender_config(const string &name="", const string &type="", variant args=variant())
static void initialize_appenders(boost::asio::io_service &ios)
static logger get_logger(const fc::string &name)
static bool configure_logging(const logging_config &l)
static void update_logger(const fc::string &name, logger &log)
static bool register_appender(const fc::string &type)
std::vector< string > appenders
std::optional< log_level > level
if not set, then parents level is used.
logger_config(const fc::string &name="")
bool additivity
if any appenders are sepecified, then parent's appenders are not set.
std::vector< logger_config > loggers
std::vector< string > includes
static logging_config default_config()
std::vector< appender_config > appenders
int l