Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
logger.cpp
Go to the documentation of this file.
1#include <fc/log/logger.hpp>
3#include <fc/log/appender.hpp>
5#include <fc/filesystem.hpp>
6#include <unordered_map>
7#include <string>
9
10namespace fc {
11
13 public:
15 :_parent(nullptr),_enabled(true),_additivity(false),_level(log_level::warn){}
21
22 std::vector<appender::ptr> _appenders;
23 };
24
25
27 :my( new impl() ){}
28
30
31 logger::logger( const string& name, const logger& parent )
32 :my( new impl() )
33 {
34 my->_name = name;
35 my->_parent = parent;
36 }
37
38
40 :my(l.my){}
41
43 :my(fc::move(l.my)){}
44
46
48 my = l.my;
49 return *this;
50 }
52 fc_swap(my,l.my);
53 return *this;
54 }
55 bool operator==( const logger& l, std::nullptr_t ) { return !l.my; }
56 bool operator!=( const logger& l, std::nullptr_t ) { return !!l.my; }
57
59 return e >= my->_level;
60 }
61
63 std::unique_lock g( log_config::get().log_mutex );
64 m.get_context().append_context( my->_name );
65
66 for( auto itr = my->_appenders.begin(); itr != my->_appenders.end(); ++itr ) {
67 try {
68 (*itr)->log( m );
69 } catch( fc::exception& er ) {
70 std::cerr << "ERROR: logger::log fc::exception: " << er.to_detail_string() << std::endl;
71 } catch( const std::exception& e ) {
72 std::cerr << "ERROR: logger::log std::exception: " << e.what() << std::endl;
73 } catch( ... ) {
74 std::cerr << "ERROR: logger::log unknown exception: " << std::endl;
75 }
76 }
77
78 if( my->_additivity && my->_parent != nullptr) {
79 logger parent = my->_parent;
80 g.unlock();
81 parent.log( m );
82 }
83 }
84
85 void logger::set_name( const fc::string& n ) { my->_name = n; }
86 const fc::string& logger::name()const { return my->_name; }
87
89 return log_config::get_logger( s );
90 }
91
92 void logger::update( const fc::string& name, logger& log ) {
94 }
95
96 logger logger::get_parent()const { return my->_parent; }
97 logger& logger::set_parent(const logger& p) { my->_parent = p; return *this; }
98
99 log_level logger::get_log_level()const { return my->_level; }
100 logger& logger::set_log_level(log_level ll) { my->_level = ll; return *this; }
101
102 void logger::add_appender( const std::shared_ptr<appender>& a ) {
103 my->_appenders.push_back(a);
104 }
105
106 bool configure_logging( const logging_config& cfg );
108
109} // namespace fc
const mie::Vuint & p
Definition bn.cpp:27
std::string name
Used to generate a useful error report when an exception is thrown.
Definition exception.hpp:58
std::string to_detail_string(log_level ll=log_level::all) const
void append_context(const fc::string &c)
aggregates a message along with the context and associated meta-information.
log_context get_context() const
fc::string _name
Definition logger.cpp:16
log_level _level
Definition logger.cpp:20
std::vector< appender::ptr > _appenders
Definition logger.cpp:22
static void update(const fc::string &name, logger &log)
Definition logger.cpp:92
logger get_parent() const
Definition logger.cpp:96
logger & operator=(const logger &)
Definition logger.cpp:47
logger & set_log_level(log_level e)
Definition logger.cpp:100
static logger get(const fc::string &name=DEFAULT_LOGGER)
Definition logger.cpp:88
void log(log_message m)
Definition logger.cpp:62
logger & set_parent(const logger &l)
Definition logger.cpp:97
void set_name(const fc::string &n)
Definition logger.cpp:85
log_level get_log_level() const
Definition logger.cpp:99
const fc::string & name() const
Definition logger.cpp:86
bool is_enabled(log_level e) const
Definition logger.cpp:58
Defines exception's used by fc.
Defines types and helper macros necessary for generating log messages.
namespace sysio::chain
Definition authority.cpp:3
bool do_default_config
Definition logger.cpp:107
std::string string
Definition string.hpp:10
bool operator!=(const array< T, N > &a, const array< T, N > &b)
Definition array.hpp:102
bool operator==(const array< T, N > &a, const array< T, N > &b)
Definition array.hpp:91
void configure_logging(const fc::path &log_config)
decltype(nullptr) nullptr_t
Definition utility.hpp:28
const GenericPointer< typename T::ValueType > T2 T::AllocatorType & a
Definition pointer.h:1181
static logger get_logger(const fc::string &name)
static void update_logger(const fc::string &name, logger &log)
static logging_config default_config()
void fc_swap(T &a, T &b)
Definition utility.hpp:211
char * s
int l