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
- func VerbosityFromInt(verbosity int) zapcore.Level
- type LogType
- type Logger
- func (l *Logger) Debugf(format string, args ...any)
- func (l *Logger) Errorf(format string, args ...any)
- func (l *Logger) Fatalf(format string, args ...any)
- func (l *Logger) GetClientStreamInterceptor() grpc.DialOption
- func (l *Logger) GetClientUnaryInterceptor() grpc.DialOption
- func (l *Logger) GetServerStreamInterceptor() grpc.ServerOption
- func (l *Logger) GetServerUnaryInterceptor() grpc.ServerOption
- func (l *Logger) Infof(format string, args ...any)
- func (l *Logger) Named(name string) *Logger
- func (l *Logger) ReplaceGRPCLogger()
- func (l *Logger) Sync()
- func (l *Logger) Warnf(format string, args ...any)
- func (l *Logger) With(fields ...any) *Logger
- func (l *Logger) WithIncreasedLevel(level zapcore.Level) *Logger
Constants ¶
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 ¶
VerbosityFromInt converts a verbosity level from an integer to a zapcore.Level.
Types ¶
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 (*Logger) Debugf ¶
Debugf logs a message at Debug level. Debug logs are typically voluminous, and contain detailed information on the flow of execution.
func (*Logger) Errorf ¶
Errorf logs a message at Error level. Error logs are high priority and indicate something has gone wrong.
func (*Logger) Fatalf ¶
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 ¶
Infof logs a message at Info level. This is the default logging priority and should be used for all normal messages.
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 ¶
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.