Documentation
¶
Overview ¶
Package logolang is a simple and thread-safe library for logging operations.
It consists in a Logger object where you can configure a writer for each log level. There are 5 of those levels:
- 0: no log
- 1: critical
- 2: error
- 3: info
- 4: debug
Index ¶
- Constants
- type Logger
- func (l *Logger) Critical(message string)
- func (l *Logger) Criticalf(format string, v ...interface{})
- func (l *Logger) Debug(message string)
- func (l *Logger) Debugf(format string, v ...interface{})
- func (l *Logger) Error(message string)
- func (l *Logger) Errorf(format string, v ...interface{})
- func (l *Logger) Info(message string)
- func (l *Logger) Infof(format string, v ...interface{})
- func (l *Logger) SetFormat(format string)
- func (l *Logger) SetLevel(level int) error
Constants ¶
const ( // Logger levels LevelNoLog = iota LevelCritical LevelError LevelInfo LevelDebug )
const (
// Default format for logolang
DefaultFormat = "[%YYYY%-%MM%-%DD% %hh%:%mm%:%ss%] %LEVEL%: %MESSAGE%"
)
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Logger ¶
type Logger struct {
// contains filtered or unexported fields
}
Logger is the type used by logolang to perform logging operations. It have 4 writers, one for each logging level except 0 (no log). Every logging operation results in panic if there's an error when writing to one of those interfaces.
func NewLogger ¶
NewLogger creates a new Logger object. It will write the log in the writers provided. If one of the writers is set to nil, it will be set to its default value.
Default values:
- debug: os.Stdout
- info: os.Stdout
- error: os.Stderr
- critical: os.Stderr
func (*Logger) Critical ¶
Critical logs a critical message in the critical interface when logger level >= LevelCritical.
func (*Logger) Criticalf ¶
Criticalf logs a critical message in the critical interface when logger level >= LevelCritical. Arguments are handled in the manner of fmt.Printf.
func (*Logger) Debug ¶
Debug logs a debug message in the debug interface when logger level >= LevelDebug.
func (*Logger) Debugf ¶
Debug logs a debug message in the debug interface when logger level >= LevelDebug. Arguments are handled in the manner of fmt.Printf.
func (*Logger) Error ¶
Error logs an error message in the error interface when logger level >= LevelError.
func (*Logger) Errorf ¶
Error logs an error message in the error interface when logger level >= LevelError. Arguments are handled in the manner of fmt.Printf.
func (*Logger) Info ¶
Info logs an info message in the info interface when logger level >= LevelInfo.
func (*Logger) Infof ¶
Info logs an info message in the info interface when logger level >= LevelInfo. Arguments are handled in the manner of fmt.Printf.
func (*Logger) SetFormat ¶ added in v0.2.0
SetFormat let you set the format for the logger output. The format is defined by a string where the following sequences are given the following values:
%YYYY% = current year %MM% = current month %DD% = current day of the month %hh% = current hour %mm% = current minute %ss% = current second %ns% = current nanosecond %LEVEL% = level name (DEBUG, INFO, ERROR or CRITICAL) %MESSAGE% = message logged
The default format is:
DefaultFormat = "[%YYYY%-%MM%-%DD% %hh%:%mm%:%ss%] %LEVEL%: %MESSAGE%"
