openthread-br  0.3.0-72c0388
logging.hpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2017, The OpenThread Authors.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  * 1. Redistributions of source code must retain the above copyright
8  * notice, this list of conditions and the following disclaimer.
9  * 2. Redistributions in binary form must reproduce the above copyright
10  * notice, this list of conditions and the following disclaimer in the
11  * documentation and/or other materials provided with the distribution.
12  * 3. Neither the name of the copyright holder nor the
13  * names of its contributors may be used to endorse or promote products
14  * derived from this software without specific prior written permission.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
20  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26  * POSSIBILITY OF SUCH DAMAGE.
27  */
28 
33 #ifndef OTBR_COMMON_LOGGING_HPP_
34 #define OTBR_COMMON_LOGGING_HPP_
35 
36 #include "openthread-br/config.h"
37 
38 #include <stdarg.h>
39 #include <stddef.h>
40 
41 #ifndef OTBR_LOG_TAG
42 #error "OTBR_LOG_TAG is not defined"
43 #endif
44 
45 #include "common/types.hpp"
46 
51 typedef enum
52 {
61 } otbrLogLevel;
62 
67 
71 void otbrLogSetLevel(otbrLogLevel aLevel);
72 
79 void otbrLogEnableSyslog(bool aEnabled);
80 
89 void otbrLogInit(const char *aIdent, otbrLogLevel aLevel, bool aPrintStderr);
90 
99 void otbrLog(otbrLogLevel aLevel, const char *aLogTag, const char *aFormat, ...);
100 
109 void otbrLogv(otbrLogLevel aLevel, const char *aFormat, va_list aArgList);
110 
119 void otbrLogvNoFilter(otbrLogLevel aLevel, const char *aFormat, va_list aArgList);
120 
131 void otbrDump(otbrLogLevel aLevel, const char *aLogTag, const char *aPrefix, const void *aMemory, size_t aSize);
132 
141 const char *otbrErrorString(otbrError aError);
142 
147 void otbrLogDeinit(void);
148 
160 #define otbrLogResult(aError, aFormat, ...) \
161  do \
162  { \
163  otbrError _err = (aError); \
164  otbrLog(_err == OTBR_ERROR_NONE ? OTBR_LOG_INFO : OTBR_LOG_WARNING, OTBR_LOG_TAG, aFormat ": %s", \
165  ##__VA_ARGS__, otbrErrorString(_err)); \
166  } while (0)
167 
239 #define otbrLogEmerg(...) otbrLog(OTBR_LOG_EMERG, OTBR_LOG_TAG, __VA_ARGS__)
240 #define otbrLogAlert(...) otbrLog(OTBR_LOG_ALERT, OTBR_LOG_TAG, __VA_ARGS__)
241 #define otbrLogCrit(...) otbrLog(OTBR_LOG_CRIT, OTBR_LOG_TAG, __VA_ARGS__)
242 #define otbrLogErr(...) otbrLog(OTBR_LOG_ERR, OTBR_LOG_TAG, __VA_ARGS__)
243 #define otbrLogWarning(...) otbrLog(OTBR_LOG_WARNING, OTBR_LOG_TAG, __VA_ARGS__)
244 #define otbrLogNotice(...) otbrLog(OTBR_LOG_NOTICE, OTBR_LOG_TAG, __VA_ARGS__)
245 #define otbrLogInfo(...) otbrLog(OTBR_LOG_INFO, OTBR_LOG_TAG, __VA_ARGS__)
246 #define otbrLogDebug(...) otbrLog(OTBR_LOG_DEBUG, OTBR_LOG_TAG, __VA_ARGS__)
247 
248 #endif // OTBR_COMMON_LOGGING_HPP_
OTBR_LOG_CRIT
@ OTBR_LOG_CRIT
Critical conditions.
Definition: logging.hpp:55
otbrLogInit
void otbrLogInit(const char *aIdent, otbrLogLevel aLevel, bool aPrintStderr)
Definition: logging.cpp:73
OTBR_LOG_INFO
@ OTBR_LOG_INFO
Informational.
Definition: logging.hpp:59
otbrLogvNoFilter
void otbrLogvNoFilter(otbrLogLevel aLevel, const char *aFormat, va_list aArgList)
Definition: logging.cpp:137
otbrLogDeinit
void otbrLogDeinit(void)
Definition: logging.cpp:254
otbrLogGetLevel
otbrLogLevel otbrLogGetLevel(void)
Definition: logging.cpp:58
otbrLogSetLevel
void otbrLogSetLevel(otbrLogLevel aLevel)
Definition: logging.cpp:66
otbrDump
void otbrDump(otbrLogLevel aLevel, const char *aLogTag, const char *aPrefix, const void *aMemory, size_t aSize)
Definition: logging.cpp:143
otbrLogEnableSyslog
void otbrLogEnableSyslog(bool aEnabled)
otbrLogv
void otbrLogv(otbrLogLevel aLevel, const char *aFormat, va_list aArgList)
Definition: logging.cpp:127
otbrLogLevel
otbrLogLevel
Definition: logging.hpp:51
OTBR_LOG_NOTICE
@ OTBR_LOG_NOTICE
Normal but significant condition.
Definition: logging.hpp:58
OTBR_LOG_WARNING
@ OTBR_LOG_WARNING
Warning conditions.
Definition: logging.hpp:57
otbrError
otbrError
Definition: types.hpp:70
otbrErrorString
const char * otbrErrorString(otbrError aError)
Definition: logging.cpp:193
OTBR_LOG_ERR
@ OTBR_LOG_ERR
Error conditions.
Definition: logging.hpp:56
config.h
otbrLog
void otbrLog(otbrLogLevel aLevel, const char *aLogTag, const char *aFormat,...)
Definition: logging.cpp:108
OTBR_LOG_EMERG
@ OTBR_LOG_EMERG
System is unusable.
Definition: logging.hpp:53
OTBR_LOG_DEBUG
@ OTBR_LOG_DEBUG
Debug level messages.
Definition: logging.hpp:60
OTBR_LOG_ALERT
@ OTBR_LOG_ALERT
Action must be taken immediately.
Definition: logging.hpp:54