Apollo
6.0
Open source self driving car software
cyber
common
log.h
Go to the documentation of this file.
1
/******************************************************************************
2
* Copyright 2018 The Apollo Authors. All Rights Reserved.
3
*
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
* you may not use this file except in compliance with the License.
6
* You may obtain a copy of the License at
7
*
8
* http://www.apache.org/licenses/LICENSE-2.0
9
*
10
* Unless required by applicable law or agreed to in writing, software
11
* distributed under the License is distributed on an "AS IS" BASIS,
12
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
* See the License for the specific language governing permissions and
14
* limitations under the License.
15
*****************************************************************************/
16
21
#ifndef CYBER_COMMON_LOG_H_
22
#define CYBER_COMMON_LOG_H_
23
24
#include <cstdarg>
25
#include <string>
26
27
#include "glog/logging.h"
28
#include "glog/raw_logging.h"
29
30
#include "
cyber/binary.h
"
31
32
#define LEFT_BRACKET "["
33
#define RIGHT_BRACKET "]"
34
35
#ifndef MODULE_NAME
36
#define MODULE_NAME apollo::cyber::binary::GetName().c_str()
37
#endif
38
39
#define ADEBUG_MODULE(module) \
40
VLOG(4) << LEFT_BRACKET << module << RIGHT_BRACKET << "[DEBUG] "
41
#define ADEBUG ADEBUG_MODULE(MODULE_NAME)
42
#define AINFO ALOG_MODULE(MODULE_NAME, INFO)
43
#define AWARN ALOG_MODULE(MODULE_NAME, WARN)
44
#define AERROR ALOG_MODULE(MODULE_NAME, ERROR)
45
#define AFATAL ALOG_MODULE(MODULE_NAME, FATAL)
46
47
#ifndef ALOG_MODULE_STREAM
48
#define ALOG_MODULE_STREAM(log_severity) ALOG_MODULE_STREAM_##log_severity
49
#endif
50
51
#ifndef ALOG_MODULE
52
#define ALOG_MODULE(module, log_severity) \
53
ALOG_MODULE_STREAM(log_severity)(module)
54
#endif
55
56
#define ALOG_MODULE_STREAM_INFO(module) \
57
google::LogMessage(__FILE__, __LINE__, google::INFO).stream() \
58
<< LEFT_BRACKET << module << RIGHT_BRACKET
59
60
#define ALOG_MODULE_STREAM_WARN(module) \
61
google::LogMessage(__FILE__, __LINE__, google::WARNING).stream() \
62
<< LEFT_BRACKET << module << RIGHT_BRACKET
63
64
#define ALOG_MODULE_STREAM_ERROR(module) \
65
google::LogMessage(__FILE__, __LINE__, google::ERROR).stream() \
66
<< LEFT_BRACKET << module << RIGHT_BRACKET
67
68
#define ALOG_MODULE_STREAM_FATAL(module) \
69
google::LogMessage(__FILE__, __LINE__, google::FATAL).stream() \
70
<< LEFT_BRACKET << module << RIGHT_BRACKET
71
72
#define AINFO_IF(cond) ALOG_IF(INFO, cond, MODULE_NAME)
73
#define AWARN_IF(cond) ALOG_IF(WARN, cond, MODULE_NAME)
74
#define AERROR_IF(cond) ALOG_IF(ERROR, cond, MODULE_NAME)
75
#define AFATAL_IF(cond) ALOG_IF(FATAL, cond, MODULE_NAME)
76
#define ALOG_IF(severity, cond, module) \
77
!(cond) ? (void)0 \
78
: google::LogMessageVoidify() & ALOG_MODULE(module, severity)
79
80
#define ACHECK(cond) CHECK(cond) << LEFT_BRACKET << MODULE_NAME << RIGHT_BRACKET
81
82
#define AINFO_EVERY(freq) \
83
LOG_EVERY_N(INFO, freq) << LEFT_BRACKET << MODULE_NAME << RIGHT_BRACKET
84
#define AWARN_EVERY(freq) \
85
LOG_EVERY_N(WARNING, freq) << LEFT_BRACKET << MODULE_NAME << RIGHT_BRACKET
86
#define AERROR_EVERY(freq) \
87
LOG_EVERY_N(ERROR, freq) << LEFT_BRACKET << MODULE_NAME << RIGHT_BRACKET
88
89
#if !defined(RETURN_IF_NULL)
90
#define RETURN_IF_NULL(ptr) \
91
if (ptr == nullptr) { \
92
AWARN << #ptr << " is nullptr."; \
93
return; \
94
}
95
#endif
96
97
#if !defined(RETURN_VAL_IF_NULL)
98
#define RETURN_VAL_IF_NULL(ptr, val) \
99
if (ptr == nullptr) { \
100
AWARN << #ptr << " is nullptr."; \
101
return val; \
102
}
103
#endif
104
105
#if !defined(RETURN_IF)
106
#define RETURN_IF(condition) \
107
if (condition) { \
108
AWARN << #condition << " is met."; \
109
return; \
110
}
111
#endif
112
113
#if !defined(RETURN_VAL_IF)
114
#define RETURN_VAL_IF(condition, val) \
115
if (condition) { \
116
AWARN << #condition << " is met."; \
117
return val; \
118
}
119
#endif
120
121
#if !defined(_RETURN_VAL_IF_NULL2__)
122
#define _RETURN_VAL_IF_NULL2__
123
#define RETURN_VAL_IF_NULL2(ptr, val) \
124
if (ptr == nullptr) { \
125
return (val); \
126
}
127
#endif
128
129
#if !defined(_RETURN_VAL_IF2__)
130
#define _RETURN_VAL_IF2__
131
#define RETURN_VAL_IF2(condition, val) \
132
if (condition) { \
133
return (val); \
134
}
135
#endif
136
137
#if !defined(_RETURN_IF2__)
138
#define _RETURN_IF2__
139
#define RETURN_IF2(condition) \
140
if (condition) { \
141
return; \
142
}
143
#endif
144
145
#endif // CYBER_COMMON_LOG_H_
binary.h
Generated by
1.8.13