feature:根据文件大小分割日志
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
#include "logging.h"
|
||||
#include "logging/logging-handler.h"
|
||||
#include "utils/logging-utils.h"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
@@ -17,14 +18,10 @@
|
||||
|
||||
Logger *G_LOGGER = NULL;
|
||||
|
||||
static void getTimeStr(char *timeStr) {
|
||||
time_t t = time(NULL);
|
||||
struct tm *p = localtime(&t);
|
||||
char _timeStr[20];
|
||||
strftime(_timeStr, sizeof(_timeStr), "%Y-%m-%d %H:%M:%S", p);
|
||||
strcpy(timeStr, _timeStr);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 为日志添加一个handler
|
||||
* @param handler 处理器对象
|
||||
*/
|
||||
static void addHandler(log_Handler *handler) {
|
||||
if (G_LOGGER == NULL) {
|
||||
return;
|
||||
@@ -53,6 +50,14 @@ void addInterceptor(log_Interceptor *Interceptor) {
|
||||
G_LOGGER->interceptor = Interceptor;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 内部日志打印处理核心函数
|
||||
* @param level 日志等级
|
||||
* @param color 应用的颜色
|
||||
* @param message 日志内容
|
||||
* @param ... 格式化参数列表
|
||||
* @return
|
||||
*/
|
||||
static void
|
||||
_builtin_log(char *level, const char *color, const char *message, ...) {
|
||||
if (G_LOGGER == NULL) {
|
||||
@@ -77,7 +82,7 @@ _builtin_log(char *level, const char *color, const char *message, ...) {
|
||||
|
||||
if (handler->apply_color)
|
||||
sprintf(logStr,
|
||||
"%s: %s %s%s%s %s\n",
|
||||
"[%s]: %s %s%s%s %s\n",
|
||||
G_LOGGER->name,
|
||||
timeStr,
|
||||
color,
|
||||
@@ -86,7 +91,7 @@ _builtin_log(char *level, const char *color, const char *message, ...) {
|
||||
message);
|
||||
else
|
||||
sprintf(
|
||||
logStr, "%s: %s %s %s\n", G_LOGGER->name, timeStr, level, message);
|
||||
logStr, "[%s]: %s %s %s\n", G_LOGGER->name, timeStr, level, message);
|
||||
|
||||
handler->output(handler, logStr);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user