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 
19 
20 // Use Google Logging Library (glog).
21 #if P1_HAVE_GLOG && !P1_NO_LOGGING
22 # include <glog/logging.h>
23 
24 // For internal use only.
25 #elif P1_HAVE_PORTABLE_LOGGING && !P1_NO_LOGGING
26 # include "point_one/common/portability/logging.h"
27 
28 // Disable logging support at compile time.
29 #else // Logging disabled
30 
31 # include <stdlib.h> // For abort().
32 
33 # if !P1_NO_LOGGING
34 # undef P1_NO_LOGGING
35 # define P1_NO_LOGGING 1
36 # endif // !P1_NO_LOGGING
37 
38 namespace point_one {
39 namespace fusion_engine {
40 namespace common {
41 
42 class NullStream : public p1_ostream {
43  public:
44 # if P1_HAVE_STD_OSTREAM
45  NullStream() : p1_ostream(nullptr) {}
46 # endif
47 };
48 
49 template <class T>
50 inline NullStream& operator<<(NullStream& stream, const T&) {
51  return stream;
52 }
53 
54 class NullMessage {
55  public:
58 
59  NullStream& stream() { return stream_; }
60 };
61 
62 } // namespace common
63 } // namespace fusion_engine
64 } // namespace point_one
65 
66 # define P1_NULL_STREAM point_one::fusion_engine::common::NullMessage::stream_
67 # define P1_NULL_MESSAGE \
68  point_one::fusion_engine::common::NullMessage::instance_
69 
70 # define COMPACT_GOOGLE_LOG_INFO P1_NULL_MESSAGE
71 # define COMPACT_GOOGLE_LOG_WARNING P1_NULL_MESSAGE
72 # define COMPACT_GOOGLE_LOG_ERROR P1_NULL_MESSAGE
73 # define COMPACT_GOOGLE_LOG_FATAL \
74  abort(); \
75  P1_NULL_MESSAGE
76 
77 # define LOG(severity) COMPACT_GOOGLE_LOG_##severity.stream()
78 # define LOG_IF(severity, condition) COMPACT_GOOGLE_LOG_##severity.stream()
79 # define LOG_EVERY_N(verboselevel, n) COMPACT_GOOGLE_LOG_##severity.stream()
80 # define LOG_IF_EVERY_N(verboselevel, condition, n) \
81  COMPACT_GOOGLE_LOG_##severity.stream()
82 
83 # define VLOG_IS_ON(verboselevel) false
84 # define COMPACT_GOOGLE_VLOG(verboselevel) P1_NULL_MESSAGE
85 
86 # define VLOG_IF(verboselevel, condition) \
87  COMPACT_GOOGLE_VLOG(verboselevel).stream()
88 # define VLOG(verboselevel) COMPACT_GOOGLE_VLOG(verboselevel).stream()
89 # define VLOG_EVERY_N(verboselevel, n) \
90  COMPACT_GOOGLE_VLOG(verboselevel).stream()
91 # define VLOG_IF_EVERY_N(verboselevel, condition, n) \
92  COMPACT_GOOGLE_VLOG(verboselevel).stream()
93 
94 #endif
Library portability helper definitions.
Definition: logging.h:54
static NullMessage instance_
Definition: logging.h:57
NullStream & operator<<(NullStream &stream, const T &)
Definition: logging.h:50
GNSS signal and frequency type definitions.
Definition: logging.h:38
NullStream & stream()
Definition: logging.h:59
std::ostream p1_ostream
Definition: portability.h:75
Definition: logging.h:42
static NullStream stream_
Definition: logging.h:56