Documentation ¶
Overview ¶
Copyright 2022-2023 Contributors to the Veraison project. SPDX-License-Identifier: Apache-2.0
Copyright 2022-2023 Contributors to the Veraison project. SPDX-License-Identifier: Apache-2.0
Copyright 2022-2023 Contributors to the Veraison project. SPDX-License-Identifier: Apache-2.0
Copyright 2022-2023 Contributors to the Veraison project. SPDX-License-Identifier: Apache-2.0
Index ¶
- Constants
- func ColorCapitalLevelEncoder(l zapcore.Level, enc zapcore.PrimitiveArrayEncoder)
- func DPanic(args ...interface{})
- func DPanicf(template string, args ...interface{})
- func DPanicln(args ...interface{})
- func DPanicw(msg string, keysAndValues ...interface{})
- func Debug(args ...interface{})
- func Debugf(template string, args ...interface{})
- func Debugln(args ...interface{})
- func Debugw(msg string, keysAndValues ...interface{})
- func Error(args ...interface{})
- func Errorf(template string, args ...interface{})
- func Errorln(args ...interface{})
- func Errorw(msg string, keysAndValues ...interface{})
- func Fatal(args ...interface{})
- func Fatalf(template string, args ...interface{})
- func Fatalln(args ...interface{})
- func Fatalw(msg string, keysAndValues ...interface{})
- func GetLevel() zapcore.Level
- func Info(args ...interface{})
- func Infof(template string, args ...interface{})
- func Infoln(args ...interface{})
- func Infow(msg string, keysAndValues ...interface{})
- func Init(v *viper.Viper, classifiers map[string]interface{}) error
- func InitGinWriter()
- func LogProblem(logger *zap.SugaredLogger, prob *problems.DefaultProblem)
- func Named(name string) *zap.SugaredLogger
- func NamedWriter(name string, level zapcore.Level) io.Writer
- func Panic(args ...interface{})
- func Panicf(template string, args ...interface{})
- func Panicln(args ...interface{})
- func Panicw(msg string, keysAndValues ...interface{})
- func SetLevel(l zapcore.Level)
- func Sync() error
- func VerboseViper()
- func Warn(args ...interface{})
- func Warnf(template string, args ...interface{})
- func Warnln(args ...interface{})
- func Warnw(msg string, keysAndValues ...interface{})
- func WriterFromZap(logger *zap.SugaredLogger, level zapcore.Level) io.Writer
- type Config
- type GinColorWriter
- type HCLogger
- func (o *HCLogger) Debug(msg string, args ...interface{})
- func (o *HCLogger) Error(msg string, args ...interface{})
- func (o *HCLogger) ImpliedArgs() []interface{}
- func (o *HCLogger) Info(msg string, args ...interface{})
- func (o *HCLogger) IsDebug() bool
- func (o *HCLogger) IsError() bool
- func (o *HCLogger) IsInfo() bool
- func (o *HCLogger) IsTrace() bool
- func (o *HCLogger) IsWarn() bool
- func (o *HCLogger) Log(level hclog.Level, msg string, args ...interface{})
- func (o *HCLogger) Name() string
- func (o *HCLogger) Named(name string) hclog.Logger
- func (o *HCLogger) ResetNamed(name string) hclog.Logger
- func (o *HCLogger) SetLevel(level hclog.Level)
- func (o *HCLogger) StandardLogger(opts *hclog.StandardLoggerOptions) *stdlog.Logger
- func (o *HCLogger) StandardWriter(opts *hclog.StandardLoggerOptions) io.Writer
- func (o *HCLogger) Trace(msg string, args ...interface{})
- func (o *HCLogger) Warn(msg string, args ...interface{})
- func (o *HCLogger) With(args ...interface{}) hclog.Logger
Constants ¶
const ( DebugLevel = zap.DebugLevel TraceLevel = zap.DebugLevel InfoLevel = zap.InfoLevel WarnLevel = zap.WarnLevel ErrorLevel = zap.ErrorLevel )
Variables ¶
This section is empty.
Functions ¶
func ColorCapitalLevelEncoder ¶
func ColorCapitalLevelEncoder(l zapcore.Level, enc zapcore.PrimitiveArrayEncoder)
An encoder for zap log levels that colorizes them based on their value.
func DPanic ¶
func DPanic(args ...interface{})
DPanic uses fmt.Sprint to construct and log a message. In development, the logger then panics. (See DPanicLevel for details.)
func DPanicf ¶
func DPanicf(template string, args ...interface{})
DPanicf uses fmt.Sprintf to log a templated message. In development, the logger then panics. (See DPanicLevel for details.)
func DPanicln ¶
func DPanicln(args ...interface{})
DPanicln uses fmt.Sprintln to construct and log a message. In development, the logger then panics. (See DPanicLevel for details.)
func DPanicw ¶
func DPanicw(msg string, keysAndValues ...interface{})
DPanicw logs a message with some additional context. In development, the logger then panics. (See DPanicLevel for details.) The variadic key-value pairs are treated as they are in With.
func Debugf ¶
func Debugf(template string, args ...interface{})
Debugf uses fmt.Sprintf to log a templated message.
func Debugln ¶
func Debugln(args ...interface{})
Debugln uses fmt.Sprintln to construct and log a message.
func Debugw ¶
func Debugw(msg string, keysAndValues ...interface{})
Debugw logs a message with some additional context. The variadic key-value pairs are treated as they are in With.
When debug-level logging is disabled, this is much faster than
s.With(keysAndValues).Debug(msg)
func Errorf ¶
func Errorf(template string, args ...interface{})
Errorf uses fmt.Sprintf to log a templated message.
func Errorln ¶
func Errorln(args ...interface{})
Errorln uses fmt.Sprintln to construct and log a message.
func Errorw ¶
func Errorw(msg string, keysAndValues ...interface{})
Errorw logs a message with some additional context. The variadic key-value pairs are treated as they are in With.
func Fatal ¶
func Fatal(args ...interface{})
Fatal uses fmt.Sprint to construct and log a message, then calls os.Exit.
func Fatalf ¶
func Fatalf(template string, args ...interface{})
Fatalf uses fmt.Sprintf to log a templated message, then calls os.Exit.
func Fatalln ¶
func Fatalln(args ...interface{})
Fatalln uses fmt.Sprintln to construct and log a message, then calls os.Exit.
func Fatalw ¶
func Fatalw(msg string, keysAndValues ...interface{})
Fatalw logs a message with some additional context, then calls os.Exit. The variadic key-value pairs are treated as they are in With.
func Infof ¶
func Infof(template string, args ...interface{})
Infof uses fmt.Sprintf to log a templated message.
func Infoln ¶
func Infoln(args ...interface{})
Infoln uses fmt.Sprintln to construct and log a message.
func Infow ¶
func Infow(msg string, keysAndValues ...interface{})
Infow logs a message with some additional context. The variadic key-value pairs are treated as they are in With.
func Init ¶
Init initializes services global logging. All loggers are going to be derived from a root created here. The classifiers are used to identify the executable/application that is being logged, e.g. when naming the output files, they are applied to templated paths.
func InitGinWriter ¶
func InitGinWriter()
InitGinWriter sets up gin DefaultWriter to use Veraison logging.
func LogProblem ¶
func LogProblem(logger *zap.SugaredLogger, prob *problems.DefaultProblem)
LogProblem logs a problems.StatusProblem reported by the api. 500 probelms are logged as errors, everything else is logged as warnings.
func Named ¶
func Named(name string) *zap.SugaredLogger
Create a new logger (derived from the global root) with the specified name.
func NamedWriter ¶
NamedWriter creates an io.Writer that utilizes a zap logger with the specified name at the specifed level.
func Panic ¶
func Panic(args ...interface{})
Panic uses fmt.Sprint to construct and log a message, then panics.
func Panicf ¶
func Panicf(template string, args ...interface{})
Panicf uses fmt.Sprintf to log a templated message, then panics.
func Panicln ¶
func Panicln(args ...interface{})
Panicln uses fmt.Sprintln to construct and log a message, then panics.
func Panicw ¶
func Panicw(msg string, keysAndValues ...interface{})
Panicw logs a message with some additional context, then panics. The variadic key-value pairs are treated as they are in With.
func VerboseViper ¶
func VerboseViper()
VerboseViper enables verbose output level for Viper loggers. This is exposed as a separate function as one might want to enable this before initializing logging.
func Warnf ¶
func Warnf(template string, args ...interface{})
Warnf uses fmt.Sprintf to log a templated message.
func Warnln ¶
func Warnln(args ...interface{})
Warnln uses fmt.Sprintln to construct and log a message.
func Warnw ¶
func Warnw(msg string, keysAndValues ...interface{})
Warnw logs a message with some additional context. The variadic key-value pairs are treated as they are in With.
func WriterFromZap ¶
WriterFromZap returns an io.Writer utilzing the provided zap logger at the specified level.
Types ¶
type Config ¶
type Config struct { // Level is the minimum enabled logging level. Note that this is a dynamic // level, so calling Config.Level.SetLevel will atomically change the log // level of all loggers descended from this config. Level string `mapstructure:"level"` // Development puts the logger in development mode, which changes the // behavior of DPanicLevel and takes stacktraces more liberally. Development bool `mapstructure:"development" config:"zerodefault"` // DisableCaller stops annotating logs with the calling function's file // name and line number. By default, all logs are annotated. DisableCaller bool `mapstructure:"disable-caller" config:"zerodefault"` // DisableStacktrace completely disables automatic stacktrace capturing. By // default, stacktraces are captured for WarnLevel and above logs in // development and ErrorLevel and above in production. DisableStacktrace bool `mapstructure:"disable-stacktrace" config:"zerodefault"` // Sampling sets a sampling policy. A nil SamplingConfig disables sampling. Sampling *zap.SamplingConfig `mapstructure:"sampling" config:"zerodefault"` // Encoding sets the logger's encoding. Valid values are "json" and // "console", as well as any third-party encodings registered via // RegisterEncoder. Encoding string `mapstructure:"encoding"` // OutputPaths is a list of URLs or file paths to write logging output to. // See Open for details. OutputPaths []string `mapstructure:"output-paths"` // ErrorOutputPaths is a list of URLs to write internal logger errors to. // The default is standard error. // // Note that this setting only affects internal errors; for sample code that // sends error-level logs to a different location from info- and debug-level // logs, see the package-level AdvancedConfiguration example. ErrorOutputPaths []string `mapstructure:"err-output-paths"` // InitialFields is a collection of fields to add to the root logger. InitialFields map[string]interface{} `mapstructure:"initial-fields" config:"zerodefault"` // Format is the only field that is not directly transposed into // zap.Config. Instead, it is used to look up a pre-defined // zapcore.EncoderConfig. Format string `mapstructure:"format"` }
Config is, essentially, and adapter for zap.Config that defines mapstructure tags for zap.Config fields, and provides any additional Veraison-specific validation. Note: zap.Config defines field tags for JSON and YAML. Even though Veraison uses YAML config files, we do not load them directly, but use Viper, which uses mapstructure internally. Thus the need for mapstructure tags. Additionally, zap specifies camel-case for its config fields, whereas Verasion uses all-lower-case-with-hyphen-delimiter fields.
type GinColorWriter ¶
type GinColorWriter struct {
// contains filtered or unexported fields
}
GinColorWriter wraps zapio.Writer to provide warning and error highlighting inside gin traces.
func NewGinColorWriter ¶
func NewGinColorWriter(writer *zapio.Writer) *GinColorWriter
type HCLogger ¶
type HCLogger struct {
// contains filtered or unexported fields
}
HCLogger is a wrapper around zap logger used by Veraison that implements go-hclog.Logger interface expected by go-plugin plugins.
func NewInternalLogger ¶
func NewInternalLogger(logger *zap.SugaredLogger) *HCLogger
NewInternalLogger returns a new logger that logs all Info level messages at Debug level. This is to allow treating info-level messages form 3rd-party libararies as debug-level for our services.
func NewLogger ¶
func NewLogger(logger *zap.SugaredLogger) *HCLogger
func (*HCLogger) ImpliedArgs ¶
func (o *HCLogger) ImpliedArgs() []interface{}
ImpliedArgs returns With key/value pairs
func (*HCLogger) IsTrace ¶
Indicate if TRACE logs would be emitted. This and the other Is* guards are used to elide expensive logging code based on the current level.
func (*HCLogger) Named ¶
Create a logger that will prepend the name string on the front of all messages. If the logger already has a name, the new value will be appended to the current name. That way, a major subsystem can use this to decorate all it's own logs without losing context.
func (*HCLogger) ResetNamed ¶
Create a logger that will prepend the name string on the front of all messages. This sets the name of the logger to the value directly, unlike Named which honor the current name as well.
func (*HCLogger) SetLevel ¶
func (o *HCLogger) SetLevel(level hclog.Level)
Updates the level. This should affect all related loggers as well, unless they were created with IndependentLevels. If an implementation cannot update the level on the fly, it should no-op.
func (*HCLogger) StandardLogger ¶
Return a value that conforms to the stdlib log.Logger interface
func (*HCLogger) StandardWriter ¶
Return a value that conforms to io.Writer, which can be passed into log.SetOutput()