diff --git a/demo/os/windows/easylogger/inc/elog_cfg.h b/demo/os/windows/easylogger/inc/elog_cfg.h index 54301bd..de2b31a 100644 --- a/demo/os/windows/easylogger/inc/elog_cfg.h +++ b/demo/os/windows/easylogger/inc/elog_cfg.h @@ -31,6 +31,10 @@ /* enable log output. default open this macro */ #define ELOG_OUTPUT_ENABLE +/* enable log write file. default open this macro */ +#define ELOG_FILE_ENABLE +/* enable flush file cache. default open this macro */ +#define ELOG_FILE_FLUSH_CAHCE_ENABLE /* setting static output log level */ #define ELOG_OUTPUT_LVL ELOG_LVL_VERBOSE /* enable assert check */ diff --git a/demo/os/windows/easylogger/inc/elog_file_cfg.h b/demo/os/windows/easylogger/inc/elog_file_cfg.h new file mode 100644 index 0000000..e13d2ad --- /dev/null +++ b/demo/os/windows/easylogger/inc/elog_file_cfg.h @@ -0,0 +1,41 @@ +/* + * This file is part of the EasyLogger Library. + * + * Copyright (c) 2015-2019, Qintl, + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * 'Software'), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY + * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + * Function: It is the configure head file for this flash log plugin. + * Created on: 2019-01-05 + */ + +#ifndef _ELOG_FILE_CFG_H_ +#define _ELOG_FILE_CFG_H_ + +/* EasyLogger file log plugin's using file name */ +#define ELOG_FILE_NAME "logs/elog_file.log" + +/* EasyLogger file log plugin's using file max size */ +#define ELOG_FILE_MAX_SIZE (1 * 1024 * 1024) + +/* EasyLogger file log plugin's using max rotate file count */ +#define ELOG_FILE_MAX_ROTATE 10 + +#endif /* _ELOG_FILE_CFG_H_ */ diff --git a/demo/os/windows/easylogger/port/elog_file_port.c b/demo/os/windows/easylogger/port/elog_file_port.c new file mode 100644 index 0000000..2e44bc6 --- /dev/null +++ b/demo/os/windows/easylogger/port/elog_file_port.c @@ -0,0 +1,65 @@ +/* + * This file is part of the EasyLogger Library. + * + * Copyright (c) 2015-2019, Qintl, + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * 'Software'), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY + * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + * Function: Portable interface for EasyLogger's file log pulgin. + * Created on: 2019-01-05 + */ + +#include + +/** + * EasyLogger flile log pulgin port initialize + * + * @return result + */ +ElogErrCode elog_file_port_init(void) { + ElogErrCode result = ELOG_NO_ERR; + + /* do noting, using elog_port.c's locker only */ + + return result; +} + +/** + * file log lock + */ +void elog_file_port_lock(void) +{ + /* do noting, using elog_port.c's locker only */ +} + +/** + * file log unlock + */ +void elog_file_port_unlock(void) +{ + /* do noting, using elog_port.c's locker only */ +} +/** + * file log deinit + */ +void elog_file_port_deinit(void) +{ + /* do noting, using elog_port.c's locker only */ +} diff --git a/demo/os/windows/easylogger/port/elog_port.c b/demo/os/windows/easylogger/port/elog_port.c index 26969b5..de47b6e 100644 --- a/demo/os/windows/easylogger/port/elog_port.c +++ b/demo/os/windows/easylogger/port/elog_port.c @@ -31,6 +31,10 @@ #include #include +#ifdef ELOG_FILE_ENABLE +#include +#endif + static pthread_mutex_t output_lock; /** @@ -43,6 +47,10 @@ ElogErrCode elog_port_init(void) { pthread_mutex_init(&output_lock, NULL); +#ifdef ELOG_FILE_ENABLE + elog_file_init(); +#endif + return result; } @@ -55,6 +63,10 @@ ElogErrCode elog_port_init(void) { void elog_port_output(const char *log, size_t size) { /* output to terminal */ printf("%.*s", size, log); +#ifdef ELOG_FILE_ENABLE + /* write the file */ + elog_file_write(log, size); +#endif } /** diff --git a/demo/os/windows/main.c b/demo/os/windows/main.c index 3a860bf..80afb4b 100644 --- a/demo/os/windows/main.c +++ b/demo/os/windows/main.c @@ -80,6 +80,6 @@ void test_elog(void) { log_d("Hello EasyLogger!"); log_v("Hello EasyLogger!"); // elog_raw("Hello EasyLogger!"); - Sleep(5000); + Sleep(1000); } } diff --git a/demo/os/windows/make.bat b/demo/os/windows/make.bat index 4b0cabd..8662afa 100644 --- a/demo/os/windows/make.bat +++ b/demo/os/windows/make.bat @@ -1,5 +1,7 @@ gcc -I "easylogger\inc" -I "..\..\..\easylogger\inc" -O0 -g3 -Wall -c "..\..\..\easylogger\src\elog.c" -o "out\elog.o" -gcc -I "easylogger\inc" -I "..\..\..\easylogger\inc" -O0 -g3 -Wall -c "easylogger\port\elog_port.c" -o "out\elog_port.o" +gcc -I "easylogger\inc" -I "..\..\..\easylogger\inc" -I "..\..\..\easylogger\plugins\file" -O0 -g3 -Wall -c "easylogger\port\elog_port.c" -o "out\elog_port.o" gcc -I "easylogger\inc" -I "..\..\..\easylogger\inc" -O0 -g3 -Wall -c "..\..\..\easylogger\src\elog_utils.c" -o "out\elog_utils.o" +gcc -I "easylogger\inc" -I "..\..\..\easylogger\inc" -O0 -g3 -Wall -c "..\..\..\easylogger\plugins\file\elog_file.c" -o "out\elog_file.o" +gcc -I "easylogger\inc" -I "..\..\..\easylogger\inc" -I "..\..\..\easylogger\plugins\file" -O0 -g3 -Wall -c "..\..\..\easylogger\plugins\file\elog_file_port.c" -o "out\elog_file_port.o" gcc -I "easylogger\inc" -I "..\..\..\easylogger\inc" -O0 -g3 -Wall -c "main.c" -o "out\main.o" -gcc -o out\EasyLoggerWinDemo.exe "out\main.o" "out\elog_utils.o" "out\elog.o" "out\elog_port.o" -lpthread +gcc -o out\EasyLoggerWinDemo.exe "out\main.o" "out\elog_utils.o" "out\elog.o" "out\elog_port.o" "out\elog_file.o" "out\elog_file_port.o" -lpthread