1 /* 2 * Copyright (c) 2016-2018, 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 29 /** 30 * @file 31 * @brief 32 * This file includes OpenThread logging related definitions. 33 */ 34 35 #ifndef OPENTHREAD_LOGGING_H_ 36 #define OPENTHREAD_LOGGING_H_ 37 38 #include <openthread/error.h> 39 #include <openthread/platform/logging.h> 40 41 #ifdef __cplusplus 42 extern "C" { 43 #endif 44 45 /** 46 * @addtogroup api-logging 47 * 48 * @brief 49 * This module includes OpenThread logging related definitions. 50 * 51 * @{ 52 * 53 */ 54 55 /** 56 * Returns the current log level. 57 * 58 * If dynamic log level feature `OPENTHREAD_CONFIG_LOG_LEVEL_DYNAMIC_ENABLE` is enabled, this function returns the 59 * currently set dynamic log level. Otherwise, this function returns the build-time configured log level. 60 * 61 * @returns The log level. 62 * 63 */ 64 otLogLevel otLoggingGetLevel(void); 65 66 /** 67 * Sets the log level. 68 * 69 * @note This function requires `OPENTHREAD_CONFIG_LOG_LEVEL_DYNAMIC_ENABLE=1`. 70 * 71 * @param[in] aLogLevel The log level. 72 * 73 * @retval OT_ERROR_NONE Successfully updated log level. 74 * @retval OT_ERROR_INVALID_ARGS Log level value is invalid. 75 * 76 */ 77 otError otLoggingSetLevel(otLogLevel aLogLevel); 78 79 /** 80 * Emits a log message at critical log level. 81 * 82 * Is intended for use by platform. If `OPENTHREAD_CONFIG_LOG_PLATFORM` is not set or the current log 83 * level is below critical, this function does not emit any log message. 84 * 85 * @param[in] aFormat The format string. 86 * @param[in] ... Arguments for the format specification. 87 * 88 */ 89 void otLogCritPlat(const char *aFormat, ...) OT_TOOL_PRINTF_STYLE_FORMAT_ARG_CHECK(1, 2); 90 91 /** 92 * Emits a log message at warning log level. 93 * 94 * Is intended for use by platform. If `OPENTHREAD_CONFIG_LOG_PLATFORM` is not set or the current log 95 * level is below warning, this function does not emit any log message. 96 * 97 * @param[in] aFormat The format string. 98 * @param[in] ... Arguments for the format specification. 99 * 100 */ 101 void otLogWarnPlat(const char *aFormat, ...) OT_TOOL_PRINTF_STYLE_FORMAT_ARG_CHECK(1, 2); 102 103 /** 104 * Emits a log message at note log level. 105 * 106 * Is intended for use by platform. If `OPENTHREAD_CONFIG_LOG_PLATFORM` is not set or the current log 107 * level is below note, this function does not emit any log message. 108 * 109 * @param[in] aFormat The format string. 110 * @param[in] ... Arguments for the format specification. 111 * 112 */ 113 void otLogNotePlat(const char *aFormat, ...) OT_TOOL_PRINTF_STYLE_FORMAT_ARG_CHECK(1, 2); 114 115 /** 116 * Emits a log message at info log level. 117 * 118 * Is intended for use by platform. If `OPENTHREAD_CONFIG_LOG_PLATFORM` is not set or the current log 119 * level is below info, this function does not emit any log message. 120 * 121 * @param[in] aFormat The format string. 122 * @param[in] ... Arguments for the format specification. 123 * 124 */ 125 void otLogInfoPlat(const char *aFormat, ...) OT_TOOL_PRINTF_STYLE_FORMAT_ARG_CHECK(1, 2); 126 127 /** 128 * Emits a log message at debug log level. 129 * 130 * Is intended for use by platform. If `OPENTHREAD_CONFIG_LOG_PLATFORM` is not set or the current log 131 * level is below debug, this function does not emit any log message. 132 * 133 * @param[in] aFormat The format string. 134 * @param[in] ... Arguments for the format specification. 135 * 136 */ 137 void otLogDebgPlat(const char *aFormat, ...) OT_TOOL_PRINTF_STYLE_FORMAT_ARG_CHECK(1, 2); 138 139 /** 140 * Generates a memory dump at critical log level. 141 * 142 * If `OPENTHREAD_CONFIG_LOG_PLATFORM` or `OPENTHREAD_CONFIG_LOG_PKT_DUMP` is not set or the current log level is below 143 * critical this function does not emit any log message. 144 * 145 * @param[in] aText A string that is printed before the bytes. 146 * @param[in] aData A pointer to the data buffer. 147 * @param[in] aDataLength Number of bytes in @p aData. 148 * 149 */ 150 void otDumpCritPlat(const char *aText, const void *aData, uint16_t aDataLength); 151 152 /** 153 * Generates a memory dump at warning log level. 154 * 155 * If `OPENTHREAD_CONFIG_LOG_PLATFORM` or `OPENTHREAD_CONFIG_LOG_PKT_DUMP` is not set or the current log level is below 156 * warning this function does not emit any log message. 157 * 158 * @param[in] aText A string that is printed before the bytes. 159 * @param[in] aData A pointer to the data buffer. 160 * @param[in] aDataLength Number of bytes in @p aData. 161 * 162 */ 163 void otDumpWarnPlat(const char *aText, const void *aData, uint16_t aDataLength); 164 165 /** 166 * Generates a memory dump at note log level. 167 * 168 * If `OPENTHREAD_CONFIG_LOG_PLATFORM` or `OPENTHREAD_CONFIG_LOG_PKT_DUMP` is not set or the current log level is below 169 * note this function does not emit any log message. 170 * 171 * @param[in] aText A string that is printed before the bytes. 172 * @param[in] aData A pointer to the data buffer. 173 * @param[in] aDataLength Number of bytes in @p aData. 174 * 175 */ 176 void otDumpNotePlat(const char *aText, const void *aData, uint16_t aDataLength); 177 178 /** 179 * Generates a memory dump at info log level. 180 * 181 * If `OPENTHREAD_CONFIG_LOG_PLATFORM` or `OPENTHREAD_CONFIG_LOG_PKT_DUMP` is not set or the current log level is below 182 * info this function does not emit any log message. 183 * 184 * @param[in] aText A string that is printed before the bytes. 185 * @param[in] aData A pointer to the data buffer. 186 * @param[in] aDataLength Number of bytes in @p aData. 187 * 188 */ 189 void otDumpInfoPlat(const char *aText, const void *aData, uint16_t aDataLength); 190 191 /** 192 * Generates a memory dump at debug log level. 193 * 194 * If `OPENTHREAD_CONFIG_LOG_PLATFORM` or `OPENTHREAD_CONFIG_LOG_PKT_DUMP` is not set or the current log level is below 195 * debug this function does not emit any log message. 196 * 197 * @param[in] aText A string that is printed before the bytes. 198 * @param[in] aData A pointer to the data buffer. 199 * @param[in] aDataLength Number of bytes in @p aData. 200 * 201 */ 202 void otDumpDebgPlat(const char *aText, const void *aData, uint16_t aDataLength); 203 204 /** 205 * Emits a log message at a given log level. 206 * 207 * Is intended for use by CLI only. If `OPENTHREAD_CONFIG_LOG_CLI` is not set or the current log 208 * level is below the given log level, this function does not emit any log message. 209 * 210 * @param[in] aLogLevel The log level. 211 * @param[in] aFormat The format string. 212 * @param[in] ... Arguments for the format specification. 213 * 214 */ 215 void otLogCli(otLogLevel aLogLevel, const char *aFormat, ...) OT_TOOL_PRINTF_STYLE_FORMAT_ARG_CHECK(2, 3); 216 217 /** 218 * @} 219 * 220 */ 221 222 #ifdef __cplusplus 223 } // extern "C" 224 #endif 225 226 #endif // OPENTHREAD_LOGGING_H_ 227