Documentation ¶
Overview ¶
Package logawl is a package for custom logging needs
LogAwl extends the standard log library with support for log levels This is _different_ from the syslog package in the standard library because you do not define a file because awl is a cli utility it writes directly to std err.
Use the New() function to init logawl logger := logawl.New()
You can call specific logging levels from your new logger using
logger.Debug("Message to log") logger.Warning("Message to log") logger.Info("Message to log") logger.Error("Message to log")
You may also set the log level on the fly with
Logger.SetLevel(3)
This allows you to change the default level (Info) and prevent log messages from being posted at higher verbosity levels for example if
Logger.SetLevel(3)
is not called and you call
Logger.Debug()
this runs through
IsLevel(level)
to verify if the debug log should be sent to std.Err or not based on the current expected log level
Index ¶
- Variables
- type Level
- type Logger
- func (logger *Logger) Debug(in ...any)
- func (logger *Logger) Debugf(format string, in ...any)
- func (logger *Logger) Error(in ...any)
- func (logger *Logger) Errorf(format string, in ...any)
- func (logger *Logger) FormatHeader(buf *[]byte, t time.Time, line int, level Level) error
- func (logger *Logger) GetLevel() Level
- func (logger *Logger) Info(in ...any)
- func (logger *Logger) Infof(format string, in ...any)
- func (logger *Logger) IsLevel(level Level) bool
- func (logger *Logger) Printer(level Level, s string) error
- func (logger *Logger) Println(level Level, in ...any)
- func (logger *Logger) SetLevel(level Level)
- func (logger *Logger) UnMarshalLevel(lv Level) (string, error)
- func (logger *Logger) Warn(in ...any)
- func (logger *Logger) Warnf(format string, in ...any)
Constants ¶
This section is empty.
Variables ¶
var AllLevels = []Level{ ErrLevel, WarnLevel, InfoLevel, DebugLevel, }
AllLevels is an array of all valid log levels.
Functions ¶
This section is empty.
Types ¶
type Level ¶
type Level int32
Level is the logging level.
const ( // ErrLevel is the fatal (error) log level. ErrLevel Level = iota // WarnLevel is for warning logs. // // Example: when one setting implies another, when a request fails but is retried. WarnLevel // InfoLevel is for saying what is going on when. // This is essentially the "verbose" option. // // When in doubt, use info. InfoLevel // DebugLevel is for spewing debug structs/interfaces. DebugLevel )
type Logger ¶
type Logger struct { Out io.Writer Prefix string Mu sync.Mutex Level Level // contains filtered or unexported fields }
Logger is the overall logger.
func New ¶
func New() *Logger
New instantiates Logger
Level can be changed to one of the other log levels (ErrorLevel, WarnLevel, InfoLevel, DebugLevel).
func (*Logger) FormatHeader ¶
FormatHeader formats the log header as such <LogLevel> YYYY/MM/DD HH:MM:SS (local time) <the message to log>.
func (*Logger) Println ¶
Println takes any and prints it out to Logger -> Out (io.Writer (default is std.Err)).
func (*Logger) UnMarshalLevel ¶
UnMarshalLevel unmarshalls the int value of level for writing the header.