Documentation ¶
Overview ¶
Package log provides a leveled logger with structured logging support.
Index ¶
- Constants
- Variables
- func Debug(args ...any)
- func Debugf(format string, args ...any)
- func Debugln(args ...any)
- func Error(args ...any)
- func Errorf(format string, args ...any)
- func Errorln(args ...any)
- func Info(args ...any)
- func Infof(format string, args ...any)
- func Infoln(args ...any)
- func Print(args ...any)
- func Printf(args ...any)
- func Println(args ...any)
- func RemoveAllASCISeq(str string) string
- func ResetASCISeq(str string) string
- func SetOptions(opts ...Option)
- func Trace(args ...any)
- func Tracef(format string, args ...any)
- func Warn(args ...any)
- func Warnf(format string, args ...any)
- func Warnln(args ...any)
- type Entry
- type Fields
- type Formatter
- type Level
- type Levels
- type Logger
- type Option
Constants ¶
const ( CurDir = "." CurDirWithSeparator = CurDir + string(os.PathSeparator) )
Variables ¶
var AllLevels = Levels{ StderrLevel, StdoutLevel, ErrorLevel, WarnLevel, InfoLevel, DebugLevel, TraceLevel, }
AllLevels exposes all logging levels
Functions ¶
func Debugln ¶
func Debugln(args ...any)
Debugln logs a message at level Debug on the standard logger.
func Errorln ¶
func Errorln(args ...any)
Errorln logs a message at level Error on the standard logger.
func Println ¶
func Println(args ...any)
Println logs a message at level Info on the standard logger.
func RemoveAllASCISeq ¶ added in v0.67.5
RemoveAllASCISeq returns a string with all ASCII color characters removed.
func ResetASCISeq ¶ added in v0.67.5
ResetASCISeq returns a string with the ASCI color reset to the default one.
func SetOptions ¶ added in v0.67.5
func SetOptions(opts ...Option)
SetOptions sets the options for the standard logger.
func Trace ¶ added in v0.56.4
func Trace(args ...any)
Trace logs a message at level Trace on the standard logger.
Types ¶
type Fields ¶ added in v0.67.5
type Fields map[string]interface{}
Fields is the type used to pass arguments to `WithFields`.
type Level ¶ added in v0.67.5
type Level uint32
Level type
const ( // StderrLevel level. Used to log error messages that we get from OpenTofu/Terraform stderr. StderrLevel Level = iota // StdoutLevel level. Used to log messages that we get from OpenTofu/Terraform stdout. StdoutLevel // ErrorLevel level. Logs. Used for errors that should definitely be noted. 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 // TraceLevel level. Designates finer-grained informational events than the Debug. TraceLevel )
These are the different logging levels.
func FromLogrusLevel ¶ added in v0.67.5
FromLogrusLevel converts `logrus.Level` to our `Level`.
func ParseLevel ¶ added in v0.67.5
ParseLevel takes a string and returns the Level constant.
func (Level) MarshalText ¶ added in v0.67.5
MarshalText implements encoding.MarshalText.
func (Level) ToLogrusLevel ¶ added in v0.67.5
ToLogrusLevel converts our `Level` to `logrus.Level`.
func (*Level) UnmarshalText ¶ added in v0.67.5
UnmarshalText implements encoding.TextUnmarshaler.
type Levels ¶ added in v0.67.5
type Levels []Level
Levels is a slice of `Level` type.
func (Levels) Contains ¶ added in v0.67.5
Contains returns true if the `Levels` list contains the given search `Level`.
func (Levels) ToLogrusLevels ¶ added in v0.67.5
ToLogrusLevels converts our `Levels` to `logrus.Levels`.
type Logger ¶
type Logger interface { // Clone creates a new Logger instance with a copy of the fields from the current one. Clone() Logger // SetOptions sets the given options to the instance. SetOptions(opts ...Option) // WithOptions clones and sets the given options for the new instance. // In other words, it is a combination of two methods, `log.Clone().SetOptions(...)`, but // unlike `SetOptions(...)`, it returns the instance, which is convenient for further actions. WithOptions(opts ...Option) Logger // WithField adds a single field to the Logger and returns partly cloning instance, the `Entry` structure. // This way the field is added to the returned instance only. WithField(key string, value any) Logger // WithFields adds a struct of fields to the Logger. All it does is call `WithField` for each `Field`. WithFields(fields Fields) Logger // WithError adds an error as single field to the Logger. The error is added to the returned instance only. WithError(err error) Logger // WithContext adds a context to the Logger. The context is added to the returned instance only. WithContext(ctx context.Context) Logger // WithTime overrides the time of the Logger. This only affects the returned instance. WithTime(t time.Time) Logger // Writer returns an io.Writer that writes to the Logger at the info log level. Writer() *io.PipeWriter // WriterLevel returns an io.Writer that writes to the Logger at the given log level. WriterLevel(level Level) *io.PipeWriter // Logf logs a message at the level given as parameter on the Logger. Logf(level Level, format string, args ...any) // Tracef logs a message at level Trace on the Logger. Tracef(format string, args ...any) // Debugf logs a message at level Debug on the Logger. Debugf(format string, args ...any) // Infof logs a message at level Info on the Logger. Infof(format string, args ...any) // Printf logs a message at level Info on the Logger. Printf(format string, args ...any) // Warnf logs a message at level Warn on the Logger. Warnf(format string, args ...any) // Errorf logs a message at level Error on the Logger. Errorf(format string, args ...any) // Log logs a message at the level given as parameter on the Logger. Log(level Level, args ...any) // Trace logs a message at level Trace on the Logger. Trace(args ...any) // Debug logs a message at level Debug on the Logger. Debug(args ...any) // Info logs a message at level Info on the Logger. Info(args ...any) // Print logs a message at level Info on the Logger. Print(args ...any) // Warn logs a message at level Warn on the Logger. Warn(args ...any) // Error logs a message at level Error on the Logger. Error(args ...any) // Logln logs a message at the level given as parameter on the Logger. Logln(level Level, args ...any) // Traceln logs a message at level Trace on the Logger. Traceln(args ...any) // Debugln logs a message at level Debug on the Logger. Debugln(args ...any) // Infoln logs a message at level Info on the Logger. Infoln(args ...any) // Println logs a message at level Info on the Logger. Println(args ...any) // Warnln logs a message at level Warn on the Logger. Warnln(args ...any) // Errorln logs a message at level Error on the Logger. Errorln(args ...any) }
Logger wraps the logrus package to have full control over implementing the required functionality, such as adding or removing log levels etc. This also provides developers with an easier way to clone and set parameters.
func Default ¶ added in v0.67.5
func Default() Logger
Default returns the standard logger used by the package-level output functions. Typically used as the default logger for various packages. It is highly recommended not to use it to avoid conflicts in tests.
func WithFields ¶ added in v0.67.5
WithFields adds a struct of fields to the logger. All it does is call `WithField` for each `Field`.
func WithOptions ¶ added in v0.67.5
WithOptions returns a new logger with the given options.
type Option ¶ added in v0.67.5
type Option func(logger *logger)
Option is a function to set options for logger.
func WithFormatter ¶ added in v0.67.5
WithFormatter sets the logger formatter.
func WithOutput ¶ added in v0.67.5
WithOutput sets the logger output.
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
Package format implements a custom format logs
|
Package format implements a custom format logs |
options
Package options represents a set of placeholders options.
|
Package options represents a set of placeholders options. |
placeholders
Package placeholders represents a set of placeholders for formatting various log values.
|
Package placeholders represents a set of placeholders for formatting various log values. |
Package writer provides a writer that redirects Write requests to configured logger and level.
|
Package writer provides a writer that redirects Write requests to configured logger and level. |