Documentation
¶
Overview ¶
Package logger provides compatibility with logging guidelines
Index ¶
Examples ¶
Constants ¶
View Source
const (
// ISO8601 is timestamp format used by Logger
ISO8601 = "2006-01-02T15:04:05.000Z07:00"
)
Variables ¶
This section is empty.
Functions ¶
func PrivacyDataFormatter ¶
PrivacyDataFormatter formats the given sensitive string.
Types ¶
type Logger ¶
type Logger interface { Debug(ctx context.Context, v ...interface{}) Debugln(ctx context.Context, v ...interface{}) Debugf(ctx context.Context, f string, v ...interface{}) Info(ctx context.Context, v ...interface{}) Infoln(ctx context.Context, v ...interface{}) Infof(ctx context.Context, f string, v ...interface{}) Warn(ctx context.Context, v ...interface{}) Warnln(ctx context.Context, v ...interface{}) Warnf(ctx context.Context, f string, v ...interface{}) Error(ctx context.Context, v ...interface{}) Errorln(ctx context.Context, v ...interface{}) Errorf(ctx context.Context, f string, v ...interface{}) With(key string, value interface{}) Logger WithFields(map[string]interface{}) Logger // log with Error* and exit Fatal(ctx context.Context, v ...interface{}) Fatalln(ctx context.Context, v ...interface{}) Fatalf(ctx context.Context, f string, v ...interface{}) }
Logger is the interface for loggers.
func NewLogger ¶
func NewLogger() Logger
NewLogger returns a new Logger logging to stderr.
Example (With) ¶
log := NewLogger() log = log.With("key", "value") log.Info(context.Background(), "Message")
Output:
Example (WithCustomInterfaceFields) ¶
log := NewLogger() fields := map[string]interface{}{ "trace_id": 12345, "user_id": "haapis", "origin": "127.0.0.1", } logWithContext := log.WithFields(fields) logWithContext.Info(context.Background(), "Message") // Example Output: // {"level":"info","logger":"logging_test.go:63","message":"Message","origin":"127.0.0.1","timestamp":"2018-03-01T11:01:13.415+02:00","trace_id":12345,"user_id":"haapis"}
Output:
Example (WithEmptyContext) ¶
log := NewLogger() log.Info(context.Background(), "Message") log.Info(context.TODO(), "Other message")
Output:
Example (WithValidRequestContext) ¶
log := NewLogger() // Either create a span from existing request context or create a fresh one span, ctx := opentracing.StartSpanFromContext(context.Background(), "testOperation") defer span.Finish() log.Info(ctx, "Message")
Output:
type StdLogger ¶
type StdLogger interface { Print(ctx context.Context, v ...interface{}) Println(ctx context.Context, v ...interface{}) Printf(ctx context.Context, f string, v ...interface{}) }
StdLogger is the interface which allows us to use Logger with Print methods. To use this Logger as StdLogger just type cast the Logger to StdLogger.
Click to show internal directories.
Click to hide internal directories.