log.go 723 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. package logging
  2. import (
  3. "context"
  4. "log/slog"
  5. "os"
  6. )
  7. const LevelTrace slog.Level = slog.LevelDebug - 4
  8. type Logger struct {
  9. logger *slog.Logger
  10. }
  11. func NewLogger() *Logger {
  12. handler := slog.NewTextHandler(os.Stdout, nil)
  13. return &Logger{
  14. logger: slog.New(handler),
  15. }
  16. }
  17. func (l *Logger) Trace(msg string, args ...any) {
  18. l.logger.Log(context.Background(), LevelTrace, msg, args...)
  19. }
  20. func (l *Logger) Debug(msg string, args ...any) {
  21. l.logger.Debug(msg, args...)
  22. }
  23. func (l *Logger) Info(msg string, args ...any) {
  24. l.logger.Info(msg, args...)
  25. }
  26. func (l *Logger) Warn(msg string, args ...any) {
  27. l.logger.Warn(msg, args...)
  28. }
  29. func (l *Logger) Error(msg string, args ...any) {
  30. l.logger.Error(msg, args...)
  31. }