1
0
mirror of https://github.com/armink/EasyLogger.git synced 2025-02-07 16:44:09 +08:00

Merge pull request #90 from 5ooo/master

optimize async log
This commit is contained in:
朱天龙 (Armink) 2021-04-08 09:30:15 +08:00 committed by GitHub
commit 9bacff022c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 16 additions and 5 deletions

View File

@ -31,10 +31,12 @@
/* enable log output. default open this macro */ /* enable log output. default open this macro */
#define ELOG_OUTPUT_ENABLE #define ELOG_OUTPUT_ENABLE
/* enable terminal output. default open this macro */
#define ELOG_TERMINAL_ENABLE
/* enable log write file. default open this macro */ /* enable log write file. default open this macro */
#define ELOG_FILE_ENABLE #define ELOG_FILE_ENABLE
/* enable flush file cache. default open this macro */ /* enable flush file cache. default open this macro */
#define ELOG_FILE_FLUSH_CAHCE_ENABLE #define ELOG_FILE_FLUSH_CACHE_ENABLE
/* setting static output log level */ /* setting static output log level */
#define ELOG_OUTPUT_LVL ELOG_LVL_VERBOSE #define ELOG_OUTPUT_LVL ELOG_LVL_VERBOSE
/* enable assert check */ /* enable assert check */
@ -58,7 +60,7 @@
/* the highest output level for async mode, other level will sync output */ /* the highest output level for async mode, other level will sync output */
#define ELOG_ASYNC_OUTPUT_LVL ELOG_LVL_DEBUG #define ELOG_ASYNC_OUTPUT_LVL ELOG_LVL_DEBUG
/* buffer size for asynchronous output mode */ /* buffer size for asynchronous output mode */
#define ELOG_ASYNC_OUTPUT_BUF_SIZE (ELOG_LINE_BUF_SIZE * 100) #define ELOG_ASYNC_OUTPUT_BUF_SIZE (ELOG_LINE_BUF_SIZE * 50)
/* each asynchronous output's log which must end with newline sign */ /* each asynchronous output's log which must end with newline sign */
//#define ELOG_ASYNC_LINE_OUTPUT //#define ELOG_ASYNC_LINE_OUTPUT
/* asynchronous output mode using POSIX pthread implementation */ /* asynchronous output mode using POSIX pthread implementation */

View File

@ -75,7 +75,10 @@ void elog_port_deinit(void) {
*/ */
void elog_port_output(const char *log, size_t size) { void elog_port_output(const char *log, size_t size) {
/* output to terminal */ /* output to terminal */
#ifdef ELOG_TERMINAL_ENABLE
printf("%.*s", (int)size, log); printf("%.*s", (int)size, log);
#endif
#ifdef ELOG_FILE_ENABLE #ifdef ELOG_FILE_ENABLE
/* write the file */ /* write the file */
elog_file_write(log, size); elog_file_write(log, size);

View File

@ -34,7 +34,7 @@
/* enable log write file. default open this macro */ /* enable log write file. default open this macro */
#define ELOG_FILE_ENABLE #define ELOG_FILE_ENABLE
/* enable flush file cache. default open this macro */ /* enable flush file cache. default open this macro */
#define ELOG_FILE_FLUSH_CAHCE_ENABLE #define ELOG_FILE_FLUSH_CACHE_ENABLE
/* setting static output log level */ /* setting static output log level */
#define ELOG_OUTPUT_LVL ELOG_LVL_VERBOSE #define ELOG_OUTPUT_LVL ELOG_LVL_VERBOSE
/* enable assert check */ /* enable assert check */

View File

@ -131,7 +131,7 @@ void elog_file_write(const char *log, size_t size)
fwrite(log, size, 1, fp); fwrite(log, size, 1, fp);
#ifdef ELOG_FILE_FLUSH_CAHCE_ENABLE #ifdef ELOG_FILE_FLUSH_CACHE_ENABLE
fflush(fp); fflush(fp);
#endif #endif

View File

@ -47,16 +47,22 @@
#define ELOG_ASYNC_OUTPUT_PTHREAD_PRIORITY (sched_get_priority_max(SCHED_RR) - 1) #define ELOG_ASYNC_OUTPUT_PTHREAD_PRIORITY (sched_get_priority_max(SCHED_RR) - 1)
#endif #endif
/* output thread poll get log buffer size */ /* output thread poll get log buffer size */
#ifndef ELOG_ASYNC_LINE_OUTPUT
#ifndef ELOG_ASYNC_POLL_GET_LOG_BUF_SIZE
#define ELOG_ASYNC_POLL_GET_LOG_BUF_SIZE (ELOG_ASYNC_OUTPUT_BUF_SIZE - 4)
#endif
#else
#ifndef ELOG_ASYNC_POLL_GET_LOG_BUF_SIZE #ifndef ELOG_ASYNC_POLL_GET_LOG_BUF_SIZE
#define ELOG_ASYNC_POLL_GET_LOG_BUF_SIZE (ELOG_LINE_BUF_SIZE - 4) #define ELOG_ASYNC_POLL_GET_LOG_BUF_SIZE (ELOG_LINE_BUF_SIZE - 4)
#endif #endif
#endif
#endif /* ELOG_ASYNC_OUTPUT_USING_PTHREAD */ #endif /* ELOG_ASYNC_OUTPUT_USING_PTHREAD */
/* asynchronous output log notice */ /* asynchronous output log notice */
static sem_t output_notice; static sem_t output_notice;
/* asynchronous output pthread thread */ /* asynchronous output pthread thread */
static pthread_t async_output_thread; static pthread_t async_output_thread;
#endif /* ELOG_ASYNC_OUTPUT_USING_PTHREAD */ #endif /* ELOG_ASYNC_OUTPUT_ENABLE */
/* the highest output level for async mode, other level will sync output */ /* the highest output level for async mode, other level will sync output */
#ifdef ELOG_ASYNC_OUTPUT_LVL #ifdef ELOG_ASYNC_OUTPUT_LVL