libbgp  0.6
A C++ BGP Library.
bgp-log-handler.h
Go to the documentation of this file.
1 
11 #ifndef BGP_LOG_H_
12 #define BGP_LOG_H_
13 #include <mutex>
14 #include "serializable.h"
15 
16 // log helper macro. some log taks a lot of resources to produce (e.g., print
17 // BgpPacket). This allow us to disable logging completely with macro and also
18 // force log level check.
19 #ifndef DISBALE_LOG_MACROS
20 #define LIBBGP_LOG(logger, level) if (logger->getLogLevel() >= level)
21 #else
22 #define LIBBGP_LOG(logger, level)
23 #endif
24 
25 namespace libbgp {
26 
27 class Serializable;
28 
33 enum LogLevel {
34  FATAL,
35  ERROR,
36  WARN,
37  INFO,
38  DEBUG
39 };
40 
48 public:
49  BgpLogHandler();
50 
51  void log(LogLevel level, const char* format_str, ...);
52  void log(LogLevel level, const Serializable &serializable);
53  void setLogLevel(LogLevel level);
54  LogLevel getLogLevel() const;
55 
60  virtual ~BgpLogHandler() {}
61 protected:
62 
69  virtual void logImpl(const char* str);
70 
71 private:
72  LogLevel level;
73  std::mutex buf_mtx;
74  char out_buffer[4096];
75 };
76 
94 }
95 
96 #endif // BGP_LOG_H_
LogLevel
Log levels for logger (BgpLogHandler)
virtual ~BgpLogHandler()
Destroy the Bgp Log Handler object.
The serializable base class.
Definition: serializable.h:26
void log(LogLevel level, const char *format_str,...)
Log a message. Consider using LIBBGP_LOG if logging the message needs a lot of computing power...
Definition: bgp-afi.h:14
The BgpLogHandler class.
virtual void logImpl(const char *str)
Log implementation. By default, it writes to stderr. You may implement your own BgpLogHandler to writ...
The serializable base.
void setLogLevel(LogLevel level)
Set the log level.
LogLevel getLogLevel() const
Get the log level.