• 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 /**
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  * The support for log region is removed and instead each core module can define its own name to appended to the logs.
119  * However, the `otLogRegion` enumeration is still defined as before to help with platforms which we may be using it
120  * in their `otPlatLog()` implementation. The OT core will always emit all logs with `OT_LOG_REGION_CORE`.
121  *
122  */
123 typedef enum otLogRegion
124 {
125     OT_LOG_REGION_API      = 1,  ///< OpenThread API
126     OT_LOG_REGION_MLE      = 2,  ///< MLE
127     OT_LOG_REGION_ARP      = 3,  ///< EID-to-RLOC mapping.
128     OT_LOG_REGION_NET_DATA = 4,  ///< Network Data
129     OT_LOG_REGION_ICMP     = 5,  ///< ICMPv6
130     OT_LOG_REGION_IP6      = 6,  ///< IPv6
131     OT_LOG_REGION_TCP      = 7,  ///< TCP
132     OT_LOG_REGION_MAC      = 8,  ///< IEEE 802.15.4 MAC
133     OT_LOG_REGION_MEM      = 9,  ///< Memory
134     OT_LOG_REGION_NCP      = 10, ///< NCP
135     OT_LOG_REGION_MESH_COP = 11, ///< Mesh Commissioning Protocol
136     OT_LOG_REGION_NET_DIAG = 12, ///< Network Diagnostic
137     OT_LOG_REGION_PLATFORM = 13, ///< Platform
138     OT_LOG_REGION_COAP     = 14, ///< CoAP
139     OT_LOG_REGION_CLI      = 15, ///< CLI
140     OT_LOG_REGION_CORE     = 16, ///< OpenThread Core
141     OT_LOG_REGION_UTIL     = 17, ///< Utility module
142     OT_LOG_REGION_BBR      = 18, ///< Backbone Router (available since Thread 1.2)
143     OT_LOG_REGION_MLR      = 19, ///< Multicast Listener Registration (available since Thread 1.2)
144     OT_LOG_REGION_DUA      = 20, ///< Domain Unicast Address (available since Thread 1.2)
145     OT_LOG_REGION_BR       = 21, ///< Border Router
146     OT_LOG_REGION_SRP      = 22, ///< Service Registration Protocol (SRP)
147     OT_LOG_REGION_DNS      = 23, ///< DNS
148 } otLogRegion;
149 
150 /**
151  * This function outputs logs.
152  *
153  * Note that the support for log region is removed. The OT core will always emit all logs with `OT_LOG_REGION_CORE`
154  * as @p aLogRegion.
155  *
156  * @param[in]  aLogLevel   The log level.
157  * @param[in]  aLogRegion  The log region.
158  * @param[in]  aFormat     A pointer to the format string.
159  * @param[in]  ...         Arguments for the format specification.
160  *
161  */
162 void otPlatLog(otLogLevel aLogLevel, otLogRegion aLogRegion, const char *aFormat, ...);
163 
164 /**
165  * This function handles OpenThread log level changes.
166  *
167  * This platform function is called whenever the OpenThread log level changes.
168  * This platform function is optional since an empty weak implementation has been provided.
169  *
170  * @note Only applicable when `OPENTHREAD_CONFIG_LOG_LEVEL_DYNAMIC_ENABLE=1`.
171  *
172  * @param[in]  aLogLevel  The new OpenThread log level.
173  *
174  */
175 void otPlatLogHandleLevelChanged(otLogLevel aLogLevel);
176 
177 /**
178  * @}
179  *
180  */
181 
182 #ifdef __cplusplus
183 } // extern "C"
184 #endif
185 
186 #endif // OPENTHREAD_PLATFORM_LOGGING_H_
187