RDK Documentation (Open Sourced RDK Components)
rdk_debug.h
Go to the documentation of this file.
1 /*
2  * If not stated otherwise in this file or this component's Licenses.txt file the
3  * following copyright and licenses apply:
4  *
5  * Copyright 2016 RDK Management
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18 */
19 
20 /**
21  * @file rdk_debug.h
22  * The header file provides RDK debug APIs.
23  */
24 
25 /**
26  * @defgroup RDKLOGGER RDK Logger
27  * RDK Logger provides common logging capability for all RDK components.
28  * It is a common logging library which is based on MPEOS logging & uses log4c for
29  * formatting and supports multiple log levels.
30  *
31  * @par RDK Logger Capabilities
32  *
33  * - Abstracts logging client from underlying logging utility.
34  * - Dynamically enables/disables logging level at run time.
35  * - Provides logging format that complies with the existing OCAP format (e.g. <timestamp> [mod=*, level=*]).
36  * - Controls log level independently for each component/module.
37  * - Enables logging globally via single configuration value.
38  * - Controls initial log level for each component/module from configuration file (debug.ini) at startup.
39  * - The debug.ini is the main configuration file for RDK Logger and it is intended to be used
40  * globally in multi-process environment.
41  * - Prints formatted data to stdout.
42  * - Separates logs into separate files based on "SEPARATE.LOGFILE.SUPPORT" configuration variable.
43  * - RDK logger log files will be generated under "/opt/logs" folder if SEPARATE.LOGFILE.SUPPORT=TRUE
44  *
45  * @par How to add the RDK logger functionality to the new module?
46  * @n Include rdk_debug.h header file and make use of RDK_LOG for printing logs. Initialize RDK Logger by
47  * calling rdk_logger_init() in the respective module/component. Build new module/component by linking
48  * "librdkloggers.so" along with "liblog4c.so" and "libglib-2.0.so" shared object.
49  * @code
50  * Example: -lrdkloggers -L ../opensource/lib -llog4c -lglib-2.0
51  * @endcode
52  *
53  * @par RDK Logger Usage
54  * @code
55  * RDK_LOG (rdk_LogLevel level, const char *module, const char *format,...)
56  * @endcode
57  * - "level" is Log level of the log message (FATAL, ERROR etc). Apart from this there are
58  * special log levels like ALL, NONE, TRACE, !TRACE are supported.
59  * - "module" is the Module to which this message belongs to (Use module name same as mentioned in debug.ini)
60  * - "format" is a printf style string containing the log message.
61  * @n All the RDK components logs are stored under /opt/log/ with a naming convention <RDK component>_log.txt.
62  * @n For example, /opt/log/pod_log.txt includes all events logged by POD Manager module.
63  *
64  * @par Sample code for Logging:
65  * For example, add a debug messages for "INBSI" module
66  * @code
67  * RDK_LOG (RDK_LOG_NOTICE, "LOG.RDK.INBSI","<%s: %s>: Sending PMT_ACQUIRED event\n", PSIMODULE, __FUNCTION__);
68  * @endcode
69  * User needs to provide the module name "LOG.RDK.INBSI", which is the same as mentioned in debug.ini
70  * @code
71  * $ cat debug.ini
72  * EnableMPELog = TRUE
73  * LOG.RDK.INBSI = ALL FATAL ERROR WARNING NOTICE INFO DEBUG
74  * @endcode
75  *
76  * @par Sample logging output:
77  * @code
78  * 131011-21:21:49.578394 [mod=INBSI, lvl=NOTICE] [tid=4141] <SITP_PSI: NotifyTableChanged>: Sending PMT_ACQUIRED event
79  * @endcode
80  * In this way, user make use of the RDK logger in the respective modules and control the logging levels through configuration file.
81  * Here, No need to build RDK logger again for the addition of new components/module.
82  * @ingroup RDKLOGGER
83  *
84  * @par How GStreamer logging
85  * - A callback function gst_debug_add_log_function() is registered to receive gstreamer logs.
86  * - Logs are converted to RDK logs in callback function.
87  * - RMF element which controls a gst-element shall register element name and corresponding log module using
88  * void RMF_registerGstElementDbgModule(char *gst_module, char *rmf_module)
89  * - Callback function uses this information to get module names corresponding to gstreamer logs.
90  *
91  * @par RDK Logging architecture
92  *
93  * @image html rdk_logger_architecture.jpg
94  *
95  * @par RDK Logging Configuration
96  * @n Default level of logging is ERROR. Logging settings are configured in debug.ini
97  * @code
98  * - LOG.RDK.<component1> = FATAL ERROR WARNING NOTICE INFO
99  * - LOG.RDK.<component2> = FATAL ERROR WARNING NOTICE INFO DEBUG
100  * @endcode
101  *
102  * @par Logging Levels supported by RDK Logger.
103  * Code | Description
104  * -----|------------
105  * RDK_LOG_FATAL | Any error that is forcing a shutdown of the service or application to prevent data loss (or further data loss), reserve these only for the most heinous errors and situations where there is guaranteed to have been data corruption or loss.
106  * RDK_LOG_ERROR | Any error which is fatal to the operation but not the service (cant open a file, missing data, etc)
107  * RDK_LOG_WARN | Anything that can potentially cause application oddities, but for which the application automatically recoverring.
108  * RDK_LOG_NOTICE | Anything that largely superfluous for application-level logging.
109  * RDK_LOG_INFO | Generally useful information to log (service start/stop, configuration assumptions, etc).
110  * RDK_LOG_DEBUG | Information that is diagnostically helpful to people more than just developers.
111  * RDK_LOG_TRACE1, RDK_LOG_TRACE2,... | Only when it would be "tracing" the code and trying to find one part of a function specifically.
112  *
113  * @par How log files are upload to server
114  * @image html rdk_logupload.jpg
115  *
116  * @defgroup RDKLOGGER_DEBUG_API RDK Logger APIs
117  * Describe the details about RDK debug APIs specifications.
118  * @ingroup RDKLOGGER
119  *
120  * @defgroup RDKLOGGER_UTILS_API RDK Logger Utils APIs
121  * Describe the details about RDK Logger utils API specifications.
122  * @ingroup RDKLOGGER
123  */
124 
125 /**
126 * @defgroup rdk_logger
127 * @{
128 * @defgroup include
129 * @{
130 **/
131 
132 
133 #ifndef _RDK_DEBUG_H_
134 #define _RDK_DEBUG_H_
135 
136 #include <stdio.h>
137 #include "rdk_logger_types.h"
138 #include "rdk_error.h"
139 #ifdef __cplusplus
140 extern "C"
141 {
142 #endif
143 
144 /**
145  * Support for overriding debug.ini file location
146  */
147 #define DEBUG_INI_OVERRIDE_PATH "/nvram/debug.ini"
148 #define RDK_LOGGER_INIT() (0 == access(DEBUG_INI_OVERRIDE_PATH, F_OK)) \
149  ? rdk_logger_init(DEBUG_INI_OVERRIDE_PATH) \
150  : rdk_logger_init(DEBUG_INI_NAME);
151 
152 /**
153  * @enum rdk_LogLevel
154  * @brief These values represent the logging 'levels' or 'types', they are each
155  * independent.
156  */
157 typedef enum
158 {
159  ENUM_RDK_LOG_BEGIN = 0, /**< Used as array index. */
160 
161  RDK_LOG_FATAL = ENUM_RDK_LOG_BEGIN,
162  RDK_LOG_ERROR,
163  RDK_LOG_WARN,
164  RDK_LOG_NOTICE,
165  RDK_LOG_INFO,
166  RDK_LOG_DEBUG,
167 
168  RDK_LOG_TRACE1,
169  RDK_LOG_TRACE2,
170  RDK_LOG_TRACE3,
171  RDK_LOG_TRACE4,
172  RDK_LOG_TRACE5,
173  RDK_LOG_TRACE6,
174  RDK_LOG_TRACE7,
175  RDK_LOG_TRACE8,
176  RDK_LOG_TRACE9,
177 
178  ENUM_RDK_LOG_COUNT
179 } rdk_LogLevel;
180 
181 /**
182  * String names that correspond to the various logging types.
183  * Note: This array *must* match the RDK_LOG_* enum.
184  */
185 #ifdef RDK_DEBUG_DEFINE_STRINGS
186 const char *rdk_logLevelStrings[ENUM_RDK_LOG_COUNT] =
187 {
188  "FATAL",
189  "ERROR",
190  "WARNING",
191  "NOTICE",
192  "INFO",
193  "DEBUG",
194 
195  "TRACE1",
196  "TRACE2",
197  "TRACE3",
198  "TRACE4",
199  "TRACE5",
200  "TRACE6",
201  "TRACE7",
202  "TRACE8",
203  "TRACE9",
204 };
205 #else
206 extern const char *rdk_logLevelStrings[ENUM_RDK_LOG_COUNT];
207 #endif /* RDK_DEBUG_DEFINE_STRINGS */
208 
209 void RDK_LOG_ControlCB(const char *moduleName, const char *subComponentName, const char *loggingLevel, int log_status);
210 
211 /**
212  * @ingroup RDKLOGGER_DEBUG_API
213  * @{
214  */
215 
216 void rdk_dbgDumpLog(const char* path);
217 
218 void rdk_dbgInit();
219 
220 rdk_Error rdk_logger_init(const char* debugConfigFile);
221 
222 rdk_Error rdk_logger_deinit();
223 
224 void rdk_dbg_MsgRaw(rdk_LogLevel level, const char *module, const char *format, ...) __attribute__ ((format (printf, 3, 4)));
225 
226 void rdk_dbg_MsgRaw1(rdk_LogLevel level, const char *module,const char *format, va_list args);
227 
228 rdk_logger_Bool rdk_dbg_enabled(const char *module, rdk_LogLevel level);
229 
230 void rdk_log_onboard(const char *module, const char *msg, ...) __attribute__ ((format (printf, 2, 3)));
231 
232 /** @} */ //end of Doxygen tag RDKLOGGER_DEBUG_API
233 
234 /**
235  * Use RDK_LOG debug message as.
236  * RDK_LOG (rdk_LogLevel level, const char *module, const char *format,...)
237  * @param level Log level of the log message
238  * @param module Module in which this message belongs to (Use module name same as mentioned in debug.ini)
239  * @param format Printf style string containing the log message.
240  */
241 /**
242  * @details Default log level entries for each modules are present in the debug.ini
243  * These entries are read at startup and can be modifiy/add as per the requirement.
244  * @details Bydefault logs are redirected to /opt/logs/ocapri_log.txt.
245  * But these can be configure to capture logs for each component in separate files under
246  * /opt/logs/ by setting configuration parameter SEPARATE.LOGFILE.SUPPORT as TRUE in
247  * debug.ini
248  * @details Following logs files generated if SEPARATE.LOGFILE.SUPPORT=TRUE
249  *
250  * For POD: pod_log.txt
251  *
252  * For CANH Daemon: canh_log.txt
253  *
254  * For RMFStreamer: rmfstr_log.txt
255  *
256  */
257 
258 #define RDK_LOG rdk_dbg_MsgRaw
259 #define RDK_LOG1 rdk_dbg_MsgRaw1
260 
261 #ifdef __cplusplus
262 }
263 #endif
264 
265 #endif /* _RDK_DEBUG_H_ */
rdk_dbgInit
void rdk_dbgInit()
Initialize the underlying MPEOS debug support. This API must be called only once per boot cycle.
Definition: rdk_debug.c:100
rdk_dbg_enabled
rdk_logger_Bool rdk_dbg_enabled(const char *module, rdk_LogLevel level)
Function to check if a specific log level of a module is enabled.
Definition: rdk_debug_priv.c:415
rdk_dbg_MsgRaw
void rdk_dbg_MsgRaw(rdk_LogLevel level, const char *module, const char *format,...) __attribute__((format(printf
Dump the debug log. It will Dump all the current settings so that an analysis of a log file will incl...
rdk_logLevelStrings
const char * rdk_logLevelStrings[ENUM_RDK_LOG_COUNT]
ENUM_RDK_LOG_BEGIN
@ ENUM_RDK_LOG_BEGIN
Definition: rdk_debug.h:159
rdk_logger_deinit
rdk_Error rdk_logger_deinit()
Cleanup the logger instantiation.
Definition: rdk_logger_init.c:108
rdk_LogLevel
rdk_LogLevel
These values represent the logging 'levels' or 'types', they are each independent.
Definition: rdk_debug.h:157
rdk_dbgDumpLog
void rdk_dbgDumpLog(const char *path)
Dump the debug log. It will Dump all the current settings so that an analysis of a log file will incl...
Definition: rdk_debug.c:67
rdk_log_onboard
void rdk_log_onboard(const char *module, const char *msg,...) __attribute__((format(printf
Dump the debug log. It will Dump all the current settings so that an analysis of a log file will incl...
rdk_logger_init
rdk_Error rdk_logger_init(const char *debugConfigFile)
Initialize the logger. Sets up the environment variable storage by parsing debug configuration file t...
Definition: rdk_logger_init.c:57
rdk_dbg_MsgRaw1
void void rdk_dbg_MsgRaw1(rdk_LogLevel level, const char *module, const char *format, va_list args)
Dump the debug log. It will Dump all the current settings so that an analysis of a log file will incl...
Definition: rdk_debug.c:139