RDK Documentation (Open Sourced RDK Components)
rdk_logger_onboard.c
1 /*
2 * If not stated otherwise in this file or this component's LICENSE 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 #ifdef FEATURE_SUPPORT_ONBOARD_LOGGING
20 #include <stdio.h>
21 #include <time.h>
22 #include <string.h>
23 #include <unistd.h>
24 #include <stdarg.h>
25 #define MAX_BUF_SIZE 1024
26 
27 #ifndef ONBOARDING_FILE
28 #define ONBOARDING_FILE /rdklogs/logs/OnBoardingLog.txt.0
29 #endif
30 
31 #define STRINGIFY_VALUE(x) #x
32 #define STRINGIFY_MACRO(x) STRINGIFY_VALUE(x)
33 #define ONBOARDING_LOG_FILE STRINGIFY_MACRO(ONBOARDING_FILE)
34 
35 #define DEVICE_ONBOARDED "/nvram/.device_onboarded"
36 #define DISABLE_ONBOARDING "/nvram/DISABLE_ONBOARD_LOGGING"
37 
38 void rdk_log_onboard(const char *module, const char *msg, ...)
39 {
40  va_list arg_ptr;
41  char buf[MAX_BUF_SIZE];
42  int nbytes;
43  struct tm * l_sTimeInfo;
44  char l_cLocalTime[32] = {0};
45  time_t l_sNowTime;
46  FILE *l_fOnBoardingLogFile = NULL;
47 
48  if (access(DEVICE_ONBOARDED, F_OK) != -1 || access(DISABLE_ONBOARDING, F_OK) != -1)
49  {
50  return;
51  }
52 
53  time(&l_sNowTime);
54  l_sTimeInfo = localtime(&l_sNowTime);
55 
56  strftime(l_cLocalTime,32, "%y%m%d-%X",l_sTimeInfo);
57  va_start(arg_ptr, msg);
58  nbytes = vsnprintf(buf, MAX_BUF_SIZE, msg, arg_ptr);
59  va_end(arg_ptr);
60 
61  if( nbytes >= MAX_BUF_SIZE )
62  {
63  buf[ MAX_BUF_SIZE - 1 ] = '\0';
64  }
65  else
66  {
67  buf[nbytes] = '\0';
68  }
69 
70  l_fOnBoardingLogFile = fopen(ONBOARDING_LOG_FILE, "a+");
71  if (NULL != l_fOnBoardingLogFile)
72  {
73  if(module != NULL)
74  {
75  fprintf(l_fOnBoardingLogFile, "%s [%s] %s", l_cLocalTime, module, buf);
76  }
77  else
78  {
79  fprintf(l_fOnBoardingLogFile, "%s %s", l_cLocalTime, buf);
80  }
81  fclose(l_fOnBoardingLogFile);
82  }
83  else //fopen of on boarding file failed atleast write on the console
84  {
85  if(module != NULL)
86  {
87  printf("%s [%s] %s", l_cLocalTime, module, buf);
88  }
89  else
90  {
91  printf("%s %s", l_cLocalTime, buf);
92  }
93  }
94 }
95 #endif
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...