gookit / slog

📑 Lightweight, configurable, extensible logging library written in Go. Support multi level, multi outputs and built-in multi file logger, buffers, clean, rotate-file handling.一个易于使用的,轻量级、可配置、可扩展的日志库。支持多个级别,输出到多文件;内置文件日志处理、自动切割、清理、压缩等增强功能
https://pkg.go.dev/github.com/gookit/slog
MIT License
383 stars 24 forks source link

record中的Time time.Time #105

Closed zuozhehao closed 1 year ago

zuozhehao commented 1 year ago

这里是不是得用指针,内部系统执行一段时间后,这个获取到的时间就固定不变。

https://github.com/gookit/slog/blob/513ffbb0e17e9713ed0e9b956d15f7f699c0fef9/record.go#L16

inhere commented 1 year ago

record 每次都是创建新的。在写入时, record.Time 为空则会使用当前时间。你是怎样使用的呢?

zuozhehao commented 1 year ago

record 每次都是创建新的。在写入时, record.Time 为空则会使用当前时间。你是怎样使用的呢?

record.Time format 成字符串,和其它信息拼接成一个字符串,存储到一个queue里,然后消费者读取queue里的消息发送到钉钉。

inhere commented 1 year ago

怎么记录日志的呢?r := logger.Record() 拿到就一直使用 r.Info()/r.Warn()

zuozhehao commented 1 year ago

怎么记录日志的呢?r := logger.Record() 拿到就一直使用 r.Info()/r.Warn()

直接使用slog.Error(err)

inhere commented 1 year ago

可以给个复现示例吗?

我测试都有时间:

wg := sync.WaitGroup{}
for i := 0; i < 100; i++ {
    wg.Add(1)
    go func(i int) {
        slog.Error("concurrent error log", i)
        time.Sleep(time.Millisecond * 50)
        wg.Done()
    }(i)
}
wg.Wait()

Output:

=== RUN   TestIssues_105/concurrent_write
[2023/06/28T10:18:08.881] [application] [ERROR] [issues_test.go:87,1] concurrent error log 21  
[2023/06/28T10:18:08.881] [application] [ERROR] [issues_test.go:87,1] concurrent error log 25  
[2023/06/28T10:18:08.881] [application] [ERROR] [issues_test.go:87,1] concurrent error log 23  
[2023/06/28T10:18:08.882] [application] [ERROR] [issues_test.go:87,1] concurrent error log 24  
[2023/06/28T10:18:08.882] [application] [ERROR] [issues_test.go:87,1] concurrent error log 29  
[2023/06/28T10:18:08.882] [application] [ERROR] [issues_test.go:87,1] concurrent error log 0  
[2023/06/28T10:18:08.882] [application] [ERROR] [issues_test.go:87,1] concurrent error log 26  
[2023/06/28T10:18:08.882] [application] [ERROR] [issues_test.go:87,1] concurrent error log 27  
zuozhehao commented 1 year ago

可以给个复现示例吗?

我测试都有时间:

wg := sync.WaitGroup{}
for i := 0; i < 100; i++ {
  wg.Add(1)
  go func(i int) {
      slog.Error("concurrent error log", i)
      time.Sleep(time.Millisecond * 50)
      wg.Done()
  }(i)
}
wg.Wait()

Output:

=== RUN   TestIssues_105/concurrent_write
[2023/06/28T10:18:08.881] [application] [ERROR] [issues_test.go:87,1] concurrent error log 21  
[2023/06/28T10:18:08.881] [application] [ERROR] [issues_test.go:87,1] concurrent error log 25  
[2023/06/28T10:18:08.881] [application] [ERROR] [issues_test.go:87,1] concurrent error log 23  
[2023/06/28T10:18:08.882] [application] [ERROR] [issues_test.go:87,1] concurrent error log 24  
[2023/06/28T10:18:08.882] [application] [ERROR] [issues_test.go:87,1] concurrent error log 29  
[2023/06/28T10:18:08.882] [application] [ERROR] [issues_test.go:87,1] concurrent error log 0  
[2023/06/28T10:18:08.882] [application] [ERROR] [issues_test.go:87,1] concurrent error log 26  
[2023/06/28T10:18:08.882] [application] [ERROR] [issues_test.go:87,1] concurrent error log 27  

不好复现,当出现大量异常的时候才会发生这种问题。

我们是在注册的handle,处理错误消息,然后存入queue,再统一消费。

不是没时间,有几种可能: 1、时间固定住了,每条消息的时间都一样。 2、时间超前了。 1

inhere commented 1 year ago

可以更新最新版本看看 v0.5.3

inhere commented 1 year ago

我先关了,使用最新版有问题再打开