Documentation ¶
Overview ¶
Defines global context-aware logger. The default implementation uses logrus. This package registers "logger" config section on init(). The structure of the config section is expected to be un-marshal-able to Config struct.
Index ¶
- func Debug(ctx context.Context, args ...interface{})
- func Debugf(ctx context.Context, format string, args ...interface{})
- func Debugln(ctx context.Context, args ...interface{})
- func Error(ctx context.Context, args ...interface{})
- func Errorf(ctx context.Context, format string, args ...interface{})
- func Errorln(ctx context.Context, args ...interface{})
- func Fatal(ctx context.Context, args ...interface{})
- func Fatalf(ctx context.Context, format string, args ...interface{})
- func Fatalln(ctx context.Context, args ...interface{})
- func GetLogWriter(ctx context.Context) *io.PipeWriter
- func Info(ctx context.Context, args ...interface{})
- func Infof(ctx context.Context, format string, args ...interface{})
- func InfofNoCtx(format string, args ...interface{})
- func Infoln(ctx context.Context, args ...interface{})
- func IsLoggable(_ context.Context, level Level) bool
- func Panic(ctx context.Context, args ...interface{})
- func Panicf(ctx context.Context, format string, args ...interface{})
- func Panicln(ctx context.Context, args ...interface{})
- func Print(ctx context.Context, args ...interface{})
- func Printf(ctx context.Context, format string, args ...interface{})
- func Println(ctx context.Context, args ...interface{})
- func SetConfig(cfg *Config) error
- func Warn(ctx context.Context, args ...interface{})
- func Warnf(ctx context.Context, format string, args ...interface{})
- func Warning(ctx context.Context, args ...interface{})
- func Warningf(ctx context.Context, format string, args ...interface{})
- func Warningln(ctx context.Context, args ...interface{})
- func Warnln(ctx context.Context, args ...interface{})
- func WithIndent(ctx context.Context, additionalIndent string) context.Context
- type Config
- type FormatterConfig
- type FormatterType
- type GcpEntry
- type GcpFormatter
- type GcpSeverity
- type Level
- type NoopLogger
- func (NoopLogger) Debug(args ...interface{})
- func (NoopLogger) Debugf(format string, args ...interface{})
- func (NoopLogger) Debugln(args ...interface{})
- func (NoopLogger) Error(args ...interface{})
- func (NoopLogger) Errorf(format string, args ...interface{})
- func (NoopLogger) Errorln(args ...interface{})
- func (NoopLogger) Fatal(...interface{})
- func (NoopLogger) Fatalf(string, ...interface{})
- func (NoopLogger) Fatalln(...interface{})
- func (NoopLogger) Info(args ...interface{})
- func (NoopLogger) Infof(format string, args ...interface{})
- func (NoopLogger) Infoln(args ...interface{})
- func (NoopLogger) Panic(...interface{})
- func (NoopLogger) Panicf(string, ...interface{})
- func (NoopLogger) Panicln(...interface{})
- func (NoopLogger) Print(...interface{})
- func (NoopLogger) Printf(string, ...interface{})
- func (NoopLogger) Println(...interface{})
- func (NoopLogger) Warn(args ...interface{})
- func (NoopLogger) Warnf(format string, args ...interface{})
- func (NoopLogger) Warning(args ...interface{})
- func (NoopLogger) Warningf(format string, args ...interface{})
- func (NoopLogger) Warningln(args ...interface{})
- func (NoopLogger) Warnln(args ...interface{})
- func (NoopLogger) WithError(err error) *logrus.Entry
- func (NoopLogger) WithField(key string, value interface{}) *logrus.Entry
- func (NoopLogger) WithFields(fields logrus.Fields) *logrus.Entry
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetLogWriter ¶
func GetLogWriter(ctx context.Context) *io.PipeWriter
Returns a standard io.PipeWriter that logs using the same logger configurations in this package.
func InfofNoCtx ¶
func InfofNoCtx(format string, args ...interface{})
InfofNoCtx logs a formatted message without context.
func IsLoggable ¶
Gets a value indicating whether logs at this level will be written to the logger. This is particularly useful to avoid computing log messages unnecessarily.
Types ¶
type Config ¶
type Config struct { // Determines whether to include source code location in logs. This might incurs a performance hit and is only // recommended on debug/development builds. IncludeSourceCode bool `json:"show-source" pflag:",Includes source code location in logs."` // Determines whether the logger should mute all logs (including panics) Mute bool `json:"mute" pflag:",Mutes all logs regardless of severity. Intended for benchmarks/tests only."` // Determines the minimum log level to log. Level Level `json:"level" pflag:",Sets the minimum logging level."` Formatter FormatterConfig `json:"formatter" pflag:",Sets logging format."` }
Global logger config.
type FormatterConfig ¶
type FormatterConfig struct {
Type FormatterType `json:"type" pflag:",Sets logging format type."`
}
type FormatterType ¶
type FormatterType = string
const ( FormatterJSON FormatterType = "json" FormatterText FormatterType = "text" FormatterGCP FormatterType = "gcp" )
type GcpEntry ¶
type GcpEntry struct { Data map[string]interface{} `json:"data,omitempty"` Message string `json:"message,omitempty"` Severity GcpSeverity `json:"severity,omitempty"` Timestamp string `json:"timestamp,omitempty"` }
type GcpFormatter ¶
type GcpFormatter struct { }
GcpFormatter Log formatter compatible with GCP stackdriver logging.
type GcpSeverity ¶
type GcpSeverity = string
const ( GcpSeverityDebug GcpSeverity = "DEBUG" GcpSeverityInfo GcpSeverity = "INFO" GcpSeverityWarning GcpSeverity = "WARNING" GcpSeverityError GcpSeverity = "ERROR" GcpSeverityCritical GcpSeverity = "CRITICAL" GcpSeverityAlert GcpSeverity = "ALERT" )
https://cloud.google.com/logging/docs/reference/v2/rest/v2/LogEntry#LogSeverity
type Level ¶
type Level = int
Level type.
const ( // PanicLevel level, highest level of severity. Logs and then calls panic with the // message passed to Debug, Info, ... PanicLevel Level = iota // FatalLevel level. Logs and then calls `os.Exit(1)`. It will exit even if the // logging level is set to Panic. FatalLevel // ErrorLevel level. Logs. Used for errors that should definitely be noted. // Commonly used for hooks to send errors to an error tracking service. ErrorLevel // WarnLevel level. Non-critical entries that deserve eyes. WarnLevel // InfoLevel level. General operational entries about what's going on inside the // application. InfoLevel // DebugLevel level. Usually only enabled when debugging. Very verbose logging. DebugLevel )
These are the different logging levels.
type NoopLogger ¶
type NoopLogger struct { }
func (NoopLogger) Debug ¶
func (NoopLogger) Debug(args ...interface{})
func (NoopLogger) Debugf ¶
func (NoopLogger) Debugf(format string, args ...interface{})
func (NoopLogger) Debugln ¶
func (NoopLogger) Debugln(args ...interface{})
func (NoopLogger) Error ¶
func (NoopLogger) Error(args ...interface{})
func (NoopLogger) Errorf ¶
func (NoopLogger) Errorf(format string, args ...interface{})
func (NoopLogger) Errorln ¶
func (NoopLogger) Errorln(args ...interface{})
func (NoopLogger) Fatal ¶
func (NoopLogger) Fatal(...interface{})
func (NoopLogger) Fatalf ¶
func (NoopLogger) Fatalf(string, ...interface{})
func (NoopLogger) Fatalln ¶
func (NoopLogger) Fatalln(...interface{})
func (NoopLogger) Info ¶
func (NoopLogger) Info(args ...interface{})
func (NoopLogger) Infof ¶
func (NoopLogger) Infof(format string, args ...interface{})
func (NoopLogger) Infoln ¶
func (NoopLogger) Infoln(args ...interface{})
func (NoopLogger) Panic ¶
func (NoopLogger) Panic(...interface{})
func (NoopLogger) Panicf ¶
func (NoopLogger) Panicf(string, ...interface{})
func (NoopLogger) Panicln ¶
func (NoopLogger) Panicln(...interface{})
func (NoopLogger) Print ¶
func (NoopLogger) Print(...interface{})
func (NoopLogger) Printf ¶
func (NoopLogger) Printf(string, ...interface{})
func (NoopLogger) Println ¶
func (NoopLogger) Println(...interface{})
func (NoopLogger) Warn ¶
func (NoopLogger) Warn(args ...interface{})
func (NoopLogger) Warnf ¶
func (NoopLogger) Warnf(format string, args ...interface{})
func (NoopLogger) Warning ¶
func (NoopLogger) Warning(args ...interface{})
func (NoopLogger) Warningf ¶
func (NoopLogger) Warningf(format string, args ...interface{})
func (NoopLogger) Warningln ¶
func (NoopLogger) Warningln(args ...interface{})
func (NoopLogger) Warnln ¶
func (NoopLogger) Warnln(args ...interface{})
func (NoopLogger) WithField ¶
func (NoopLogger) WithField(key string, value interface{}) *logrus.Entry
func (NoopLogger) WithFields ¶
func (NoopLogger) WithFields(fields logrus.Fields) *logrus.Entry