• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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  * Log level None.
56  *
57  * @note Log Levels are defines so that embedded implementations can eliminate code at compile time via
58  * #if/#else/#endif.
59  */
60 #define OT_LOG_LEVEL_NONE 0
61 
62 /**
63  * Log level Critical.
64  *
65  * @note Log Levels are defines so that embedded implementations can eliminate code at compile time via
66  * #if/#else/#endif.
67  */
68 #define OT_LOG_LEVEL_CRIT 1
69 
70 /**
71  * Log level Warning.
72  *
73  * @note Log Levels are defines so that embedded implementations can eliminate code at compile time via
74  * #if/#else/#endif.
75  */
76 #define OT_LOG_LEVEL_WARN 2
77 
78 /**
79  * Log level Notice.
80  *
81  * @note Log Levels are defines so that embedded implementations can eliminate code at compile time via
82  * #if/#else/#endif.
83  */
84 #define OT_LOG_LEVEL_NOTE 3
85 
86 /**
87  * Log level Informational.
88  *
89  * @note Log Levels are defines so that embedded implementations can eliminate code at compile time via
90  * #if/#else/#endif.
91  */
92 #define OT_LOG_LEVEL_INFO 4
93 
94 /**
95  * Log level Debug.
96  *
97  * @note Log Levels are defines so that embedded implementations can eliminate code at compile time via
98  * #if/#else/#endif.
99  */
100 #define OT_LOG_LEVEL_DEBG 5
101 
102 /**
103  * Represents the log level.
104  */
105 typedef int otLogLevel;
106 
107 /**
108  * Represents log regions.
109  *
110  * The support for log region is removed and instead each core module can define its own name to appended to the logs.
111  * However, the `otLogRegion` enumeration is still defined as before to help with platforms which we may be using it
112  * in their `otPlatLog()` implementation. The OT core will always emit all logs with `OT_LOG_REGION_CORE`.
113  */
114 typedef enum otLogRegion
115 {
116     OT_LOG_REGION_API      = 1,  ///< OpenThread API
117     OT_LOG_REGION_MLE      = 2,  ///< MLE
118     OT_LOG_REGION_ARP      = 3,  ///< EID-to-RLOC mapping.
119     OT_LOG_REGION_NET_DATA = 4,  ///< Network Data
120     OT_LOG_REGION_ICMP     = 5,  ///< ICMPv6
121     OT_LOG_REGION_IP6      = 6,  ///< IPv6
122     OT_LOG_REGION_TCP      = 7,  ///< TCP
123     OT_LOG_REGION_MAC      = 8,  ///< IEEE 802.15.4 MAC
124     OT_LOG_REGION_MEM      = 9,  ///< Memory
125     OT_LOG_REGION_NCP      = 10, ///< NCP
126     OT_LOG_REGION_MESH_COP = 11, ///< Mesh Commissioning Protocol
127     OT_LOG_REGION_NET_DIAG = 12, ///< Network Diagnostic
128     OT_LOG_REGION_PLATFORM = 13, ///< Platform
129     OT_LOG_REGION_COAP     = 14, ///< CoAP
130     OT_LOG_REGION_CLI      = 15, ///< CLI
131     OT_LOG_REGION_CORE     = 16, ///< OpenThread Core
132     OT_LOG_REGION_UTIL     = 17, ///< Utility module
133     OT_LOG_REGION_BBR      = 18, ///< Backbone Router (available since Thread 1.2)
134     OT_LOG_REGION_MLR      = 19, ///< Multicast Listener Registration (available since Thread 1.2)
135     OT_LOG_REGION_DUA      = 20, ///< Domain Unicast Address (available since Thread 1.2)
136     OT_LOG_REGION_BR       = 21, ///< Border Router
137     OT_LOG_REGION_SRP      = 22, ///< Service Registration Protocol (SRP)
138     OT_LOG_REGION_DNS      = 23, ///< DNS
139 } otLogRegion;
140 
141 /**
142  * Outputs logs.
143  *
144  * Note that the support for log region is removed. The OT core will always emit all logs with `OT_LOG_REGION_CORE`
145  * as @p aLogRegion.
146  *
147  * @param[in]  aLogLevel   The log level.
148  * @param[in]  aLogRegion  The log region.
149  * @param[in]  aFormat     A pointer to the format string.
150  * @param[in]  ...         Arguments for the format specification.
151  */
152 void otPlatLog(otLogLevel aLogLevel, otLogRegion aLogRegion, const char *aFormat, ...);
153 
154 /**
155  * Handles OpenThread log level changes.
156  *
157  * This platform function is called whenever the OpenThread log level changes.
158  * This platform function is optional since an empty weak implementation has been provided.
159  *
160  * @note Only applicable when `OPENTHREAD_CONFIG_LOG_LEVEL_DYNAMIC_ENABLE=1`.
161  *
162  * @param[in]  aLogLevel  The new OpenThread log level.
163  */
164 void otPlatLogHandleLevelChanged(otLogLevel aLogLevel);
165 
166 /**
167  * @}
168  */
169 
170 #ifdef __cplusplus
171 } // extern "C"
172 #endif
173 
174 #endif // OPENTHREAD_PLATFORM_LOGGING_H_
175