phuslu / log

Fastest structured logging
MIT License
672 stars 44 forks source link

Incorrect caller when using slog #61

Closed sdvcrx closed 1 year ago

sdvcrx commented 1 year ago

Hi!

package main

import (
    "log/slog"

    plog "github.com/phuslu/log"
)

func main() {
    plog.DefaultLogger = plog.Logger{
        Level: plog.DebugLevel,
        Caller: 1,
    }

    var logger *slog.Logger
    logger = plog.DefaultLogger.Slog()

    plog.Info().Msg("msg from phuslu/log")
    logger.Info("info msg from slog")
    logger.Error("error msg from slot")
}

Output:

{"time":"2023-09-06T15:36:41.406+08:00","level":"info","caller":"main.go:18","goid":1,"message":"msg from phuslu/log"}
{"time":"2023-09-06T15:36:41.406+08:00","caller":"logger_go1.21.go:30","goid":1,"message":"info msg from slog"}
{"time":"2023-09-06T15:36:41.406+08:00","caller":"logger_go1.21.go:30","goid":1,"message":"error msg from slot"}

And missing level when using log/slog, it would be great to have support for slog levels!

phuslu commented 1 year ago

fixed and released v1.0.88

https://goplay.tools/snippet/elUVQ8Io6eQ