Documentation
¶
Index ¶
- func ContextWithLogger(ctx context.Context, logger *Logger) context.Context
- func ContextWithNewDefaultLogger(ctx context.Context) context.Context
- func JSONStreamer(r io.Reader, log *Logger, defaultLevel Level) error
- func LevelStrings() []string
- func ReplayLogs(ctx context.Context)
- func ScopeColor(scope string) string
- func SetCurrentLevel(l *Logger, level Level)
- func SetupDebugFileLogging(ctx context.Context, root string, maxLogs int)
- type Config
- type Entry
- type Interface
- type Level
- type Logger
- func (l Logger) AddSink(sink Sink) *Logger
- func (l Logger) Attrs(attributes map[string]string) *Logger
- func (l Logger) Changeset(changeset key.Changeset) *Logger
- func (l *Logger) Debugf(format string, args ...interface{})
- func (l Logger) Deployment(deployment key.Deployment) *Logger
- func (l *Logger) Errorf(err error, format string, args ...interface{})
- func (l Logger) GetLevel() Level
- func (l *Logger) Infof(format string, args ...interface{})
- func (l Logger) Level(level Level) *Logger
- func (l *Logger) Log(entry Entry)
- func (l *Logger) Logf(level Level, format string, args ...interface{})
- func (l Logger) Module(module string) *Logger
- func (l Logger) Scope(scope string) *Logger
- func (l *Logger) Tracef(format string, args ...interface{})
- func (l *Logger) Warnf(format string, args ...interface{})
- func (l *Logger) WriterAt(level Level) *io.PipeWriter
- type Sink
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ContextWithLogger ¶
func ContextWithLogger(ctx context.Context, logger *Logger) context.Context
ContextWithLogger returns a new context with the given logger attached. Use FromContext to retrieve it.
func ContextWithNewDefaultLogger ¶
func ContextWithNewDefaultLogger(ctx context.Context) context.Context
func JSONStreamer ¶
func JSONStreamer(r io.Reader, log *Logger, defaultLevel Level) error
JSONStreamer reads a stream of JSON log entries from r and logs them to log.
If a line of JSON is invalid an entry is created at the defaultLevel.
func LevelStrings ¶
func LevelStrings() []string
LevelStrings returns a slice of all String values of the enum
func ReplayLogs ¶ added in v0.458.0
func ReplayLogs(ctx context.Context)
ReplayLogs replays the debug logs to the delegate logger
func ScopeColor ¶
func ScopeColor(scope string) string
func SetCurrentLevel ¶ added in v0.457.0
func SetCurrentLevel(l *Logger, level Level)
SetCurrentLevel sets the current log level, it is a global operation, and will affect all contexts using this logger
func SetupDebugFileLogging ¶ added in v0.458.0
func SetupDebugFileLogging(ctx context.Context, root string, maxLogs int)
Types ¶
type Config ¶
type Config struct {
Level Level `help:"Log level." default:"info" env:"LOG_LEVEL"`
JSON bool `help:"Log in JSON format." env:"LOG_JSON"`
Timestamps bool `help:"Include timestamps in text logs." env:"LOG_TIMESTAMPS"`
Color bool `help:"Enable colored output regardless of TTY." env:"LOG_COLOR"`
}
Config for the logger.
type Entry ¶
type Entry struct {
Time time.Time `json:"-"`
Level Level `json:"level"`
Attributes map[string]string `json:"attributes,omitempty"`
Message string `json:"message"`
Error error `json:"-"`
}
type Interface ¶
type Interface interface {
Log(entry Entry)
Logf(level Level, format string, args ...interface{})
Tracef(format string, args ...interface{})
Debugf(format string, args ...interface{})
Infof(format string, args ...interface{})
Warnf(format string, args ...interface{})
// Errorf conditionally logs an error. If err is nil, nothing is logged.
Errorf(err error, format string, args ...interface{})
}
type Level ¶
type Level int
Level is the log level.
const (
// Default is a special value that means the log level will use a default.
Default Level = 0
Trace Level = 1
Debug Level = 5
Info Level = 9
Warn Level = 13
Error Level = 17
)
Log levels.
func LevelString ¶
func LevelString(s string) (Level, error)
LevelString retrieves an enum value from the enum constants string name. Throws an error if the param is not part of the enum.
func ParseLevel ¶
func ParseLevel(input string) (Level, error)
ParseLevel parses a log level from text.
func (Level) IsALevel ¶
func (i Level) IsALevel() bool
IsALevel returns "true" if the value is listed in the enum definition. "false" otherwise
func (Level) MarshalText ¶
func (i Level) MarshalText() ([]byte, error)
MarshalText implements the encoding.TextMarshaler interface for Level
func (Level) Severity ¶
func (l Level) Severity() int
Severity returns the open telemetry severity of the log level.
func (*Level) UnmarshalText ¶
func (i *Level) UnmarshalText(text []byte) error
UnmarshalText implements the encoding.TextUnmarshaler interface for Level
type Logger ¶
type Logger struct {
// contains filtered or unexported fields
}
Logger is the concrete logger.
func Configure ¶
func Configure(w io.Writer, cfg Config) *Logger
Configure returns a new logger based on the config.
func FromContext ¶
func FromContext(ctx context.Context) *Logger
FromContext retrieves the current logger from the context or panics
func (Logger) Attrs ¶
func (l Logger) Attrs(attributes map[string]string) *Logger
Attrs creates a new logger with the given attributes.
func (Logger) Changeset ¶ added in v0.464.0
func (l Logger) Changeset(changeset key.Changeset) *Logger
func (Logger) Deployment ¶ added in v0.462.0
func (l Logger) Deployment(deployment key.Deployment) *Logger