diff --git a/CHANGELOG.md b/CHANGELOG.md index 7c03c86..feedbef 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 277455d..61b95c2 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -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) @@ -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) diff --git a/src/cimplog-onboarding.c b/src/cimplog-onboarding.c new file mode 100644 index 0000000..d9ac5a5 --- /dev/null +++ b/src/cimplog-onboarding.c @@ -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 +#include +#include +#include +#include +#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); + } + } +} diff --git a/src/cimplog.c b/src/cimplog.c index 23178ea..4880c20 100644 --- a/src/cimplog.c +++ b/src/cimplog.c @@ -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; +} diff --git a/src/cimplog.h b/src/cimplog.h index 6f9bc1a..0e98bc5 100644 --- a/src/cimplog.h +++ b/src/cimplog.h @@ -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 * @@ -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 diff --git a/src/main.c b/src/main.c new file mode 100644 index 0000000..14207fd --- /dev/null +++ b/src/main.c @@ -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 +#include +#include +#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; +} diff --git a/tests/onboardingTest.sh b/tests/onboardingTest.sh new file mode 100755 index 0000000..f567a74 --- /dev/null +++ b/tests/onboardingTest.sh @@ -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" diff --git a/tests/simple.c b/tests/simple.c index 4657794..34e5ac1 100644 --- a/tests/simple.c +++ b/tests/simple.c @@ -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 ); } /*----------------------------------------------------------------------------*/