import worker code
This commit is contained in:
parent
61654a06e8
commit
8831040043
64 changed files with 20853 additions and 1 deletions
93
src/include/xcelog.h
Normal file
93
src/include/xcelog.h
Normal file
|
|
@ -0,0 +1,93 @@
|
|||
#ifndef _XCELOG_H_
|
||||
#define _XCELOG_H_
|
||||
|
||||
#include "tlog.h"
|
||||
#include <pthread.h>
|
||||
|
||||
|
||||
static pthread_mutex_t log_mutex = PTHREAD_MUTEX_INITIALIZER;
|
||||
static int xce_log_initialized = 0;
|
||||
|
||||
typedef enum {
|
||||
XCE_LOG_DEBUG3 = TLOG_DEBUG3,
|
||||
XCE_LOG_DEBUG2 = TLOG_DEBUG2,
|
||||
XCE_LOG_DEBUG = TLOG_DEBUG,
|
||||
XCE_LOG_INFO = TLOG_INFO,
|
||||
XCE_LOG_NOTICE = TLOG_NOTICE,
|
||||
XCE_LOG_WARN = TLOG_WARN,
|
||||
XCE_LOG_ERROR = TLOG_ERROR,
|
||||
XCE_LOG_FATAL = TLOG_FATAL,
|
||||
XCE_LOG_OFF = TLOG_OFF,
|
||||
XCE_LOG_END = TLOG_END
|
||||
} LogLevel;
|
||||
|
||||
static inline int xce_init_xcecd_log(const char* log_file,
|
||||
int log_size,
|
||||
int log_level)
|
||||
{
|
||||
int ret;
|
||||
pthread_mutex_lock(&log_mutex);
|
||||
if (!xce_log_initialized) {
|
||||
ret = tlog_init(log_file, log_size, 6, 0, 0);
|
||||
if (ret != 0) {
|
||||
tlog(TLOG_ERROR, "XCECD start tlog failed.\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
tlog_setlevel(log_level);
|
||||
xce_log_initialized = 1;
|
||||
}
|
||||
pthread_mutex_unlock(&log_mutex);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static inline int xce_init_xcecdwk_log(const char* log_file,
|
||||
int log_size,
|
||||
int log_level)
|
||||
{
|
||||
int ret;
|
||||
pthread_mutex_lock(&log_mutex);
|
||||
if (!xce_log_initialized) {
|
||||
ret = tlog_init(log_file, log_size, 6, 0, 0);
|
||||
if (ret != 0) {
|
||||
tlog(TLOG_ERROR, "XCECD_WORKER start tlog failed.\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
tlog_setlevel(log_level);
|
||||
xce_log_initialized = 1;
|
||||
}
|
||||
pthread_mutex_unlock(&log_mutex);
|
||||
return 0;
|
||||
}
|
||||
|
||||
#define XCECD_LOG(level, format, ...) \
|
||||
do { \
|
||||
pthread_mutex_lock(&log_mutex); \
|
||||
tlog((int)(level), \
|
||||
format \
|
||||
__VA_OPT__(,) __VA_ARGS__); \
|
||||
pthread_mutex_unlock(&log_mutex); \
|
||||
} while(0)
|
||||
|
||||
#define XCECD_WORKER_LOG(level, format, ...) \
|
||||
do { \
|
||||
pthread_mutex_lock(&log_mutex); \
|
||||
tlog((int)(level), \
|
||||
format \
|
||||
__VA_OPT__(,) __VA_ARGS__); \
|
||||
pthread_mutex_unlock(&log_mutex); \
|
||||
} while(0)
|
||||
|
||||
|
||||
/* For different XCE modules we can have customized macros. Here is an example
|
||||
* of XCECD log micro.
|
||||
*/
|
||||
#define CONTROLLER_LOG(level, format, ...) tlog((int)level, format __VA_OPT__(,)__VA_ARGS__)
|
||||
#define SCHEDULER_LOG(level, format, ...) tlog((int)level, format __VA_OPT__(,)__VA_ARGS__)
|
||||
|
||||
static inline void xce_log_fini() {
|
||||
tlog_exit();
|
||||
}
|
||||
|
||||
#endif
|
||||
Loading…
Add table
Add a link
Reference in a new issue