Documentation ¶
Overview ¶
Package logger basic and simple logger for application, it base the go embed `log` package. it's able to control output by log level, level order `all<debug<info<warn<error<none`.
Index ¶
- Constants
- Variables
- func Prefix(level Level) string
- type Config
- type Level
- type Logger
- func (l Logger) Buffer() *bytes.Buffer
- func (l Logger) DebugFunc(callback func() string)
- func (l Logger) Debugf(message string, args ...interface{})
- func (l Logger) ErrorFunc(callback func() string)
- func (l Logger) Errorf(message string, args ...interface{})
- func (l Logger) Format(prefix, message string, args ...interface{})
- func (l Logger) InfoFunc(callback func() string)
- func (l Logger) Infof(message string, args ...interface{})
- func (l Logger) Log() *log.Logger
- func (l Logger) WarnFunc(callback func() string)
- func (l Logger) Warnf(message string, args ...interface{})
Examples ¶
Constants ¶
View Source
const ( DriverStdout = "stdout" DriverFile = "file" DriverBuffer = "buffer" )
DriverStdout logging driver support builtin
Variables ¶
View Source
var DefaultConfig = Config{ Level: "warn", Driver: DriverStdout, }
Functions ¶
Types ¶
type Config ¶
type Config struct { Log *log.Logger Level string // driver list: stdout, file, buffer Driver string // when Driver is file it will be work OutputDir string }
Config builder logging configure.
type Logger ¶
type Logger struct { Level Level // contains filtered or unexported fields }
func NewLogger ¶
NewLogger build a simple logger user it.
Example ¶
lg := NewLogger(Config{Level: "error"}) lg.Debugf("it's a debug level message") lg.Warnf("it's a warn level message") lg.Errorf("it's a error level message")
Output: 10:19:38 [ERROR] it's a error level message
Click to show internal directories.
Click to hide internal directories.