Skip to content

Commit

Permalink
Add Slog adapter for async logging
Browse files Browse the repository at this point in the history
Introduce a new `slogAdapter` to integrate `slog` with the `asynq` logging interface. This adapter implements Debug, Info, Warn, Error, and Fatal methods, providing seamless logging at various levels.
  • Loading branch information
dmitrymomot committed Jul 29, 2024
1 parent 843d5d4 commit e542641
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions slog_adapter.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package asyncer

import (
"log/slog"
"os"

"github.com/hibiken/asynq"
)

type slogAdapter struct {
log slog.Logger
}

func NewSlogAdapter(log slog.Logger) asynq.Logger {
return &slogAdapter{log: log}
}

// Debug logs a message at Debug level.
func (s *slogAdapter) Debug(args ...interface{}) {
s.log.Debug("", args...)
}

// Info logs a message at Info level.
func (s *slogAdapter) Info(args ...interface{}) {
s.log.Info("", args...)
}

// Warn logs a message at Warning level.
func (s *slogAdapter) Warn(args ...interface{}) {
s.log.Warn("", args...)
}

// Error logs a message at Error level.
func (s *slogAdapter) Error(args ...interface{}) {
s.log.Error("", args...)
}

// Fatal logs a message at Fatal level
// and process will exit with status set to 1.
func (s *slogAdapter) Fatal(args ...interface{}) {
s.log.Error("", args...)
os.Exit(1)
}

0 comments on commit e542641

Please sign in to comment.