logger

package
v2.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 8, 2022 License: AGPL-3.0 Imports: 10 Imported by: 0

Documentation

Overview

Package logger provides logging functionality for Constellation services. It is a thin wrapper around the zap package, providing a consistent interface for logging. Use this package to implement logging for your Constellation services.

Usage

1. Create a logger using New().

2. Defer the Sync() method to ensure that all log entries are flushed.

3. Use the Debugf(), Infof(), Warnf(), Errorf(), and Fatalf() methods depending on the level of logging you need.

4. Use the Named() method to create a named child logger.

5. Use the With() method to create a child logger with structured context. This can also be used to add context to a single log message:

logger.With(zap.String("key", "value")).Infof("log message")

Log Levels

Use Debugf() to log low level and detailed information that is useful for debugging.

Use Infof() to log general information. This method is correct for most logging purposes.

Use Warnf() to log information that may indicate unwanted behavior, but is not an error.

Use Errorf() to log information about any errors that occurred.

Use Fatalf() to log information about any errors that occurred and then exit the program.

Index

Constants

View Source
const CmdLineVerbosityDescription = "log verbosity in zap logging levels. Use -1 for debug information, 0 for info, 1 for warn, 2 for error"

Variables

This section is empty.

Functions

func VerbosityFromInt

func VerbosityFromInt(verbosity int) zapcore.Level

VerbosityFromInt converts a verbosity level from an integer to a zapcore.Level.

Types

type LogType

type LogType int

LogType indicates the output encoding of the log.

const (
	// JSONLog encodes logs in JSON format.
	JSONLog LogType = iota
	// PlainLog encodes logs as human readable text.
	PlainLog
)

type Logger

type Logger struct {
	// contains filtered or unexported fields
}

Logger is a wrapper for zap logger. The purpose is to provide a simple interface for logging with sensible defaults.

func New

func New(logType LogType, logLevel zapcore.Level) *Logger

New creates a new Logger. Set name to an empty string to create an unnamed logger.

func NewTest

func NewTest(t *testing.T) *Logger

NewTest creates a logger for unit / integration tests.

func (*Logger) Debugf

func (l *Logger) Debugf(format string, args ...any)

Debugf logs a message at Debug level. Debug logs are typically voluminous, and contain detailed information on the flow of execution.

func (*Logger) Errorf

func (l *Logger) Errorf(format string, args ...any)

Errorf logs a message at Error level. Error logs are high priority and indicate something has gone wrong.

func (*Logger) Fatalf

func (l *Logger) Fatalf(format string, args ...any)

Fatalf logs the message and then calls os.Exit(1). Use this to exit your program when a fatal error occurs.

func (*Logger) GetClientStreamInterceptor

func (l *Logger) GetClientStreamInterceptor() grpc.DialOption

GetClientStreamInterceptor returns a gRPC client option for intercepting stream gRPC logs.

func (*Logger) GetClientUnaryInterceptor

func (l *Logger) GetClientUnaryInterceptor() grpc.DialOption

GetClientUnaryInterceptor returns a gRPC client option for intercepting unary gRPC logs.

func (*Logger) GetServerStreamInterceptor

func (l *Logger) GetServerStreamInterceptor() grpc.ServerOption

GetServerStreamInterceptor returns a gRPC server option for intercepting streaming gRPC logs.

func (*Logger) GetServerUnaryInterceptor

func (l *Logger) GetServerUnaryInterceptor() grpc.ServerOption

GetServerUnaryInterceptor returns a gRPC server option for intercepting unary gRPC logs.

func (*Logger) Infof

func (l *Logger) Infof(format string, args ...any)

Infof logs a message at Info level. This is the default logging priority and should be used for all normal messages.

func (*Logger) Named

func (l *Logger) Named(name string) *Logger

Named returns a named logger.

func (*Logger) ReplaceGRPCLogger

func (l *Logger) ReplaceGRPCLogger()

ReplaceGRPCLogger replaces grpc's internal logger with the given logger.

func (*Logger) Sync

func (l *Logger) Sync()

Sync flushes any buffered log entries. Applications should take care to call Sync before exiting.

func (*Logger) Warnf

func (l *Logger) Warnf(format string, args ...any)

Warnf logs a message at Warn level. Warn logs are more important than Info, but they don't need human review or necessarily indicate an error.

func (*Logger) With

func (l *Logger) With(fields ...any) *Logger

With returns a logger with structured context.

func (*Logger) WithIncreasedLevel

func (l *Logger) WithIncreasedLevel(level zapcore.Level) *Logger

WithIncreasedLevel returns a logger with increased logging level.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL