12345678910111213141516171819202122 |
- package common
- import (
- "log/slog"
- "os"
- )
- var logger *slog.Logger
- func GetLog(prefix string) *slog.Logger {
- initLog(prefix)
- return logger
- }
- func initLog(prefix string) {
- textHandler := slog.NewJSONHandler(os.Stdout, &slog.HandlerOptions{
- AddSource: true,
- Level: slog.LevelDebug,
- }).WithAttrs([]slog.Attr{slog.String("module", prefix)})
- logger = slog.New(textHandler)
- }
|