1 /* 2 * Copyright (c) 2016, 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 the platform abstraction for the debug log service. 33 */ 34 35 #ifndef OPENTHREAD_PLATFORM_LOGGING_H_ 36 #define OPENTHREAD_PLATFORM_LOGGING_H_ 37 38 #include <stdarg.h> 39 #include <stdint.h> 40 41 #ifdef __cplusplus 42 extern "C" { 43 #endif 44 45 /** 46 * @addtogroup plat-logging 47 * 48 * @brief 49 * This module includes the platform abstraction for the debug log service. 50 * 51 * @{ 52 * 53 */ 54 55 /** 56 * Log level None. 57 * 58 * @note Log Levels are defines so that embedded implementations can eliminate code at compile time via 59 * #if/#else/#endif. 60 * 61 */ 62 #define OT_LOG_LEVEL_NONE 0 63 64 /** 65 * Log level Critical. 66 * 67 * @note Log Levels are defines so that embedded implementations can eliminate code at compile time via 68 * #if/#else/#endif. 69 * 70 */ 71 #define OT_LOG_LEVEL_CRIT 1 72 73 /** 74 * Log level Warning. 75 * 76 * @note Log Levels are defines so that embedded implementations can eliminate code at compile time via 77 * #if/#else/#endif. 78 * 79 */ 80 #define OT_LOG_LEVEL_WARN 2 81 82 /** 83 * Log level Notice. 84 * 85 * @note Log Levels are defines so that embedded implementations can eliminate code at compile time via 86 * #if/#else/#endif. 87 * 88 */ 89 #define OT_LOG_LEVEL_NOTE 3 90 91 /** 92 * Log level Informational. 93 * 94 * @note Log Levels are defines so that embedded implementations can eliminate code at compile time via 95 * #if/#else/#endif. 96 * 97 */ 98 #define OT_LOG_LEVEL_INFO 4 99 100 /** 101 * Log level Debug. 102 * 103 * @note Log Levels are defines so that embedded implementations can eliminate code at compile time via 104 * #if/#else/#endif. 105 * 106 */ 107 #define OT_LOG_LEVEL_DEBG 5 108 109 /** 110 * This type represents the log level. 111 * 112 */ 113 typedef int otLogLevel; 114 115 /** 116 * This enumeration represents log regions. 117 * 118 */ 119 typedef enum otLogRegion 120 { 121 OT_LOG_REGION_API = 1, ///< OpenThread API 122 OT_LOG_REGION_MLE = 2, ///< MLE 123 OT_LOG_REGION_ARP = 3, ///< EID-to-RLOC mapping. 124 OT_LOG_REGION_NET_DATA = 4, ///< Network Data 125 OT_LOG_REGION_ICMP = 5, ///< ICMPv6 126 OT_LOG_REGION_IP6 = 6, ///< IPv6 127 OT_LOG_REGION_TCP = 7, ///< TCP 128 OT_LOG_REGION_MAC = 8, ///< IEEE 802.15.4 MAC 129 OT_LOG_REGION_MEM = 9, ///< Memory 130 OT_LOG_REGION_NCP = 10, ///< NCP 131 OT_LOG_REGION_MESH_COP = 11, ///< Mesh Commissioning Protocol 132 OT_LOG_REGION_NET_DIAG = 12, ///< Network Diagnostic 133 OT_LOG_REGION_PLATFORM = 13, ///< Platform 134 OT_LOG_REGION_COAP = 14, ///< CoAP 135 OT_LOG_REGION_CLI = 15, ///< CLI 136 OT_LOG_REGION_CORE = 16, ///< OpenThread Core 137 OT_LOG_REGION_UTIL = 17, ///< Utility module 138 OT_LOG_REGION_BBR = 18, ///< Backbone Router (available since Thread 1.2) 139 OT_LOG_REGION_MLR = 19, ///< Multicast Listener Registration (available since Thread 1.2) 140 OT_LOG_REGION_DUA = 20, ///< Domain Unicast Address (available since Thread 1.2) 141 OT_LOG_REGION_BR = 21, ///< Border Router 142 OT_LOG_REGION_SRP = 22, ///< Service Registration Protocol (SRP) 143 OT_LOG_REGION_DNS = 23, ///< DNS 144 } otLogRegion; 145 146 /** 147 * This function outputs logs. 148 * 149 * @param[in] aLogLevel The log level. 150 * @param[in] aLogRegion The log region. 151 * @param[in] aFormat A pointer to the format string. 152 * @param[in] ... Arguments for the format specification. 153 * 154 */ 155 void otPlatLog(otLogLevel aLogLevel, otLogRegion aLogRegion, const char *aFormat, ...); 156 157 /** 158 * This (optional) platform function outputs a prepared log line. 159 * 160 * This platform function is used by OpenThread core when `OPENTHREAD_CONFIG_LOG_DEFINE_AS_MACRO_ONLY` is not enabled 161 * (in this case, the OT core itself will prepare a full log line). 162 * 163 * Note that this function is optional and if not provided by platform layer, a default (weak) implementation is 164 * provided and used by OpenThread core as `otPlatLog(aLogLevel, aLogResion, "%s", aLogLine)`. 165 * 166 * @param[in] aLogLevel The log level. 167 * @param[in] aLogRegion The log region. 168 * @param[in] aLogLine A pointer to a log line string. 169 * 170 */ 171 void otPlatLogLine(otLogLevel aLogLevel, otLogRegion aLogRegion, const char *aLogLine); 172 173 /** 174 * @} 175 * 176 */ 177 178 #ifdef __cplusplus 179 } // extern "C" 180 #endif 181 182 #endif // OPENTHREAD_PLATFORM_LOGGING_H_ 183