Skip to content

Commit

Permalink
declogging entry interface to avoid interfacebloat
Browse files Browse the repository at this point in the history
  • Loading branch information
Madhur committed Dec 7, 2024
1 parent 5039841 commit f22cc6c
Showing 1 changed file with 41 additions and 27 deletions.
68 changes: 41 additions & 27 deletions pkg/log/entry.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,33 +11,8 @@ import (
"github.com/gomods/athens/pkg/errors"
)

// Entry is an abstraction to the
// Logger and the slog.Entry
// so that *Logger always creates
// an Entry copy which ensures no
// Fields are being overwritten.
type Entry interface {
// Debugf logs a debug message with formatting
Debugf(format string, args ...interface{})

// Infof logs an info message with formatting
Infof(format string, args ...interface{})

// Warnf logs a warning message with formatting
Warnf(format string, args ...interface{})

// Errorf logs an error message with formatting
Errorf(format string, args ...interface{})

// Fatalf logs a fatal message with formatting and terminates the program
Fatalf(format string, args ...interface{})

// Panicf logs a panic message with formatting and panics
Panicf(format string, args ...interface{})

// Printf logs a message with formatting at default level
Printf(format string, args ...interface{})

// Logger handles basic logging operations

Check failure on line 14 in pkg/log/entry.go

View workflow job for this annotation

GitHub Actions / lint

Comment should end in a period (godot)
type LogOps interface {
// Debug logs a debug message
Debug(args ...interface{})

Expand All @@ -58,7 +33,32 @@ type Entry interface {

// Print logs a message at default level
Print(args ...interface{})
}

type FormattedLogOps interface {
// Debugf logs a debug message with formatting
Debugf(format string, args ...interface{})

// Infof logs an info message with formatting
Infof(format string, args ...interface{})

// Warnf logs a warning message with formatting
Warnf(format string, args ...interface{})

// Errorf logs an error message with formatting
Errorf(format string, args ...interface{})

// Fatalf logs a fatal message with formatting and terminates the program
Fatalf(format string, args ...interface{})

// Panicf logs a panic message with formatting and panics
Panicf(format string, args ...interface{})

// Printf logs a message with formatting at default level
Printf(format string, args ...interface{})
}

type ContextualLogOps interface {
// WithFields returns a new Entry with the provided fields added
WithFields(fields map[string]any) Entry

Expand All @@ -70,14 +70,28 @@ type Entry interface {

// WithContext returns a new Entry with the context added to the fields
WithContext(ctx context.Context) Entry
}

type SystemLogger interface {
// SystemErr handles system errors with appropriate logging levels
SystemErr(err error)

// WriterLevel returns an io.PipeWriter for the specified logging level
WriterLevel(level slog.Level) *io.PipeWriter
}

// Entry is an abstraction to the
// Logger and the slog.Entry
// so that *Logger always creates
// an Entry copy which ensures no
// Fields are being overwritten.
type Entry interface {
LogOps
FormattedLogOps
ContextualLogOps
SystemLogger
}

type entry struct {
logger *slog.Logger
}
Expand Down

0 comments on commit f22cc6c

Please sign in to comment.