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 ¶ added in v0.2.8
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 ¶ added in v0.4.7
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 ¶ added in v0.4.7
type GcpFormatter struct { }
GcpFormatter Log formatter compatible with GCP stackdriver logging.
type GcpSeverity ¶ added in v0.4.7
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 ¶ added in v0.2.3
type NoopLogger struct { }
func (NoopLogger) Debug ¶ added in v0.2.3
func (NoopLogger) Debug(args ...interface{})
func (NoopLogger) Debugf ¶ added in v0.2.3
func (NoopLogger) Debugf(format string, args ...interface{})
func (NoopLogger) Debugln ¶ added in v0.2.3
func (NoopLogger) Debugln(args ...interface{})
func (NoopLogger) Error ¶ added in v0.2.3
func (NoopLogger) Error(args ...interface{})
func (NoopLogger) Errorf ¶ added in v0.2.3
func (NoopLogger) Errorf(format string, args ...interface{})
func (NoopLogger) Errorln ¶ added in v0.2.3
func (NoopLogger) Errorln(args ...interface{})
func (NoopLogger) Fatal ¶ added in v0.2.3
func (NoopLogger) Fatal(...interface{})
func (NoopLogger) Fatalf ¶ added in v0.2.3
func (NoopLogger) Fatalf(string, ...interface{})
func (NoopLogger) Fatalln ¶ added in v0.2.3
func (NoopLogger) Fatalln(...interface{})
func (NoopLogger) Info ¶ added in v0.2.3
func (NoopLogger) Info(args ...interface{})
func (NoopLogger) Infof ¶ added in v0.2.3
func (NoopLogger) Infof(format string, args ...interface{})
func (NoopLogger) Infoln ¶ added in v0.2.3
func (NoopLogger) Infoln(args ...interface{})
func (NoopLogger) Panic ¶ added in v0.2.3
func (NoopLogger) Panic(...interface{})
func (NoopLogger) Panicf ¶ added in v0.2.3
func (NoopLogger) Panicf(string, ...interface{})
func (NoopLogger) Panicln ¶ added in v0.2.3
func (NoopLogger) Panicln(...interface{})
func (NoopLogger) Print ¶ added in v0.2.3
func (NoopLogger) Print(...interface{})
func (NoopLogger) Printf ¶ added in v0.2.3
func (NoopLogger) Printf(string, ...interface{})
func (NoopLogger) Println ¶ added in v0.2.3
func (NoopLogger) Println(...interface{})
func (NoopLogger) Warn ¶ added in v0.2.3
func (NoopLogger) Warn(args ...interface{})
func (NoopLogger) Warnf ¶ added in v0.2.3
func (NoopLogger) Warnf(format string, args ...interface{})
func (NoopLogger) Warning ¶ added in v0.2.3
func (NoopLogger) Warning(args ...interface{})
func (NoopLogger) Warningf ¶ added in v0.2.3
func (NoopLogger) Warningf(format string, args ...interface{})
func (NoopLogger) Warningln ¶ added in v0.2.3
func (NoopLogger) Warningln(args ...interface{})
func (NoopLogger) Warnln ¶ added in v0.2.3
func (NoopLogger) Warnln(args ...interface{})
func (NoopLogger) WithField ¶ added in v0.2.3
func (NoopLogger) WithField(key string, value interface{}) *logrus.Entry
func (NoopLogger) WithFields ¶ added in v0.2.3
func (NoopLogger) WithFields(fields logrus.Fields) *logrus.Entry