Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- Fixes for building in MacOS
- Reverted generic API to log messages into an additional module other than the primary module of a component
- Added support for overriding debug.ini file location in RDK code
- Added support of onboard logging

## [1.0.0] - 2017-10-11
### Added
Expand Down
11 changes: 10 additions & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ set(PROJ_CIMPL cimplog)

file(GLOB HEADERS cimplog.h cimplog.h)
if (RDK_LOGGER)
set(SOURCES cimplog-rdk-logger.c)
set(SOURCES cimplog-rdk-logger.c cimplog-onboarding.c)
else (RDK_LOGGER)
set(SOURCES cimplog.c)
endif (RDK_LOGGER)
Expand All @@ -43,3 +43,12 @@ install (TARGETS ${PROJ_CIMPL}
install (TARGETS ${PROJ_CIMPL} DESTINATION lib${LIB_SUFFIX})
install (TARGETS ${PROJ_CIMPL}.shared DESTINATION lib${LIB_SUFFIX})
install (FILES cimplog.h DESTINATION include/${PROJ_CIMPL})

if (RDK_LOGGER)
#-------------------------------------------------------------------------------
# onboarding_log cli
#-------------------------------------------------------------------------------
set(BIN_SOURCES cimplog-onboarding.c main.c)
add_executable(onboarding_log ${BIN_SOURCES} ${HEADERS})
install (TARGETS onboarding_log DESTINATION bin)
endif (RDK_LOGGER)
93 changes: 93 additions & 0 deletions src/cimplog-onboarding.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
/**
* Copyright 2016 Comcast Cable Communications Management, LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
#include <stdio.h>
#include <sys/sysinfo.h>
#include <time.h>
#include <string.h>
#include <unistd.h>
#include "cimplog.h"
#define MAX_BUF_SIZE 1024

#ifdef XB3_ARM
#define ONBOARDING_FILE "/rdklogs/logs/OnBoardingLog_Arm.txt.0"
#elif XB3_ATOM
#define ONBOARDING_FILE "/rdklogs/logs/OnBoardingLog_Atom.txt.0"
#else
#define ONBOARDING_FILE "/rdklogs/logs/OnBoardingLog.txt.0"
#endif

#define DEVICE_ONBOARDED "/nvram/.device_onboarded"

void __cimplog_generic(const char *module, const char *msg, ...)
{
va_list arg_ptr;
char buf[MAX_BUF_SIZE];
int nbytes;
struct sysinfo l_sSysInfo;
struct tm * l_sTimeInfo;
char l_cLocalTime[32] = {0};
time_t l_sNowTime;
FILE *l_fOnBoardingLogFile = NULL;

if (access(DEVICE_ONBOARDED, F_OK) != -1)
{
return;
}

sysinfo(&l_sSysInfo);
time(&l_sNowTime);
l_sTimeInfo = localtime(&l_sNowTime);

strftime(l_cLocalTime,32, "%y%m%d-%X",l_sTimeInfo);
va_start(arg_ptr, msg);
nbytes = vsnprintf(buf, MAX_BUF_SIZE, msg, arg_ptr);
va_end(arg_ptr);

if( nbytes >= MAX_BUF_SIZE )
{
buf[ MAX_BUF_SIZE - 1 ] = '\0';
}
else
{
buf[nbytes] = '\0';
}

l_fOnBoardingLogFile = fopen(ONBOARDING_FILE, "a+");
if (NULL != l_fOnBoardingLogFile)
{
if(module != NULL)
{
fprintf(l_fOnBoardingLogFile, "%s [%s] %s", l_cLocalTime, module, buf);
}
else
{
fprintf(l_fOnBoardingLogFile, "%s %s", l_cLocalTime, buf);
}
fclose(l_fOnBoardingLogFile);
}
else //fopen of on boarding file failed atleast write on the console
{
if(module != NULL)
{
printf("%s [%s] %s", l_cLocalTime, module, buf);
}
else
{
printf("%s %s", l_cLocalTime, buf);
}
}
}
5 changes: 5 additions & 0 deletions src/cimplog.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,8 @@ void __cimplog(const char *module, int level, const char *msg, ...)
}
}

void __cimplog_generic(const char *module, const char *msg, ...)
{
(void) module;
(void) msg;
}
9 changes: 9 additions & 0 deletions src/cimplog.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
#define cimplog_info(module, ...) __cimplog(module, LEVEL_INFO, __VA_ARGS__)
#define cimplog_debug(module, ...) __cimplog(module, LEVEL_DEBUG, __VA_ARGS__)

#define onboarding_log(module, ...) __cimplog_generic(module, __VA_ARGS__)

/**
* @brief handle log message based on log level
*
Expand All @@ -36,4 +38,11 @@
*/
void __cimplog(const char *module, int level, const char *msg, ...);

/**
* @brief log message into an additional module other than the primary module of a component
*
* @param module string identifying library/module
* @param msg message
*/
void __cimplog_generic(const char *module, const char *msg, ...);
#endif
39 changes: 39 additions & 0 deletions src/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/**
* Copyright 2016 Comcast Cable Communications Management, LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#include <stdio.h>
#include <string.h>
#include <stdarg.h>
#include "cimplog.h"

#define MAX_BUF_SIZE 1024

int main( int argc, char **argv)
{
char msg[MAX_BUF_SIZE];
if(argc > 2 && (NULL != argv[1]) && (NULL != argv[2]))
{
sprintf(msg, "%s\n", argv[2]);
onboarding_log(argv[1], msg);
}
else if(argc > 1 && (NULL != argv[1]))
{
sprintf(msg, "%s\n", argv[1]);
onboarding_log(NULL, msg);
}

return 0;
}
6 changes: 6 additions & 0 deletions tests/onboardingTest.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/sh
ONBOARDING_LOG=../build/src/onboarding_log
$ONBOARDING_LOG "TEST" "Simple onboarding log with module"
$ONBOARDING_LOG "Simple onboarding log without module"
ARGS="arguments"
$ONBOARDING_LOG "Simple onboarding log with $ARGS"
9 changes: 9 additions & 0 deletions tests/simple.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,19 @@ void test_cimplog()
cimplog_debug(mod3, "Sample debug\n");
}

void test_onBoarding()
{
char mod2[] = "Module2";
char *msg = "arguments";
onboarding_log("Module1", "Sample OnBoarding Log\n");
onboarding_log(mod2, "Sample OnBoarding Log with %s\n",msg);
onboarding_log(NULL, "Sample debug\n");
}
void add_suites( CU_pSuite *suite )
{
*suite = CU_add_suite( "cimplog tests", NULL, NULL );
CU_add_test( *suite, "Test cimplog logging\n", test_cimplog );
CU_add_test( *suite, "Test onboard logging\n", test_onBoarding );
}

/*----------------------------------------------------------------------------*/
Expand Down