Skip to content

Releases: donnie4w/go-logger

v0.28.0

22 Nov 04:20
Compare
Choose a tag to compare

v0.27.0

26 Oct 04:29
Compare
Choose a tag to compare

version 0.27.0
更新内容


说明

  1. 优化内存分配
  2. 优化写数据性能
  3. 增加日志属性自定义函数
  4. 增加各个日志级别格式化打印函数

说明

性能优化是该版本最重要的更新内容。性能优化的结果:

  1. 极高并发性能:极高的并发写数据性能,比官方库或同类型日志库高10倍以上。特别在Linux环境中,性能比同类型日志库高30倍以上.
  2. 极低内存占用:是官方库与同类型日志库的几分之一

由于压测数据篇幅过长,可以通过 使用文档 或 《go日志库性能基准压力测试:go-logger+slog+zap+log》 查看

以下新增功能详细说明:

1. 增加日志属性自定义函数 AttrFormat

通过 AttrFormat 可以对日志的各个属性标识进行自定义格式化设置

示例1:

 func Test_AttrFormat(t *testing.T) {
	attrformat := &logger.AttrFormat{
		SetLevelFmt: func(level logger.LEVELTYPE) string {
			switch level {
			case logger.LEVEL_DEBUG:
				return "debug:"
			case logger.LEVEL_INFO:
				return "info:"
			case logger.LEVEL_WARN:
				return "warn:"
			case logger.LEVEL_ERROR:
				return "error>>>>"
			case logger.LEVEL_FATAL:
				return "[fatal]"
			default:
				return "[unknown]"
			}
		},
		SetTimeFmt: func() (string, string, string) {
			s := time.Now().Format("2006-01-02 15:04:05")
			return s, "", ""
		},
	}
	logger.SetOption(&logger.Option{AttrFormat: attrformat, Console: true, FileOption: &logger.FileTimeMode{Filename: "testlogtime.log", Maxbuckup: 3, IsCompress: false, Timemode: logger.MODE_MONTH}})
	logger.Debug("this is a debug message", 1111111111111111111)
	logger.Info("this is a info message", 2222222222222222222)
	logger.Warn("this is a warn message", 33333333333333333)
	logger.Error("this is a error message", 4444444444444444444)
	logger.Fatal("this is a fatal message", 555555555555555555)
}

执行结果:

debug:2024-10-26 12:03:21 0_27_0_test.go:33 this is a debug message1111111111111111111
info:2024-10-26 12:03:21 0_27_0_test.go:34 this is a info message2222222222222222222
warn:2024-10-26 12:03:21 0_27_0_test.go:35 this is a warn message33333333333333333
error>>>>2024-10-26 12:03:21 0_27_0_test.go:36 this is a error message4444444444444444444
[fatal]2024-10-26 12:03:21 0_27_0_test.go:37 this is a fatal message555555555555555555

说明:修改了 LEVEL的标识 与时间的格式

示例2

func Test_AttrFormat2(t *testing.T) {
	attrformat := &logger.AttrFormat{
		SetBodyFmt: func(level logger.LEVELTYPE, bs []byte) []byte {
			//处理日志末尾换行符
			if size := len(bs); bs[size-1] == '\n' {
				bs = append(bs[:size-1], []byte("\x1b[0m\n")...)
			} else {
				bs = append(bs, []byte("\x1b[0m\n")...)
			}
			switch level {
			case logger.LEVEL_DEBUG:
				return append([]byte("\x1b[34m"), bs...)
			case logger.LEVEL_INFO:
				return append([]byte("\x1b[32m"), bs...)
			case logger.LEVEL_WARN:
				return append([]byte("\x1b[33m"), bs...)
			case logger.LEVEL_ERROR:
				return append([]byte("\x1b[31m"), bs...)
			case logger.LEVEL_FATAL:
				return append([]byte("\x1b[41m"), bs...)
			default:
				return bs
			}
		},
	}
	logger.SetOption(&logger.Option{AttrFormat: attrformat, Console: true, FileOption: &logger.FileTimeMode{Filename: "testlogtime.log", Maxbuckup: 3, IsCompress: false, Timemode: logger.MODE_MONTH}})
	logger.Debug("this is a debug message:", 111111111111111110)
	logger.Info("this is a info message:", 222222222222222220)
	logger.Warn("this is a warn message:", 333333333333333330)
	logger.Error("this is a error message:", 4444444444444444440)
	logger.Fatal("this is a fatal message:", 5555555555555555550)
}

执行结果

2. 增加各个日志级别格式化打印函数

通过 Debugf, Infof, Warnf, Errorf, Fatalf 等函数,支持在打印函数中使用 % 符号,用于指定输出格式化模式。

示例

func Test_format(t *testing.T) {
	logger.Debugf("this is a debugf message:%d", 1)
	logger.Infof("this is a infof message:%s", "hi,logger")
	logger.Warnf("this is a warnf message:%x,%x", 14, 15)
	logger.Errorf("this is a errorf message:%f", 44.4444)
	logger.Fatalf("this is a fatalf message:%t", true)
	logger.Debugf("this is a debugf message:%p", new(int))
}

执行结果

[DEBUG]2024/10/26 12:08:55 0_27_0_test.go:74 this is a debugf message:1
[INFO]2024/10/26 12:08:55 0_27_0_test.go:75 this is a infof message:hi,logger
[WARN]2024/10/26 12:08:55 0_27_0_test.go:76 this is a warnf message:e,f
[ERROR]2024/10/26 12:08:55 0_27_0_test.go:77 this is a errorf message:44.444400
[FATAL]2024/10/26 12:08:55 0_27_0_test.go:78 this is a fatalf message:true
[DEBUG]2024/10/26 12:08:55 0_27_0_test.go:79 this is a debugf message:0xc00000a938

v0.26.2

01 Oct 03:27
Compare
Choose a tag to compare

version 0.26.2
优化性能

v0.26.1

26 Aug 02:59
Compare
Choose a tag to compare

增加 FORMAT_RELATIVEFILENAME 属性,打印文件名为相对路径文件名

v0.26.0

08 Aug 02:14
Compare
Choose a tag to compare

v0.26.0 更新内容

  1. 外部处理函数:支持自定义外部处理函数。
  2. 日志堆栈信息:日志记录点可以回溯到程序入口点的所有函数调用序列,包括每一步函数调用的文件名,调用函数,行号
  3. 日志级别独立日志格式输出:支持不同日志级别 指定不同的日志输出格式。
更新内容说明与压测数据请查阅《go-logger v0.26.0》

v0.25.3

12 Jun 09:01
Compare
Choose a tag to compare
add init value for _lastprint

v0.25.2

11 Jun 08:39
Compare
Choose a tag to compare
v0.25.2

v0.25.1

06 Jun 04:35
Compare
Choose a tag to compare

this topic mainly optimizes the logger to split file logs by time
#31

v0.25.0

04 Jun 17:22
Compare
Choose a tag to compare
Update README.md

v0.24.1

14 May 15:12
Compare
Choose a tag to compare
fix  v0.24.1