Documentation ¶
Overview ¶
Package log provides functions for pretty print
Patterns of functions print:
* (?time) msg - Print(), Printf(), Println():
* (?time) [DBG] msg - Debug(), Debugf(), Debugln():
* (?time) [INF] msg - Info(), Infof(), Infoln():
* (?time) [WRN] warning - Warn(), Warnf(), Warnln():
* (?time) [ERR] (?file:line) error - Error(), Errorf(), Errorln():
* (?time) [FAT] (?file:line) error - Fatal(), Fatalf(), Fatalln():
Time pattern: MM.dd.yyyy hh:mm:ss (01.30.2018 05:5:59)
Index ¶
- Constants
- type Config
- func (c *Config) Build() *Logger
- func (c *Config) PrintColor(b bool) *Config
- func (c *Config) PrintErrorLine(b bool) *Config
- func (c *Config) PrintTime(b bool) *Config
- func (c *Config) SetLevel(lvl LogLevel) *Config
- func (c *Config) SetOutput(w io.Writer) *Config
- func (c *Config) SetPrefix(prefix string) *Config
- func (c *Config) SetTimeLayout(layout string) *Config
- type LogLevel
- type Logger
- func (l Logger) Debug(v ...interface{})
- func (l Logger) Debugf(format string, v ...interface{})
- func (l Logger) Error(v ...interface{})
- func (l Logger) Errorf(format string, v ...interface{})
- func (l Logger) Fatal(v ...interface{})
- func (l Logger) Fatalf(format string, v ...interface{})
- func (l Logger) Info(v ...interface{})
- func (l Logger) Infof(format string, v ...interface{})
- func (l Logger) Print(v ...interface{})
- func (l Logger) Printf(format string, v ...interface{})
- func (l Logger) SetPrefix(prefix string) *Logger
- func (l Logger) Warn(v ...interface{})
- func (l Logger) Warnf(format string, v ...interface{})
- func (l Logger) WithPrefix(prefix string) *Logger
- func (l *Logger) Write(b []byte)
- func (l *Logger) WriteString(s string)
Constants ¶
const ( LevelDebug = iota - 1 LevelInfo LevelWarn LevelError LevelFatal )
const (
DefaultTimeLayout = "01.02.2006 15:04:05"
)
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct {
// contains filtered or unexported fields
}
func NewDevConfig ¶
func NewDevConfig() *Config
func NewProdConfig ¶
func NewProdConfig() *Config
func (*Config) PrintColor ¶
PrintColor sets Config.printColor to b
func (*Config) PrintErrorLine ¶
PrintErrorLine sets Config.printErrorLine to b
func (*Config) SetTimeLayout ¶
SetTimeLayout changes Config.timeLayout Default Config.timeLayout is DefaultTimeLayout
type Logger ¶
type Logger struct {
// contains filtered or unexported fields
}
func NewDevLogger ¶
func NewDevLogger() *Logger
func NewProdLogger ¶
func NewProdLogger() *Logger
func (Logger) Debug ¶
func (l Logger) Debug(v ...interface{})
Debug prints debug message if Debug mode is on Output pattern: (?time) [DBG] (?custom prefix) msg
func (Logger) Debugf ¶
Debugf prints debug message if Debug mode is on. "\n" is added automatically Output pattern: (?time) [DBG] (?custom prefix) msg
func (Logger) Error ¶
func (l Logger) Error(v ...interface{})
Error prints error Output pattern: (?time) [ERR] (?file:line) (?custom prefix) error
func (Logger) Errorf ¶
Errorf prints error. "\n" is added automatically Output pattern: (?time) [ERR] (?file:line) (?custom prefix) error
func (Logger) Fatal ¶
func (l Logger) Fatal(v ...interface{})
Fatal prints error and call os.Exit(1) Output pattern: (?time) [FAT] (?file:line) (?custom prefix) error
func (Logger) Fatalf ¶
Fatalf prints error and call os.Exit(1). "\n" is added automatically Output pattern: (?time) [FAT] (?file:line) (?custom prefix) error
func (Logger) Info ¶
func (l Logger) Info(v ...interface{})
Info prints info message Output pattern: (?time) [INF] (?custom prefix) msg
func (Logger) Infof ¶
Infof prints info message. "\n" is added automatically Output pattern: (?time) [INF] (?custom prefix) msg
func (Logger) Print ¶
func (l Logger) Print(v ...interface{})
Print prints msg Output pattern: (?time) (?custom prefix) msg
func (Logger) Printf ¶
Printf prints msg."\n" is added automatically Output pattern: (?time) (?custom prefix) msg
func (Logger) Warn ¶
func (l Logger) Warn(v ...interface{})
Warn prints warning Output pattern: (?time) [WRN] (?custom prefix) warning
func (Logger) Warnf ¶
Warnf prints warning. "\n" is added automatically Output pattern: (?time) [WRN] (?custom prefix) warning
func (Logger) WithPrefix ¶
WithPrefix returns cloned Logger with added prefix (prefix + ": ").
Example:
- l.prefix == "[old prefix]: "
- l.WithPrefix("[new prefix]")
- l.prefix == "[old prefix]: [new prefix]: "
func (*Logger) WriteString ¶
WriteString writes the content of s