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
386 stars 25 forks source link

Extra newline added by default even if no newline set at Template String #53

Closed tonyho closed 2 years ago

tonyho commented 2 years ago

System (please complete the following information):

Describe the bug

The log function always add an extra newline.

I think that the function end with f should have the same behavior as fmt.Printf, so users can drop-in replace it with slog XXXXf serial function.

Except that, with or without the newline settings in template String should have an effect.

To Reproduce

import  log "github.com/gookit/slog"

const simplestTemplate = "[{{level}}] {{message}} {{data}} {{extra}}"

func init() {
    log.GetFormatter().(*log.TextFormatter).SetTemplate(simplestTemplate)

    log.Errorf("Test:line=%d\t", 1)
    log.Errorf("NoNewLineTest")
}
func main() {
}

Expected behavior

[ERROR] Test:line=1    [ERROR] NoNewLineTest

The actual output:

[ERROR] Test:line=1
[ERROR] NoNewLineTest
inhere commented 2 years ago

:) Now by default, each log is a separate line of messages. Can be easily output to a file or elsewhere.

tonyho commented 2 years ago

:) Now by default, each log is a separate line of messages. Can be easily output to a file or elsewhere.

So the XXXf function family would be a drop-in for fmt.Printf ?

I believe it would be better to leave the decision of newline setting to users, or at least an option should be exposed to users.

inhere commented 2 years ago

Adjusted, released version v0.3.2