anz-bank / pkg

Common ANZ Go packages
https://pkg.go.dev/github.com/anz-bank/pkg
Apache License 2.0
2 stars 9 forks source link

Redesigned Logger API #4

Closed nofun97 closed 4 years ago

nofun97 commented 4 years ago

the APIs available to the user

func From(ctx context.Context) Logger { /*…*/ }

func Suppress(keys ...string) Fields                                  { /*…*/ }
func With(key string, val interface{}) Fields                         { /*…*/ }
func WithCtxRef(key string, ctxKey interface{}) Fields                { /*…*/ }
func WithFunc(key string, f func(context.Context) interface{}) Fields { /*…*/ }
func WithLogger(logger Logger) Fields                                 { /*…*/ }

func (Fields) Chain(fieldses ...Fields) Fields                                 { /*…*/ }
func (Fields) From(ctx context.Context) Logger                                 { /*…*/ }
func (Fields) Onto(ctx context.Context) context.Context                        { /*…*/ }
func (Fields) Suppress(keys ...string) Fields                                  { /*…*/ }
func (Fields) With(key string, val interface{}) Fields                         { /*…*/ }
func (Fields) WithCtxRef(key string, ctxKey interface{}) Fields                { /*…*/ }
func (Fields) WithFunc(key string, f func(context.Context) interface{}) Fields { /*…*/ }
func (Fields) WithLogger(logger Logger) Fields                                 { /*…*/ }

// Logger is the underlying logger that is to be added to a context
type Logger interface {
    // Debug logs the message at the Debug level
    Debug(args ...interface{})
    // Debugf logs the message at the Debug level
    Debugf(format string, args ...interface{})
    // Info logs the message at the Info level
    Info(args ...interface{})
    // Infof logs the message at the Info level
    Infof(format string, args ...interface{})
}

and for the internal logger operation unavailable to the users, i'll also make

type internalLoggerOps interface {
    // PutFields returns the Logger with the new fields added
    PutFields(fields frozen.Map) Logger
    // Copy returns a logger whose data is copied from the caller
    Copy() Logger
}