logging.h
Go to the documentation of this file.
1 /**************************************************************************/ /**
2  * @brief API wrapper for optional compilation of logging support.
3  * @file
4  *
5  * To enable logging support, include
6  * [Google glog](https://github.com/google/glog) in your project, and define
7  * the following macro:
8  * ```cpp
9  * #define P1_HAVE_GLOG 1
10  * ```
11  *
12  * This is typically done during compilation by specifying the
13  * `-DP1_HAVE_GLOG=1` command-line argument to the compiler.
14  ******************************************************************************/
15 
16 #pragma once
17 
18 // Use Google Logging Library (glog).
19 #if P1_HAVE_GLOG && !P1_NO_LOGGING
20 # include <glog/logging.h>
21 
22 // For internal use only.
23 #elif P1_HAVE_PORTABLE_LOGGING && !P1_NO_LOGGING
24 # include "point_one/common/portability/logging.h"
25 
26 // Disable logging support at compile time.
27 #else // Logging disabled
28 
29 # include <ostream>
30 
31 # if !P1_NO_LOGGING
32 # undef P1_NO_LOGGING
33 # define P1_NO_LOGGING 1
34 # endif // !P1_NO_LOGGING
35 
36 namespace point_one {
37 namespace fusion_engine {
38 namespace common {
39 
40 class NullStream : public std::ostream {
41  public:
42  NullStream() : std::ostream(nullptr) {}
43 };
44 
45 template <class T>
46 inline NullStream& operator<<(NullStream& stream, const T&) {
47  return stream;
48 }
49 
50 class NullMessage {
51  public:
54 
55  NullStream& stream() { return stream_; }
56 };
57 
58 } // namespace common
59 } // namespace fusion_engine
60 } // namespace point_one
61 
62 # define P1_NULL_STREAM point_one::fusion_engine::common::NullMessage::stream_
63 # define P1_NULL_MESSAGE \
64  point_one::fusion_engine::common::NullMessage::instance_
65 
66 # define COMPACT_GOOGLE_LOG_INFO P1_NULL_MESSAGE
67 # define COMPACT_GOOGLE_LOG_WARNING P1_NULL_MESSAGE
68 # define COMPACT_GOOGLE_LOG_ERROR P1_NULL_MESSAGE
69 # define COMPACT_GOOGLE_LOG_FATAL P1_NULL_MESSAGE
70 
71 # define LOG(severity) COMPACT_GOOGLE_LOG_##severity.stream()
72 # define LOG_IF(severity, condition) COMPACT_GOOGLE_LOG_##severity.stream()
73 # define LOG_EVERY_N(verboselevel, n) COMPACT_GOOGLE_LOG_##severity.stream()
74 # define LOG_IF_EVERY_N(verboselevel, condition, n) \
75  COMPACT_GOOGLE_LOG_##severity.stream()
76 
77 # define VLOG_IS_ON(verboselevel) false
78 # define COMPACT_GOOGLE_VLOG(verboselevel) P1_NULL_MESSAGE
79 
80 # define VLOG_IF(verboselevel, condition) \
81  COMPACT_GOOGLE_VLOG(verboselevel).stream()
82 # define VLOG(verboselevel) COMPACT_GOOGLE_VLOG(verboselevel).stream()
83 # define VLOG_EVERY_N(verboselevel, n) \
84  COMPACT_GOOGLE_VLOG(verboselevel).stream()
85 # define VLOG_IF_EVERY_N(verboselevel, condition, n) \
86  COMPACT_GOOGLE_VLOG(verboselevel).stream()
87 
88 #endif
Definition: logging.h:50
static NullMessage instance_
Definition: logging.h:53
NullStream & operator<<(NullStream &stream, const T &)
Definition: logging.h:46
NullStream()
Definition: logging.h:42
Definition: logging.h:36
NullStream & stream()
Definition: logging.h:55
Definition: logging.h:40
static NullStream stream_
Definition: logging.h:52