Documentation
¶
Index ¶
Constants ¶
const (
ErrLoggerDying = errors.ConstError("logger worker is dying")
)
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BufferedLogWriter ¶
type BufferedLogWriter struct {
// contains filtered or unexported fields
}
BufferedLogWriter wraps a LogWriter, providing a buffer that accumulates log messages, flushing them to the underlying logger when enough messages have been accumulated. The emitted records are sorted by timestamp.
func NewBufferedLogWriter ¶
func NewBufferedLogWriter( l LogWriter, bufferSize int, flushInterval time.Duration, clock clock.Clock, ) *BufferedLogWriter
NewBufferedLogWriter returns a new BufferedLogWriter, wrapping the given Logger with a buffer of the specified size and flush interval.
func (*BufferedLogWriter) Flush ¶
func (b *BufferedLogWriter) Flush() error
Flush flushes any buffered log records to the underlying Logger.
func (*BufferedLogWriter) Log ¶
func (b *BufferedLogWriter) Log(in []LogRecord) error
Log is part of the Logger interface.
BufferedLogWriter's Log implementation will buffer log records up to the specified capacity and duration; after either of which is exceeded, the records will be flushed to the underlying logger.
type Level ¶
type Level uint32
Level represents the log level.
The severity levels. Higher values are more considered more important.
func ParseLevelFromString ¶
ParseLevelFromString returns the log level from the given string.
type LogRecord ¶
type LogRecord struct {
Time time.Time
// origin fields
ModelUUID string
Entity string
// logging-specific fields
Level Level
Module string
Location string
Message string
Labels map[string]string
}
LogRecord defines a single Juju log message as returned by LogTailer.
func (LogRecord) MarshalJSON ¶
func (*LogRecord) UnmarshalJSON ¶
type LogSink ¶
type LogSink interface {
LogWriter
}
LogSink provides a log sink that writes log messages to a file.
type LogWriter ¶
type LogWriter interface {
// Log writes the given log records to the logger's storage.
Log([]LogRecord) error
}
LogWriter provides an interface for writing log records.
type Logger ¶
type Logger interface {
// Criticalf logs a message at the critical level.
Criticalf(ctx context.Context, msg string, args ...any)
// Errorf logs a message at the error level.
Errorf(ctx context.Context, msg string, args ...any)
// Warningf logs a message at the warning level.
Warningf(ctx context.Context, msg string, args ...any)
// Infof logs a message at the info level.
Infof(ctx context.Context, msg string, args ...any)
// Debugf logs a message at the debug level.
Debugf(ctx context.Context, msg string, args ...any)
// Tracef logs a message at the trace level.
Tracef(ctx context.Context, msg string, args ...any)
// Logf logs information at the given level.
// The provided arguments are assembled together into a string with
// fmt.Sprintf.
Logf(ctx context.Context, level Level, labels Labels, format string, args ...any)
// IsLevelEnabled returns true if the given level is enabled for the logger.
IsLevelEnabled(Level) bool
// Child returns a new logger with the given name.
Child(name string, tags ...string) Logger
// GetChildByName returns a child logger with the given name.
GetChildByName(name string) Logger
// Helper marks the caller as a helper function.
Helper()
}
Logger is an interface that provides logging methods.
type LoggerContext ¶
type LoggerContext interface {
// GetLogger returns a logger with the given name and tags.
GetLogger(name string, tags ...string) Logger
// ConfigureLoggers configures loggers according to the given string
// specification, which specifies a set of modules and their associated
// logging levels. Loggers are colon- or semicolon-separated; each module is
// specified as <modulename>=<level>. White space outside of module names
// and levels is ignored. The root module is specified with the name
// "<root>".
//
// An example specification:
//
// <root>=ERROR; foo.bar=WARNING
//
// Label matching can be applied to the loggers by providing a set of labels
// to the function. If a logger has a label that matches the provided
// labels, then the logger will be configured with the provided level. If
// the logger does not have a label that matches the provided labels, then
// the logger will not be configured. No labels will configure all loggers
// in the specification.
ConfigureLoggers(specification string) error
// ResetLoggerLevels iterates through the known logging modules and sets the
// levels of all to UNSPECIFIED, except for <root> which is set to WARNING.
// If labels are provided, then only loggers that have the provided labels
// will be reset.
ResetLoggerLevels()
// Config returns the current configuration of the Loggers. Loggers
// with UNSPECIFIED level will not be included.
Config() Config
}
LoggerContext is an interface that provides a method to get loggers.
type LoggerContextGetter ¶
type LoggerContextGetter interface {
// GetLoggerContext returns a LoggerContext for the given name.
GetLoggerContext(ctx context.Context, modelUUID model.UUID) (LoggerContext, error)
}
LoggerContextGetter is an interface that is used to get a LoggerContext.
type LoggerKey ¶
type LoggerKey struct {
ModelUUID string
}
LoggerKey is a key used to identify a logger.
type ModelLogSinkGetter ¶
type ModelLogSinkGetter interface {
ModelLogger
LoggerContextGetter
}
ModelLogSinkGetter gets the ModelLogger or the LoggerContext for a given model.
type ModelLogger ¶
type ModelLogger interface {
// GetLogWriter returns a log writer for the given model and keeps
// track of it, returning the same one if called again.
GetLogWriter(ctx context.Context, modelUUID model.UUID) (LogWriter, error)
}
ModelLogger keeps track of all the log writers, which can be accessed by a given model uuid.
type Tag ¶
type Tag = string
Tag represents a common logger tag type.
const ( // API defines a common API tag to enable logging of all API connections and requests. API Tag = "api" // HTTP defines a common HTTP request tag. HTTP Tag = "http" // METRICS defines a common tag for dealing with metric output. This // should be used as a fallback for when prometheus isn't available. METRICS Tag = "metrics" // CHARMHUB defines a common tag for dealing with the charmhub client // and callers. CHARMHUB Tag = "charmhub" // CMR defines a common tag for dealing with cross model relations. CMR Tag = "cmr" // CMR_AUTH defines a common tag for dealing with cross model relations auth. CMR_AUTH Tag = "cmr-auth" // SECRETS defines a common tag for dealing with secrets. SECRETS Tag = "secrets" // WATCHERS defines a common tag for dealing with watchers. WATCHERS Tag = "watchers" // MIGRATION defines a common tag for dealing with migration. MIGRATION Tag = "migration" // OBJECTSTORE defines a common tag for dealing with objectstore. OBJECTSTORE Tag = "objectstore" // SSHIMPORTER defines a common tag for dealing with ssh key importer. SSHIMPORTER Tag = "ssh-importer" // STATUS_HISTORY defines a common tag for dealing with status history. STATUS_HISTORY Tag = "status-history" // MACAROON defines a common tag for dealing with macaroons. MACAROON Tag = "macaroon" // SIMPLESTREAM defines a common tag for dealing with simplestreams. SIMPLESTREAM Tag = "simplestreams" )
type TaggedRedirectWriter ¶
TaggedRedirectWriter is a log writer that conforms to a loggo.Writer, but actually writes to the log sink. This is a low process of removing the loggo backend dependency and replacing it with a generic log sink.
func NewTaggedRedirectWriter ¶
func NewTaggedRedirectWriter(logSink LogSink, tag string, modelUUID string) *TaggedRedirectWriter
NewTaggedRedirectWriter creates a new TaggedRedirectWriter with the given log sink, tag, and model UUID.
func (TaggedRedirectWriter) Write ¶
func (w TaggedRedirectWriter) Write(entry loggo.Entry)
Write writes the log entry to the log sink. It uses the loggo.Entry struct to extract the relevant information and create a LogRecord.