Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 22 additions & 2 deletions logging/logging.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"github.com/go-logr/logr"
"github.com/go-logr/zapr"
"go.uber.org/zap"
"go.uber.org/zap/zapcore"

"github.com/crossplane/crossplane-runtime/pkg/logging"

Expand All @@ -44,12 +45,31 @@ func NewLogrLogger(l logr.Logger) Logger {
}

// NewLogger returns a new logger.
func NewLogger(debug bool) (logging.Logger, error) {
o := []zap.Option{zap.AddCallerSkip(1)}
func NewLogger(debug, timeEncodeISO8601 bool, addCallerSkip ...int) (Logger, error) {
// default value for caller skip
callerSkip := 1
if len(addCallerSkip) > 0 {
callerSkip = addCallerSkip[0]
}

o := []zap.Option{zap.AddCallerSkip(callerSkip)}
if debug {
zl, err := zap.NewDevelopment(o...)
return NewLogrLogger(zapr.NewLogger(zl)), errors.Wrap(err, "cannot create development zap logger")
}

// If timeEncodeISO8601 is true, use ISO8601TimeEncoder for production logger.
if timeEncodeISO8601 {
ec := zap.NewProductionEncoderConfig()
ec.EncodeTime = zapcore.ISO8601TimeEncoder

p := zap.NewProductionConfig()
p.EncoderConfig = ec
zl, err := p.Build(o...)
return NewLogrLogger(zapr.NewLogger(zl)), errors.Wrap(err, "cannot create production zap logger")
}

// If timeEncodeISO8601 is false, use the default EpochTimeEncoder for production logger.
zl, err := zap.NewProduction(o...)
return NewLogrLogger(zapr.NewLogger(zl)), errors.Wrap(err, "cannot create production zap logger")
}
4 changes: 2 additions & 2 deletions sdk.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,6 @@ func Serve(fn v1beta1.FunctionRunnerServiceServer, o ...ServeOption) error {
}

// NewLogger returns a new logger.
func NewLogger(debug bool) (logging.Logger, error) {
return logging.NewLogger(debug)
func NewLogger(debug, timeEncodeISO8601 bool, addCallerSkip ...int) (logging.Logger, error) {
return logging.NewLogger(debug, timeEncodeISO8601, addCallerSkip...)
}