Loading src/lib/kinetic_logger.c +14 −10 Original line number Diff line number Diff line Loading @@ -24,29 +24,33 @@ #include <string.h> static char LogFile[256] = ""; bool LogToStdErr = true; bool LogToStdOut = true; void KineticLogger_Init(const char* logFile) { if (logFile == NULL) { LogToStdErr = true; } else LogToStdOut = true; if (logFile != NULL) { FILE* fd; strcpy(LogFile, logFile); fd = fopen(LogFile, "w"); if (fd > 0) { fclose(fd); LogToStdErr = false; LogToStdOut = false; } else { KineticLogger_LogPrintf("Failed to initialize logger with file: fopen('%s') => fd=%d", logFile, fd); } } } void KineticLogger_Log(const char* message) { if (LogToStdErr) if (LogToStdOut) { fprintf(stderr, "%s\n", message); fprintf(stdout, "%s\n", message); } else if (LogFile != NULL) { Loading test/integration/test_kinetic_logger.c +9 −0 Original line number Diff line number Diff line Loading @@ -21,6 +21,8 @@ #include "unity_helper.h" #include "kinetic_logger.h" extern bool LogToStdOut; void setUp(void) { DELETE_FILE(TEST_LOG_FILE); Loading @@ -36,10 +38,17 @@ void test_KineticLogger_KINETIC_LOG_FILE_should_be_defined_properly(void) TEST_ASSERT_EQUAL_STRING("kinetic.log", KINETIC_LOG_FILE); } void test_KineticLogger_Init_should_log_to_STDOUT_by_default(void) { KineticLogger_Init(NULL); TEST_ASSERT_TRUE(LogToStdOut); } void test_KineticLogger_Init_should_initialize_the_logger_with_specified_output_file(void) { KineticLogger_Init(TEST_LOG_FILE); TEST_ASSERT_FALSE(LogToStdOut); TEST_ASSERT_FILE_EXISTS(TEST_LOG_FILE); } Loading Loading
src/lib/kinetic_logger.c +14 −10 Original line number Diff line number Diff line Loading @@ -24,29 +24,33 @@ #include <string.h> static char LogFile[256] = ""; bool LogToStdErr = true; bool LogToStdOut = true; void KineticLogger_Init(const char* logFile) { if (logFile == NULL) { LogToStdErr = true; } else LogToStdOut = true; if (logFile != NULL) { FILE* fd; strcpy(LogFile, logFile); fd = fopen(LogFile, "w"); if (fd > 0) { fclose(fd); LogToStdErr = false; LogToStdOut = false; } else { KineticLogger_LogPrintf("Failed to initialize logger with file: fopen('%s') => fd=%d", logFile, fd); } } } void KineticLogger_Log(const char* message) { if (LogToStdErr) if (LogToStdOut) { fprintf(stderr, "%s\n", message); fprintf(stdout, "%s\n", message); } else if (LogFile != NULL) { Loading
test/integration/test_kinetic_logger.c +9 −0 Original line number Diff line number Diff line Loading @@ -21,6 +21,8 @@ #include "unity_helper.h" #include "kinetic_logger.h" extern bool LogToStdOut; void setUp(void) { DELETE_FILE(TEST_LOG_FILE); Loading @@ -36,10 +38,17 @@ void test_KineticLogger_KINETIC_LOG_FILE_should_be_defined_properly(void) TEST_ASSERT_EQUAL_STRING("kinetic.log", KINETIC_LOG_FILE); } void test_KineticLogger_Init_should_log_to_STDOUT_by_default(void) { KineticLogger_Init(NULL); TEST_ASSERT_TRUE(LogToStdOut); } void test_KineticLogger_Init_should_initialize_the_logger_with_specified_output_file(void) { KineticLogger_Init(TEST_LOG_FILE); TEST_ASSERT_FALSE(LogToStdOut); TEST_ASSERT_FILE_EXISTS(TEST_LOG_FILE); } Loading