fix
This commit is contained in:
@@ -16,11 +16,11 @@ typedef struct log_Handler {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief 文件处理器
|
* @brief 文件处理器
|
||||||
* @param name 文件名
|
* @param file_name 文件名
|
||||||
* @param max_size 文件最大大小
|
* @param max_size 文件最大大小
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
log_Handler *loggingHandlerFile(const char *name, unsigned int max_size);
|
log_Handler *loggingHandlerFile(const char *file_name, unsigned int max_size);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief 控制台处理器
|
* @brief 控制台处理器
|
||||||
|
|||||||
@@ -50,7 +50,7 @@ static void outputFileHandler(log_Handler *handler, const char *message) {
|
|||||||
changeFile(handler);
|
changeFile(handler);
|
||||||
}
|
}
|
||||||
|
|
||||||
log_Handler *loggingHandlerFile(const char *name, unsigned int max_size) {
|
log_Handler *loggingHandlerFile(const char *file_name, unsigned int max_size) {
|
||||||
char new_file_name[FILE_NAME_MAX_SIZE];
|
char new_file_name[FILE_NAME_MAX_SIZE];
|
||||||
int suffix = 0;
|
int suffix = 0;
|
||||||
unsigned int file_size;
|
unsigned int file_size;
|
||||||
@@ -60,7 +60,7 @@ log_Handler *loggingHandlerFile(const char *name, unsigned int max_size) {
|
|||||||
|
|
||||||
/// 获取未写满于设置最大文件大小的文件名
|
/// 获取未写满于设置最大文件大小的文件名
|
||||||
do {
|
do {
|
||||||
sprintf(new_file_name, "%s_%d.log", name, suffix++);
|
sprintf(new_file_name, "%s_%d.log", file_name, suffix++);
|
||||||
fp = fopen(new_file_name, "at");
|
fp = fopen(new_file_name, "at");
|
||||||
if (fp == NULL)
|
if (fp == NULL)
|
||||||
goto ERROR;
|
goto ERROR;
|
||||||
@@ -77,7 +77,7 @@ log_Handler *loggingHandlerFile(const char *name, unsigned int max_size) {
|
|||||||
handler_ex->file_size_max = max_size;
|
handler_ex->file_size_max = max_size;
|
||||||
handler_ex->file_size = file_size;
|
handler_ex->file_size = file_size;
|
||||||
handler_ex->suffix = suffix;
|
handler_ex->suffix = suffix;
|
||||||
handler_ex->file_name = strdup(name);
|
handler_ex->file_name = strdup(file_name);
|
||||||
if (handler_ex->file_name == NULL)
|
if (handler_ex->file_name == NULL)
|
||||||
goto ERROR;
|
goto ERROR;
|
||||||
|
|
||||||
|
|||||||
@@ -104,10 +104,10 @@ static void output_to_handler(log_Handler *handler,
|
|||||||
* @param ... 格式化参数列表
|
* @param ... 格式化参数列表
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
static void _builtin_cope(log_level level_e,
|
static void log_cope(log_level level_e,
|
||||||
char *level,
|
char *level,
|
||||||
const char *color,
|
const char *color,
|
||||||
const char *message) {
|
const char *message) {
|
||||||
if (G_LOGGER == NULL) {
|
if (G_LOGGER == NULL) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -136,7 +136,7 @@ void log_fatal(const char *message, ...) {
|
|||||||
va_start(args, message);
|
va_start(args, message);
|
||||||
vsprintf(logStr, message, args);
|
vsprintf(logStr, message, args);
|
||||||
va_end(args);
|
va_end(args);
|
||||||
_builtin_cope(LOG_FATAL, "Fatal", RED_B, logStr);
|
log_cope(LOG_FATAL, "Fatal", RED_B, logStr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -147,7 +147,7 @@ void log_error(const char *message, ...) {
|
|||||||
va_start(args, message);
|
va_start(args, message);
|
||||||
vsprintf(logStr, message, args);
|
vsprintf(logStr, message, args);
|
||||||
va_end(args);
|
va_end(args);
|
||||||
_builtin_cope(LOG_ERROR, "Error", RED, logStr);
|
log_cope(LOG_ERROR, "Error", RED, logStr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -158,7 +158,7 @@ void log_warning(const char *message, ...) {
|
|||||||
va_start(args, message);
|
va_start(args, message);
|
||||||
vsprintf(logStr, message, args);
|
vsprintf(logStr, message, args);
|
||||||
va_end(args);
|
va_end(args);
|
||||||
_builtin_cope(LOG_WARNING, "Warning", YELLOW, logStr);
|
log_cope(LOG_WARNING, "Warning", YELLOW, logStr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -169,7 +169,7 @@ void log_info(const char *message, ...) {
|
|||||||
va_start(args, message);
|
va_start(args, message);
|
||||||
vsprintf(logStr, message, args);
|
vsprintf(logStr, message, args);
|
||||||
va_end(args);
|
va_end(args);
|
||||||
_builtin_cope(LOG_INFO, "Info", GREEN, logStr);
|
log_cope(LOG_INFO, "Info", GREEN, logStr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -180,7 +180,7 @@ void log_debug(const char *message, ...) {
|
|||||||
va_start(args, message);
|
va_start(args, message);
|
||||||
vsprintf(logStr, message, args);
|
vsprintf(logStr, message, args);
|
||||||
va_end(args);
|
va_end(args);
|
||||||
_builtin_cope(LOG_DEBUG, "Debug", CYAN, logStr);
|
log_cope(LOG_DEBUG, "Debug", CYAN, logStr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
Logger *logger = newDefaultLogger("testLogger", LOG_DEBUG);
|
Logger *logger = newDefaultLogger(__FILE__, LOG_DEBUG);
|
||||||
|
|
||||||
log_info("This is an info message");
|
log_info("This is an info message");
|
||||||
log_error("This is an error message%s", "123");
|
log_error("This is an error message%s", "123");
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
#include "logging/logging-handler.h"
|
#include "logging/logging-handler.h"
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
Logger *logger = newDefaultLogger("testLogger", LOG_DEBUG);
|
Logger *logger = newDefaultLogger(__FILE__, LOG_DEBUG);
|
||||||
log_Handler *hander = loggingHandlerFile("test_log", 1024 * 1024 * 10);
|
log_Handler *hander = loggingHandlerFile("test_log", 1024 * 1024 * 10);
|
||||||
logger->addHandler(hander);
|
logger->addHandler(hander);
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
#include "logging.h"
|
#include "logging.h"
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
Logger *logger = newDefaultLogger("testLogger", LOG_DEBUG);
|
Logger *logger = newDefaultLogger(__FILE__, LOG_DEBUG);
|
||||||
|
|
||||||
log_info("This is an info message");
|
log_info("This is an info message");
|
||||||
log_error("This is an error message%s", "123");
|
log_error("This is an error message%s", "123");
|
||||||
|
|||||||
Reference in New Issue
Block a user