BitShares-Core  5.1.0
BitShares blockchain implementation and command-line interface 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,
39  off
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;
74  time_point get_timestamp()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 
An order-perserving dictionary of variant&#39;s.
values
Define&#39;s the various log levels for reporting.
Definition: log_message.hpp:32
FC_REFLECT_TYPENAME(fc::log_message)
void to_variant(const flat_set< T, A... > &var, variant &vo, uint32_t _max_depth)
Definition: flat.hpp:105
provides information about where and when a log message was generated.
Definition: log_message.hpp:56
std::vector< log_message > log_messages
stores null, int64, uint64, double, bool, string, std::vector<variant>, and variant_object&#39;s.
Definition: variant.hpp:198
void from_variant(const variant &var, flat_set< T, A... > &vo, uint32_t _max_depth)
Definition: flat.hpp:116
std::string to_string(double)
Definition: string.cpp:73
log_level(int v)
Definition: log_message.hpp:42
aggregates a message along with the context and associated meta-information.
defines wrappers for boost::asio functions
Definition: api.hpp:15
log_level(values v=off)
Definition: log_message.hpp:41