feature:根据文件大小分割日志

This commit is contained in:
2024-11-19 21:31:00 +08:00
parent 81cebc7a18
commit de03985fef
11 changed files with 137 additions and 29 deletions

View File

@@ -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);
}