|
| 1 | +package slog |
| 2 | + |
| 3 | +import ( |
| 4 | + "context" |
| 5 | + "fmt" |
| 6 | + "log/slog" |
| 7 | + "os" |
| 8 | +) |
| 9 | + |
| 10 | +// New to create new interface for logger |
| 11 | +func New() *Manager { |
| 12 | + return &Manager{ |
| 13 | + logger: slog.New(slog.NewTextHandler(os.Stdout, nil)), |
| 14 | + } |
| 15 | +} |
| 16 | + |
| 17 | +// Manager for slog |
| 18 | +type Manager struct { |
| 19 | + logger *slog.Logger |
| 20 | +} |
| 21 | + |
| 22 | +func (l Manager) Infof(format string, args ...interface{}) { |
| 23 | + l.logger.InfoContext(context.Background(), fmt.Sprintf(format, args...)) |
| 24 | +} |
| 25 | + |
| 26 | +func (l Manager) Errorf(format string, args ...interface{}) { |
| 27 | + l.logger.ErrorContext(context.Background(), fmt.Sprintf(format, args...)) |
| 28 | +} |
| 29 | + |
| 30 | +func (l Manager) Fatalf(format string, args ...interface{}) { |
| 31 | + l.logger.ErrorContext(context.Background(), fmt.Sprintf(format, args...)) |
| 32 | + os.Exit(1) |
| 33 | +} |
| 34 | + |
| 35 | +func (l Manager) Debugf(format string, args ...interface{}) { |
| 36 | + l.logger.DebugContext(context.Background(), fmt.Sprintf(format, args...)) |
| 37 | +} |
| 38 | + |
| 39 | +func (l Manager) Info(args ...interface{}) { |
| 40 | + l.logger.InfoContext(context.Background(), fmt.Sprint(args...)) |
| 41 | +} |
| 42 | + |
| 43 | +func (l Manager) Error(args ...interface{}) { |
| 44 | + l.logger.ErrorContext(context.Background(), fmt.Sprint(args...)) |
| 45 | +} |
| 46 | + |
| 47 | +func (l Manager) Fatal(args ...interface{}) { |
| 48 | + l.logger.ErrorContext(context.Background(), fmt.Sprint(args...)) |
| 49 | + os.Exit(1) |
| 50 | +} |
| 51 | + |
| 52 | +func (l Manager) Debug(args ...interface{}) { |
| 53 | + l.logger.DebugContext(context.Background(), fmt.Sprint(args...)) |
| 54 | +} |
0 commit comments