BitShares-Core  7.0.2
BitShares blockchain node software and command-line wallet software
log_message.hpp
Go to the documentation of this file.
1 #pragma once
2 
6 #include <fc/config.hpp>
7 #include <fc/time.hpp>
8 #include <fc/variant_object.hpp>
9 #include <memory>
10 #include <string>
11 
12 namespace fc
13 {
14  namespace detail
15  {
16  class log_context_impl;
17  class log_message_impl;
18  }
19 
23  class log_level
24  {
25  public:
32  enum values
33  {
34  all,
40  };
41  log_level( values v = off ):value(v){}
42  explicit log_level( int v ):value( static_cast<values>(v)){}
43  operator int()const { return value; }
45  };
46 
47  void to_variant( log_level e, variant& v, uint32_t max_depth = 1 );
48  void from_variant( const variant& e, log_level& ll, uint32_t max_depth = 1 );
49 
57  {
58  public:
59  log_context();
61  const char* file,
62  uint64_t line,
63  const char* method );
64  ~log_context();
65  explicit log_context( const variant& v, uint32_t max_depth );
66  variant to_variant( uint32_t max_depth )const;
67 
68  std::string get_file()const;
69  uint64_t get_line_number()const;
70  std::string get_method()const;
71  std::string get_thread_name()const;
72  std::string get_task_name()const;
73  std::string get_host_name()const;
75  log_level get_log_level()const;
76  std::string get_context()const;
77 
78  void append_context( const std::string& c );
79 
80  std::string to_string()const;
81  private:
82  std::shared_ptr<detail::log_context_impl> my;
83  };
84 
85  void to_variant( const log_context& l, variant& v, uint32_t max_depth );
86  void from_variant( const variant& l, log_context& c, uint32_t max_depth );
87 
107  {
108  public:
109  log_message();
115  log_message( log_context ctx, std::string format, variant_object args = variant_object() );
116  ~log_message();
117 
118  log_message( const variant& v, uint32_t max_depth );
119  variant to_variant(uint32_t max_depth)const;
120 
121  std::string get_message()const;
122 
123  log_context get_context()const;
124  std::string get_format()const;
125  variant_object get_data()const;
126 
127  private:
128  std::shared_ptr<detail::log_message_impl> my;
129  };
130 
131  void to_variant( const log_message& l, variant& v, uint32_t max_depth );
132  void from_variant( const variant& l, log_message& c, uint32_t max_depth );
133 
134  typedef std::vector<log_message> log_messages;
135 
136 
137 } // namespace fc
138 
140 
141 #ifndef __func__
142 #define __func__ __FUNCTION__
143 #endif
144 
151 #define FC_LOG_CONTEXT(LOG_LEVEL) \
152  fc::log_context( fc::log_level::LOG_LEVEL, (const char*)__FILE__, __LINE__, (const char*)__func__ )
153 
163 #define FC_LOG_MESSAGE( LOG_LEVEL, FORMAT, ... ) \
164  fc::log_message( FC_LOG_CONTEXT(LOG_LEVEL), \
165  FORMAT, \
166  fc::limited_mutable_variant_object( FC_MAX_LOG_OBJECT_DEPTH, true )__VA_ARGS__ )
167 
fc::log_context::to_variant
variant to_variant(uint32_t max_depth) const
Definition: log_message.cpp:166
fc::log_message::get_data
variant_object get_data() const
Definition: log_message.cpp:211
fc::log_level::error
@ error
Definition: log_message.hpp:38
fc::variant_object
An order-perserving dictionary of variant's.
Definition: variant_object.hpp:20
fc::log_message::log_message
log_message()
Definition: log_message.cpp:184
config.hpp
fc::log_level::all
@ all
Definition: log_message.hpp:34
fc::log_level::warn
@ warn
Definition: log_message.hpp:37
fc::log_context::append_context
void append_context(const std::string &c)
Definition: log_message.cpp:84
fc::log_message::to_variant
variant to_variant(uint32_t max_depth) const
Definition: log_message.cpp:201
FC_REFLECT_TYPENAME
FC_REFLECT_TYPENAME(fc::log_message)
fc::log_message::get_format
std::string get_format() const
Definition: log_message.cpp:210
fc::log_level::debug
@ debug
Definition: log_message.hpp:35
fc::log_level::off
@ off
Definition: log_message.hpp:39
fc
Definition: api.hpp:15
fc::log_context::get_log_level
log_level get_log_level() const
Definition: log_message.cpp:162
fc::log_context::log_context
log_context()
Definition: log_message.cpp:44
variant_object.hpp
fc::log_level::log_level
log_level(values v=off)
Definition: log_message.hpp:41
fc::log_context::get_thread_name
std::string get_thread_name() const
Definition: log_message.cpp:158
fc::from_variant
void from_variant(const variant &var, flat_set< T, A... > &vo, uint32_t _max_depth)
Definition: flat.hpp:116
fc::log_context::get_context
std::string get_context() const
Definition: log_message.cpp:163
fc::log_context::get_line_number
uint64_t get_line_number() const
Definition: log_message.cpp:156
fc::log_message::~log_message
~log_message()
Definition: log_message.cpp:183
fc::log_context::get_file
std::string get_file() const
Definition: log_message.cpp:155
fc::log_context
provides information about where and when a log message was generated.
Definition: log_message.hpp:56
fc::log_context::get_host_name
std::string get_host_name() const
Definition: log_message.cpp:160
fc::to_variant
void to_variant(const flat_set< T, A... > &var, variant &vo, uint32_t _max_depth)
Definition: flat.hpp:105
fc::log_context::get_timestamp
time_point get_timestamp() const
Definition: log_message.cpp:161
fc::log_context::get_task_name
std::string get_task_name() const
Definition: log_message.cpp:159
fc::log_message
aggregates a message along with the context and associated meta-information.
Definition: log_message.hpp:106
fc::log_level::log_level
log_level(int v)
Definition: log_message.hpp:42
fc::variant
stores null, int64, uint64, double, bool, string, std::vector<variant>, and variant_object's.
Definition: variant.hpp:198
fc::time_point
Definition: time.hpp:44
fc::log_messages
std::vector< log_message > log_messages
Definition: log_message.hpp:134
fc::log_context::get_method
std::string get_method() const
Definition: log_message.cpp:157
fc::log_level::info
@ info
Definition: log_message.hpp:36
fc::log_level
Definition: log_message.hpp:23
fc::log_level::values
values
Define's the various log levels for reporting.
Definition: log_message.hpp:32
time.hpp
fc::log_context::~log_context
~log_context()
Definition: log_message.cpp:91
fc::log_message::get_context
log_context get_context() const
Definition: log_message.cpp:209
fc::log_level::value
values value
Definition: log_message.hpp:44
fc::log_context::to_string
std::string to_string() const
Definition: log_message.cpp:78
fc::log_message::get_message
std::string get_message() const
Definition: log_message.cpp:213