RDK Documentation (Open Sourced RDK Components)
rdk_logger_init.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_logger_init.c
22  * This source file contains the APIs for RDK logger initializer.
23  */
24 
25 /**
26 * @defgroup rdk_logger
27 * @{
28 * @defgroup src
29 * @{
30 **/
31 
32 
33 #include <sys/socket.h>
34 #include <signal.h>
35 #include <sys/types.h>
36 #include <sys/stat.h>
37 #include <unistd.h>
38 #include "rdk_debug.h"
39 #include "rdk_error.h"
40 #include "rdk_debug_priv.h"
41 #include "rdk_dynamic_logger.h"
42 #include "rdk_utils.h"
43 
44 #define BUF_LEN 256
45 static int isLogInited = 0;
46 /**
47  * @brief Initialize the logger. Sets up the environment variable storage by parsing
48  * debug configuration file then Initialize the debug support to the underlying platform.
49  *
50  * @note Requests not to send SIGPIPE on errors on stream oriented sockets
51  * when the other end breaks the connection. The EPIPE error is still returned.
52  *
53  * @param[in] debugConfigFile The character pointer variable of debug configuration file.
54  *
55  * @return Returns 0 if initialization of RDK logger module is successful, else it returns -1.
56  */
57 rdk_Error rdk_logger_init(const char* debugConfigFile)
58 {
59  rdk_Error ret;
60  struct stat st;
61  char buf[BUF_LEN] = {'\0'};
62 
63  if (0 == isLogInited)
64  {
65  if (NULL == debugConfigFile)
66  {
67  debugConfigFile = DEBUG_CONF_FILE;
68  }
69 
70  ret = rdk_logger_env_add_conf_file(debugConfigFile);
71  if ( RDK_SUCCESS != ret)
72  {
73  printf("%s:%d Adding debug config file %s failed\n", __FUNCTION__, __LINE__, DEBUG_CONF_FILE);
74  return ret;
75  }
76 
77  rdk_dbgInit();
78  rdk_dyn_log_init();
79 
80  snprintf(buf, BUF_LEN-1, "/tmp/%s", "debugConfigFile_read");
81  buf[BUF_LEN-1] = '\0';
82 
83  if((0 == stat(buf, &st) && (0 != st.st_ino)))
84  {
85  printf("%s %s Already Stack Level Logging processed... not processing again.\n", __FUNCTION__, debugConfigFile);
86  }
87  else
88  {
89  rdk_dbgDumpLog(buf);
90  }
91 
92  /**
93  * Requests not to send SIGPIPE on errors on stream oriented
94  * sockets when the other end breaks the connection. The EPIPE
95  * error is still returned.
96  */
97  signal(SIGPIPE, SIG_IGN);
98  isLogInited = 1;
99  }
100  return RDK_SUCCESS;
101 }
102 
103 /**
104  * @brief Cleanup the logger instantiation.
105  *
106  * @return Returns 0 if the call is successful else return -1.
107  */
108 rdk_Error rdk_logger_deinit()
109 {
110  if(isLogInited)
111  {
112  rdk_dyn_log_deInit();
113  log4c_fini();
114  }
115 
116  return RDK_SUCCESS;
117 }
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_utils.h
rdk_logger_env_add_conf_file
rdk_Error rdk_logger_env_add_conf_file(const char *path)
This Function sets up the environment variable cache by parsing configuration file and adding each na...
Definition: rdk_logger_util.c:97
rdk_logger_deinit
rdk_Error rdk_logger_deinit()
Cleanup the logger instantiation.
Definition: rdk_logger_init.c:108
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_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