Documentation ¶
Index ¶
- func ModelFilePrefix(owner, name string) string
- func ModelLogFile(logDir, modelUUID, modelOwnerAndName string) string
- type BufferedLogWriter
- type Config
- type Labels
- type Level
- type LogRecord
- type LogWriter
- type LogWriterCloser
- type LogWriterForModelFunc
- type Logger
- type LoggerContext
- type ModelLogger
- type Tag
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ModelFilePrefix ¶
ModelFilePrefix makes a log file prefix from the model owner and name.
func ModelLogFile ¶
ModelLogFile makes an absolute model log file path.
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 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 LogWriterCloser ¶
LogWriterCloser is a Logger that can be closed.
type LogWriterForModelFunc ¶
type LogWriterForModelFunc func(modelUUID, modelName string) (LogWriterCloser, error)
LogWriterForModelFunc is a function which returns a log writer for a given model.
type Logger ¶
type Logger interface { // Critical logs a message at the critical level. Criticalf(msg string, args ...any) // Error logs a message at the error level. Errorf(msg string, args ...any) // Warning logs a message at the warning level. Warningf(msg string, args ...any) // Info logs a message at the info level. Infof(msg string, args ...any) // Debug logs a message at the debug level. Debugf(msg string, args ...any) // Trace logs a message at the trace level. Tracef(msg string, args ...any) // Log logs some information into the test error output. // The provided arguments are assembled together into a string with // fmt.Sprintf. Logf(level Level, 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 }
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 // AddWriter adds a writer to the list to be called for each logging call. // The name cannot be empty, and the writer cannot be nil. If an existing // writer exists with the specified name, an error is returned. // // Note: we're relying on loggo.Writer here, until we do model level logging. // Deprecated: This will be removed in the future and is only here whilst // we cut things across. AddWriter(name string, writer loggo.Writer) error }
LoggerContext is an interface that provides a method to get loggers.
type ModelLogger ¶
type ModelLogger interface { // Closer provides a Close() method which calls Close() on // each of the tracked log writers. io.Closer // GetLogWriter returns a log writer for the given model and keeps // track of it, returning the same one if called again. GetLogWriter(modelUUID, modelName, modelOwner string) (LogWriterCloser, error) // RemoveLogWriter stops tracking the given's model's log writer and // calls Close() on the log writer. RemoveLogWriter(modelUUID string) 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 ( // 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 delaing with ssh key importer. SSHIMPORTER Tag = "ssh-importer" )