RDK Documentation (Open Sourced RDK Components)
rdk_debug.c
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.c
22  * This source file contains the APIs for RDK debug.
23  */
24 
25 /**
26 * @defgroup rdk_logger
27 * @{
28 * @defgroup src
29 * @{
30 **/
31 
32 
33 #include <rdk_debug.h>
34 #include <rdk_debug_priv.h>
35 
36 #include <string.h> // memset
37 #include <rdk_utils.h>
38 #include <stdarg.h>
39 
40 extern int global_count;
41 
42 /**
43  * @brief Touch the file which can be used to check whether to log or not.
44  *
45  * @param[in] pszFile Character string representing name of the file to be created.
46  * @return None.
47  */
48 static void TouchFile(const char * pszFile)
49 {
50  if(NULL != pszFile)
51  {
52  FILE * fp = fopen(pszFile, "w");
53  if(NULL != fp)
54  {
55  fclose(fp);
56  }
57  }
58 }
59 
60 /**
61  * @brief Dump the debug log. It will Dump all the current settings so that an analysis of a log
62  * file will include what logging information to expect.
63  *
64  * @param[in] path Character string representing path of the temp file to be created.
65  * @return None.
66  */
67 void rdk_dbgDumpLog(const char* path)
68 {
69  int mod, i;
70  char config[128];
71  const char *modptr = NULL;
72  RDK_LOG(RDK_LOG_INFO, "LOG.RDK.OS", "\n");
73  RDK_LOG(RDK_LOG_INFO, "LOG.RDK.OS",
74  "-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-\n");
75  RDK_LOG(RDK_LOG_INFO, "LOG.RDK.OS", "Stack level logging levels: \n");
76 
77  /**
78  * Now just dump all the current settings so that an analysis of a log
79  * file will include what logging information to expect
80  */
81  for (mod = 1; mod <= global_count; mod++)
82  {
83  modptr = rdk_logger_envGetModFromNum(mod);
84 
85  memset(config, 0, sizeof(config));
86  (void) rdk_dbg_priv_LogQueryOpSysIntf((char*) modptr, config, 127);
87  RDK_LOG(RDK_LOG_INFO, "LOG.RDK.OS",
88  "Initial Logging Level for %-10s: %s\n", modptr, config);
89  }
90 
91  RDK_LOG(RDK_LOG_INFO, "LOG.RDK.OS",
92  "-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-\n\n");
93  TouchFile(path);
94 }
95 
96 /**
97  * @brief Initialize the underlying MPEOS debug support. This API must be called only once per boot cycle.
98  * @return None.
99  */
101 {
102  static rdk_logger_Bool inited = FALSE;
103 
104  if (!inited)
105  {
106  rdk_dbg_priv_Init();
107  inited = TRUE;
108  }
109 }
110 
111 /**
112  * @brief Send a debugging message to the debugging window. It is appended to the log output based
113  * on configurations set in the environment file.
114  *
115  * @param[in] level The debug logging level.
116  * @param[in] module The name of the module for which this message belongs to, it is mentioned in debug.ini.
117  * @param[in] format Printf style string containing the log message.
118  */
119 void rdk_dbg_MsgRaw(rdk_LogLevel level, const char *module,
120  const char *format, ...)
121 {
122 #if !defined(RDK_LOG_DISABLE)
123  int num;
124  va_list args;
125 
126  va_start(args, format);
127  /** Get the registered value of module */
128  num = rdk_logger_envGetNum(module);
129  if(num < 0)
130  {
131  return;
132  }
133  rdk_debug_priv_log_msg( level, num, module,
134  format, args);
135  va_end(args);
136 #endif /* RDK_LOG_DISABLE */
137 }
138 
139 void rdk_dbg_MsgRaw1(rdk_LogLevel level, const char *module,
140  const char *format, va_list args)
141 {
142 #if !defined(RDK_LOG_DISABLE)
143  int num;
144 
145  /** Get the registered value of module */
146  num = rdk_logger_envGetNum(module);
147  if(num < 0)
148  {
149  return;
150  }
151  rdk_debug_priv_log_msg( level, num, module,
152  format, args);
153 #endif /* RDK_LOG_DISABLE */
154 }
155 
rdk_logger_envGetModFromNum
const char * rdk_logger_envGetModFromNum(int Num)
This function is used to get the name of the specified environment variable based on its registered n...
Definition: rdk_logger_util.c:285
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_debug.h
TouchFile
static void TouchFile(const char *pszFile)
Touch the file which can be used to check whether to log or not.
Definition: rdk_debug.c:48
rdk_utils.h
rdk_logger_envGetNum
int rdk_logger_envGetNum(const char *mod)
Function will give the registered number of the specified environment variable.
Definition: rdk_logger_util.c:257
RDK_LOG
#define RDK_LOG
Definition: rdk_debug.h:258
rdk_dbg_MsgRaw
void rdk_dbg_MsgRaw(rdk_LogLevel level, const char *module, const char *format,...)
Send a debugging message to the debugging window. It is appended to the log output based on configura...
Definition: rdk_debug.c:119
rdk_LogLevel
rdk_LogLevel
These values represent the logging 'levels' or 'types', they are each independent.
Definition: rdk_debug.h:157
global_count
int global_count
Definition: rdk_logger_util.c:55
rdk_dbg_priv_LogQueryOpSysIntf
const char * rdk_dbg_priv_LogQueryOpSysIntf(char *modName, char *cfgStr, int cfgStrMaxLen)
Definition: rdk_debug_priv.c:490
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_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
TRUE
#define TRUE
Defines for TRUE/FALSE/ENABLE flags.
Definition: wifi_common_hal.h:199