Go to file
kingecg 36b2fe9f34 ```
feat(logger): add maxCount configuration option for file appender

Add support for maxCount parameter in file appender configuration.
The maxCount option allows users to specify the maximum number of
backup files to keep when log rotation is enabled.

The new configuration option defaults to 1 if not specified in the
appender options and is passed to the FileAppender struct during
initialization.
```

Co-authored-by: Copilot <copilot@github.com>
2026-07-11 08:54:19 +08:00
.vscode getlogger返回指针,file 改为通过协程写文件 2023-12-13 23:05:42 +08:00
log refactor 2023-11-29 10:16:56 +08:00
test chore: update module path to git.kingecg.top 2025-06-26 01:05:39 +08:00
.gitignore fix test app 2024-09-21 22:41:52 +08:00
LICENSE 添加 LICENSE 2024-11-08 21:33:16 +08:00
README.md add doc 2025-06-06 19:38:01 +08:00
console.go add doc 2025-06-06 19:38:01 +08:00
file.go ``` 2026-07-11 08:54:19 +08:00
format.go ``` 2026-07-09 21:47:03 +08:00
format_test.go fix code 2025-06-06 09:57:25 +08:00
go.mod chore: update module path to git.kingecg.top 2025-06-25 21:56:20 +08:00
main.go ``` 2026-07-09 21:47:03 +08:00
main_test.go make it can reconfig 2025-06-06 13:55:46 +08:00

README.md

gologger

GoLogger 是一个简单但功能强大的 Go 语言日志库,提供灵活的日志记录功能。它支持多种日志输出方式(控制台、文件等),并允许自定义日志格式。

特性

  • 支持多种日志级别ERROR, WARN, INFO, DEBUG, TRACE
  • 支持多种输出方式:控制台、文件(支持滚动策略)
  • 可定制日志格式
  • 支持按类别记录日志

安装

go get github.com/yourusername/gologger

快速开始

package main

import (
	"github.com/yourusername/gologger"
)

func main() {
	// 获取默认logger
	logger := gologger.GetLogger("main")

	// 设置全局日志级别
	gologger.Configure(gologger.LoggersConfig{
		Level: "info",
		Appenders: []gologger.LogAppenderConfig{
			{
				Type: "console",
			},
			{
				Type: "file",
				Options: map[string]interface{}{
					"filePath": "app.log",
					"EnableRolling": true,
					"MaxSize": 1024 * 1024 * 10, // 10MB
				},
			},
		},
	})

	// 记录日志
	logger.Info("Application started")
	logger.Error("An error occurred")
}

配置说明

日志级别

支持的级别包括off, error, warn, info, debug, trace

输出方式Appenders

  1. ConsoleAppender - 控制台输出 配置示例:

    {
     Type: "console",
    }
    
  2. FileAppender - 文件输出,支持滚动策略 配置参数:

    • filePath: 日志文件路径
    • EnableRolling: 是否启用滚动默认true
    • MaxSize: 单个文件最大大小字节默认10MB
    • MaxAge: 文件最大保存时间默认86400秒=24小时

格式化器

可以通过SelectFormatter选择不同的日志格式

  • simple: 简单格式 [timestamp] level : category - message
  • json: JSON 格式输出