Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
logger.hpp
Go to the documentation of this file.
1#pragma once
2#include <fc/string.hpp>
3#include <fc/time.hpp>
5
6#ifndef DEFAULT_LOGGER
7#define DEFAULT_LOGGER "default"
8#endif
9
10namespace fc
11{
12
13 class appender;
14
25 class logger
26 {
27 public:
28 static logger get( const fc::string& name = DEFAULT_LOGGER );
29 static void update( const fc::string& name, logger& log );
30
31 logger();
32 logger( const string& name, const logger& parent = nullptr );
33 logger( std::nullptr_t );
34 logger( const logger& c );
35 logger( logger&& c );
36 ~logger();
37 logger& operator=(const logger&);
39 friend bool operator==( const logger&, nullptr_t );
40 friend bool operator!=( const logger&, nullptr_t );
41
44 logger& set_parent( const logger& l );
45 logger get_parent()const;
46
47 void set_name( const fc::string& n );
48 const fc::string& name()const;
49
50 bool is_enabled( log_level e )const;
51 void log( log_message m );
52
53 private:
54 friend struct log_config;
55 void add_appender( const std::shared_ptr<appender>& a );
56
57 private:
58 class impl;
59 std::shared_ptr<impl> my;
60 };
61
62} // namespace fc
63
64// suppress warning "conditional expression is constant" in the while(0) for visual c++
65// http://cnicholson.net/2009/03/stupid-c-tricks-dowhile0-and-c4127/
66#define FC_MULTILINE_MACRO_BEGIN do {
67#ifdef _MSC_VER
68# define FC_MULTILINE_MACRO_END \
69 __pragma(warning(push)) \
70 __pragma(warning(disable:4127)) \
71 } while (0) \
72 __pragma(warning(pop))
73#else
74# define FC_MULTILINE_MACRO_END } while (0)
75#endif
76
77#define fc_dlog( LOGGER, FORMAT, ... ) \
78 FC_MULTILINE_MACRO_BEGIN \
79 if( (LOGGER).is_enabled( fc::log_level::debug ) ) \
80 (LOGGER).log( FC_LOG_MESSAGE( debug, FORMAT, __VA_ARGS__ ) ); \
81 FC_MULTILINE_MACRO_END
82
83#define fc_ilog( LOGGER, FORMAT, ... ) \
84 FC_MULTILINE_MACRO_BEGIN \
85 if( (LOGGER).is_enabled( fc::log_level::info ) ) \
86 (LOGGER).log( FC_LOG_MESSAGE( info, FORMAT, __VA_ARGS__ ) ); \
87 FC_MULTILINE_MACRO_END
88
89#define fc_wlog( LOGGER, FORMAT, ... ) \
90 FC_MULTILINE_MACRO_BEGIN \
91 if( (LOGGER).is_enabled( fc::log_level::warn ) ) \
92 (LOGGER).log( FC_LOG_MESSAGE( warn, FORMAT, __VA_ARGS__ ) ); \
93 FC_MULTILINE_MACRO_END
94
95#define fc_elog( LOGGER, FORMAT, ... ) \
96 FC_MULTILINE_MACRO_BEGIN \
97 if( (LOGGER).is_enabled( fc::log_level::error ) ) \
98 (LOGGER).log( FC_LOG_MESSAGE( error, FORMAT, __VA_ARGS__ ) ); \
99 FC_MULTILINE_MACRO_END
100
101#define dlog( FORMAT, ... ) \
102 FC_MULTILINE_MACRO_BEGIN \
103 if( (fc::logger::get(DEFAULT_LOGGER)).is_enabled( fc::log_level::debug ) ) \
104 (fc::logger::get(DEFAULT_LOGGER)).log( FC_LOG_MESSAGE( debug, FORMAT, __VA_ARGS__ ) ); \
105 FC_MULTILINE_MACRO_END
106
111#define ulog( FORMAT, ... ) \
112 FC_MULTILINE_MACRO_BEGIN \
113 if( (fc::logger::get("user")).is_enabled( fc::log_level::debug ) ) \
114 (fc::logger::get("user")).log( FC_LOG_MESSAGE( debug, FORMAT, __VA_ARGS__ ) ); \
115 FC_MULTILINE_MACRO_END
116
117
118#define ilog( FORMAT, ... ) \
119 FC_MULTILINE_MACRO_BEGIN \
120 if( (fc::logger::get(DEFAULT_LOGGER)).is_enabled( fc::log_level::info ) ) \
121 (fc::logger::get(DEFAULT_LOGGER)).log( FC_LOG_MESSAGE( info, FORMAT, __VA_ARGS__ ) ); \
122 FC_MULTILINE_MACRO_END
123
124#define wlog( FORMAT, ... ) \
125 FC_MULTILINE_MACRO_BEGIN \
126 if( (fc::logger::get(DEFAULT_LOGGER)).is_enabled( fc::log_level::warn ) ) \
127 (fc::logger::get(DEFAULT_LOGGER)).log( FC_LOG_MESSAGE( warn, FORMAT, __VA_ARGS__ ) ); \
128 FC_MULTILINE_MACRO_END
129
130#define elog( FORMAT, ... ) \
131 FC_MULTILINE_MACRO_BEGIN \
132 if( (fc::logger::get(DEFAULT_LOGGER)).is_enabled( fc::log_level::error ) ) \
133 (fc::logger::get(DEFAULT_LOGGER)).log( FC_LOG_MESSAGE( error, FORMAT, __VA_ARGS__ ) ); \
134 FC_MULTILINE_MACRO_END
135
136#include <boost/preprocessor/seq/for_each.hpp>
137#include <boost/preprocessor/seq/enum.hpp>
138#include <boost/preprocessor/seq/size.hpp>
139#include <boost/preprocessor/seq/seq.hpp>
140#include <boost/preprocessor/stringize.hpp>
141#include <boost/preprocessor/punctuation/paren.hpp>
142
143
144#define FC_FORMAT_ARG(r, unused, base) \
145 BOOST_PP_STRINGIZE(base) ": ${" BOOST_PP_STRINGIZE( base ) "} "
146
147#define FC_FORMAT_ARGS(r, unused, base) \
148 BOOST_PP_LPAREN() BOOST_PP_STRINGIZE(base),fc::variant(base) BOOST_PP_RPAREN()
149
150#define FC_FORMAT( SEQ )\
151 BOOST_PP_SEQ_FOR_EACH( FC_FORMAT_ARG, v, SEQ )
152
153// takes a ... instead of a SEQ arg because it can be called with an empty SEQ
154// from FC_CAPTURE_AND_THROW()
155#define FC_FORMAT_ARG_PARAMS( ... )\
156 BOOST_PP_SEQ_FOR_EACH( FC_FORMAT_ARGS, v, __VA_ARGS__ )
157
158#define idump( SEQ ) \
159 ilog( FC_FORMAT(SEQ), FC_FORMAT_ARG_PARAMS(SEQ) )
160#define wdump( SEQ ) \
161 wlog( FC_FORMAT(SEQ), FC_FORMAT_ARG_PARAMS(SEQ) )
162#define edump( SEQ ) \
163 elog( FC_FORMAT(SEQ), FC_FORMAT_ARG_PARAMS(SEQ) )
164
165// this disables all normal logging statements -- not something you'd normally want to do,
166// but it's useful if you're benchmarking something and suspect logging is causing
167// a slowdown.
168#ifdef FC_DISABLE_LOGGING
169# undef ulog
170# define ulog(...) FC_MULTILINE_MACRO_BEGIN FC_MULTILINE_MACRO_END
171# undef elog
172# define elog(...) FC_MULTILINE_MACRO_BEGIN FC_MULTILINE_MACRO_END
173# undef wlog
174# define wlog(...) FC_MULTILINE_MACRO_BEGIN FC_MULTILINE_MACRO_END
175# undef ilog
176# define ilog(...) FC_MULTILINE_MACRO_BEGIN FC_MULTILINE_MACRO_END
177# undef dlog
178# define dlog(...) FC_MULTILINE_MACRO_BEGIN FC_MULTILINE_MACRO_END
179#endif
aggregates a message along with the context and associated meta-information.
static void update(const fc::string &name, logger &log)
Definition logger.cpp:92
friend bool operator!=(const logger &, nullptr_t)
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
logger(std::nullptr_t)
friend bool operator==(const logger &, nullptr_t)
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 types and helper macros necessary for generating log messages.
#define DEFAULT_LOGGER
Definition logger.hpp:7
namespace sysio::chain
Definition authority.cpp:3
std::string string
Definition string.hpp:10
decltype(nullptr) nullptr_t
Definition utility.hpp:28
const GenericPointer< typename T::ValueType > T2 T::AllocatorType & a
Definition pointer.h:1181
int l