OpenSDN source code
logging.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2013 Juniper Networks, Inc. All rights reserved.
3  * Copyright Contributors to the OpenSDN project
4  */
5 
6 #ifndef __LOGGING_H__
7 #define __LOGGING_H__
8 
9 #ifdef __clang__
10 #pragma clang diagnostic push
11 #pragma clang diagnostic ignored "-Wunused-variable"
12 #endif
13 
14 #include <log4cplus/logger.h>
15 #include <log4cplus/loggingmacros.h>
16 #include <log4cplus/initializer.h>
17 
18 #ifdef __clang__
19 #pragma clang diagnostic pop
20 #endif
21 
22 #ifdef __clang__
23 #pragma clang diagnostic push
24 #pragma clang diagnostic ignored "-Wmismatched-tags"
25 #endif
26 
27 #include <boost/units/detail/utility.hpp>
28 
29 #ifdef __clang__
30 #pragma clang diagnostic pop
31 #endif
32 
33 #define TYPE_NAME(_type) boost::units::detail::demangle(typeid(_type).name())
34 
35 #define LOG(_Level, _Msg) \
36  do { \
37  if (LoggingDisabled()) break; \
38  log4cplus::Logger logger = log4cplus::Logger::getRoot(); \
39  LOG4CPLUS_##_Level(logger, _Msg); \
40  } while (0)
41 
44 class Logging {
45 
48  log4cplus::Initializer initializer_;
49 
50 public:
51 
54  Logging();
55 
58  ~Logging();
59 
62  void Init();
63 
67  void Init(const std::string &filename,
68  long maxFileSize,
69  int maxBackupIndex,
70  bool useSyslog,
71  const std::string &syslogFacility,
72  const std::string &ident,
73  log4cplus::LogLevel logLevel);
74 
77  void Init(const std::string &propertyFile);
78 };
79 
80 void LoggingInit();
81 void LoggingInit(const std::string &filename,
82  long maxFileSize,
83  int maxBackupIndex,
84  bool useSyslog,
85  const std::string &syslogFacility,
86  const std::string &ident,
87  log4cplus::LogLevel logLevel);
88 
89 void LoggingInit(const std::string &propertyFile);
90 void SetLoggingLevel(log4cplus::LogLevel logLevel);
91 bool LoggingUseSyslog();
92 
93 //
94 // Disable logging - For testing purposes only
95 //
96 bool LoggingDisabled();
97 void SetLoggingDisabled(bool flag);
98 void SetUseSysLog(bool); // To be used only for testing
99 #endif /* __LOGGING_H__ */
A class providing basic control over logging capabilities in OpenSDN control plane.
Definition: logging.h:44
void Init()
Performs basic initialization of the logging system ( log4cplus).
Definition: logging.cc:32
log4cplus::Initializer initializer_
A log4cplus object to maintain multi- and singlethreaded execution of the logging library.
Definition: logging.h:48
Logging()
Prepares log4cplus library for execution. Uses RAII to free resources after the completion of the pro...
Definition: logging.cc:25
~Logging()
Destroys the object and shutdowns the logging system.
Definition: logging.cc:29
bool LoggingDisabled()
Definition: logging.cc:56
void SetLoggingLevel(log4cplus::LogLevel logLevel)
void SetUseSysLog(bool)
Definition: logging.cc:68
void LoggingInit()
Definition: logging.cc:83
bool LoggingUseSyslog()
Definition: logging.cc:64
void SetLoggingDisabled(bool flag)
Definition: logging.cc:60