Documentation
¶
Overview ¶
Package log is a simple and configurable Logging in Go, with level, formatters and writers.
It is completely API compatible with the standard library logger.
The simplest way to use log is simply the package-level exported logger:
package main
import ( "os" "github.com/subchen/go-log" ) func main() { log.Print("some message") log.Infof("$HOME = %v", os.Getenv("HOME")) log.Errorln("Got err:", os.ErrPermission) }
Output:
07:34:23.039 INFO some message 07:34:23.039 INFO $HOME = /home/subchen 07:34:23.039 ERROR Got err: permission denied
You also can config `log.Default` or new `log.Logger` to customize formatter and writer.
package main import ( "os" "github.com/subchen/go-log" "github.com/subchen/go-log/formatters" "github.com/subchen/go-log/writers" ) func main() { logger := &log.Logger{ Level: log.INFO, Formatter: new(formatters.TextFormatter), Out: &writers.FixedSizeFileWriter{ Name: "/tmp/test.log", MaxSize: 10 * 1024 * 1024, // 10m MaxCount: 10, }, } logger.Info("some message") }
Output log in `/tmp/test.log`:
2018-05-19T07:49:05.979+0000 INFO devbox main 9981 example/main.go:17 some message
For a full guide visit https://github.com/subchen/go-log
Index ¶
- Variables
- func Debug(obj ...interface{})
- func Debugf(msg string, args ...interface{})
- func Debugln(obj ...interface{})
- func Error(obj ...interface{})
- func Errorf(msg string, args ...interface{})
- func Errorln(obj ...interface{})
- func Fatal(obj ...interface{})
- func Fatalf(msg string, args ...interface{})
- func Fatalln(obj ...interface{})
- func Info(obj ...interface{})
- func Infof(msg string, args ...interface{})
- func Infoln(obj ...interface{})
- func IsDebugEnabled() bool
- func IsDisabled() bool
- func IsErrorEnabled() bool
- func IsFatalEnabled() bool
- func IsInfoEnabled() bool
- func IsPanicEnabled() bool
- func IsPrintEnabled() bool
- func IsWarnEnabled() bool
- func Panic(obj ...interface{})
- func Panicf(msg string, args ...interface{})
- func Panicln(obj ...interface{})
- func Print(obj ...interface{})
- func Printf(msg string, args ...interface{})
- func Println(obj ...interface{})
- func Warn(obj ...interface{})
- func Warnf(msg string, args ...interface{})
- func Warnln(obj ...interface{})
- type Formatter
- type Level
- type LogInterface
- type Logger
- func (l *Logger) Debug(obj ...interface{})
- func (l *Logger) Debugf(msg string, args ...interface{})
- func (l *Logger) Debugln(obj ...interface{})
- func (l *Logger) Error(obj ...interface{})
- func (l *Logger) Errorf(msg string, args ...interface{})
- func (l *Logger) Errorln(obj ...interface{})
- func (l *Logger) Fatal(obj ...interface{})
- func (l *Logger) Fatalf(msg string, args ...interface{})
- func (l *Logger) Fatalln(obj ...interface{})
- func (l *Logger) Info(obj ...interface{})
- func (l *Logger) Infof(msg string, args ...interface{})
- func (l *Logger) Infoln(obj ...interface{})
- func (l *Logger) IsDebugEnabled() bool
- func (l *Logger) IsDisabled() bool
- func (l *Logger) IsErrorEnabled() bool
- func (l *Logger) IsFatalEnabled() bool
- func (l *Logger) IsInfoEnabled() bool
- func (l *Logger) IsPanicEnabled() bool
- func (l *Logger) IsPrintEnabled() bool
- func (l *Logger) IsWarnEnabled() bool
- func (l *Logger) Panic(obj ...interface{})
- func (l *Logger) Panicf(msg string, args ...interface{})
- func (l *Logger) Panicln(obj ...interface{})
- func (l *Logger) Print(obj ...interface{})
- func (l *Logger) Printf(msg string, args ...interface{})
- func (l *Logger) Println(obj ...interface{})
- func (l *Logger) Warn(obj ...interface{})
- func (l *Logger) Warnf(msg string, args ...interface{})
- func (l *Logger) Warnln(obj ...interface{})
- type StdLog
Constants ¶
This section is empty.
Variables ¶
var Default = New()
Default is a default Logger instance
Exit is equals os.Exit
Functions ¶
func Debug ¶
func Debug(obj ...interface{})
Debug outputs message, Arguments are handled by fmt.Sprint
func Debugf ¶
func Debugf(msg string, args ...interface{})
Debugf outputs message, Arguments are handled by fmt.Sprintf
func Debugln ¶
func Debugln(obj ...interface{})
Debugln outputs message, Arguments are handled by fmt.Sprintln
func Error ¶
func Error(obj ...interface{})
Error outputs message, Arguments are handled by fmt.Sprint
func Errorf ¶
func Errorf(msg string, args ...interface{})
Errorf outputs message, Arguments are handled by fmt.Sprintf
func Errorln ¶
func Errorln(obj ...interface{})
Errorln outputs message, Arguments are handled by fmt.Sprintln
func Fatal ¶
func Fatal(obj ...interface{})
Fatal outputs message, and followed by a call to os.Exit(1) Arguments are handled by fmt.Sprint
func Fatalf ¶
func Fatalf(msg string, args ...interface{})
Fatalf outputs message and followed by a call to os.Exit(1), Arguments are handled by fmt.Sprintf
func Fatalln ¶
func Fatalln(obj ...interface{})
Fatalln outputs message and followed by a call to os.Exit(1), Arguments are handled by fmt.Sprintln
func Infof ¶
func Infof(msg string, args ...interface{})
Infof outputs message, Arguments are handled by fmt.Sprintf
func Infoln ¶
func Infoln(obj ...interface{})
Infoln outputs message, Arguments are handled by fmt.Sprintln
func Panic ¶
func Panic(obj ...interface{})
Panic outputs message, and followed by a call to panic() Arguments are handled by fmt.Sprint
func Panicf ¶
func Panicf(msg string, args ...interface{})
Panicf outputs message and followed by a call to panic(), Arguments are handled by fmt.Sprintf
func Panicln ¶
func Panicln(obj ...interface{})
Panicln outputs message and followed by a call to panic(), Arguments are handled by fmt.Sprintln
func Print ¶
func Print(obj ...interface{})
Print outputs message, Arguments are handled by fmt.Sprint
func Printf ¶
func Printf(msg string, args ...interface{})
Printf outputs message, Arguments are handled by fmt.Sprintf
func Println ¶
func Println(obj ...interface{})
Println outputs message, Arguments are handled by fmt.Sprintln
func Warnf ¶
func Warnf(msg string, args ...interface{})
Warnf outputs message, Arguments are handled by fmt.Sprintf
func Warnln ¶
func Warnln(obj ...interface{})
Warnln outputs message, Arguments are handled by fmt.Sprintln
Types ¶
type Formatter ¶
Formatter is a interface used to implement a custom Formatter
type Level ¶
type Level uint32
Level type
func ParseLevel ¶
ParseLevel takes a string level and returns the log level constant.
func (Level) ColorString ¶
ColorString converts the Level to a string with term colorful
type LogInterface ¶
type LogInterface interface { Debug(...interface{}) Info(...interface{}) Print(...interface{}) Warn(...interface{}) Error(...interface{}) Panic(...interface{}) Fatal(...interface{}) Debugln(...interface{}) Infoln(...interface{}) Println(...interface{}) Warnln(...interface{}) Errorln(...interface{}) Panicln(...interface{}) Fatalln(...interface{}) Debugf(string, ...interface{}) Infof(string, ...interface{}) Printf(string, ...interface{}) Warnf(string, ...interface{}) Errorf(string, ...interface{}) Panicf(string, ...interface{}) Fatalf(string, ...interface{}) }
LogInterface is interface for this logger
type Logger ¶
type Logger struct { Level Level Formatter Formatter Out io.Writer // contains filtered or unexported fields }
Logger is represents an active logging object
func (*Logger) Debug ¶
func (l *Logger) Debug(obj ...interface{})
Debug outputs message, Arguments are handled by fmt.Sprint
func (*Logger) Debugf ¶
Debugf outputs message, Arguments are handles by fmt.Sprintf
func (*Logger) Debugln ¶
func (l *Logger) Debugln(obj ...interface{})
Debugln outputs message, Arguments are handled by fmt.Sprintln
func (*Logger) Error ¶
func (l *Logger) Error(obj ...interface{})
Error outputs message, Arguments are handled by fmt.Sprint
func (*Logger) Errorf ¶
Errorf outputs message, Arguments are handles by fmt.Sprintf
func (*Logger) Errorln ¶
func (l *Logger) Errorln(obj ...interface{})
Errorln outputs message, Arguments are handled by fmt.Sprintln
func (*Logger) Fatal ¶
func (l *Logger) Fatal(obj ...interface{})
Fatal outputs message and followed by a call to os.Exit(1), Arguments are handled by fmt.Sprint
func (*Logger) Fatalf ¶
Fatalf outputs message and followed by a call to os.Exit(1), Arguments are handles by fmt.Sprintf
func (*Logger) Fatalln ¶
func (l *Logger) Fatalln(obj ...interface{})
Fatalln outputs message and followed by a call to os.Exit(1), Arguments are handled by fmt.Sprintln
func (*Logger) Info ¶
func (l *Logger) Info(obj ...interface{})
Info outputs message, Arguments are handled by fmt.Sprint
func (*Logger) Infof ¶
Infof outputs message, Arguments are handles by fmt.Sprintf
func (*Logger) Infoln ¶
func (l *Logger) Infoln(obj ...interface{})
Infoln outputs message, Arguments are handled by fmt.Sprintln
func (*Logger) IsDebugEnabled ¶
IsDebugEnabled indicates whether output message
func (*Logger) IsDisabled ¶
IsDisabled indicates whether output message
func (*Logger) IsErrorEnabled ¶
IsErrorEnabled indicates whether output message
func (*Logger) IsFatalEnabled ¶
IsFatalEnabled indicates whether output message
func (*Logger) IsInfoEnabled ¶
IsInfoEnabled indicates whether output message
func (*Logger) IsPanicEnabled ¶
IsPanicEnabled indicates whether output message
func (*Logger) IsPrintEnabled ¶
IsPrintEnabled indicates whether output message
func (*Logger) IsWarnEnabled ¶
IsWarnEnabled indicates whether output message
func (*Logger) Panic ¶
func (l *Logger) Panic(obj ...interface{})
Panic outputs message, and followed by a call to panic() Arguments are handled by fmt.Sprint
func (*Logger) Panicf ¶
Panicf outputs message and followed by a call to panic(), Arguments are handles by fmt.Sprintf
func (*Logger) Panicln ¶
func (l *Logger) Panicln(obj ...interface{})
Panicln outputs message and followed by a call to panic(), Arguments are handled by fmt.Sprintln
func (*Logger) Print ¶
func (l *Logger) Print(obj ...interface{})
Print outputs message, Arguments are handled by fmt.Sprint
func (*Logger) Printf ¶
Printf outputs message, Arguments are handles by fmt.Sprintf
func (*Logger) Println ¶
func (l *Logger) Println(obj ...interface{})
Println outputs message, Arguments are handled by fmt.Sprintln
func (*Logger) Warn ¶
func (l *Logger) Warn(obj ...interface{})
Warn outputs message, Arguments are handled by fmt.Sprint
func (*Logger) Warnf ¶
Warnf outputs message, Arguments are handles by fmt.Sprintf
type StdLog ¶
type StdLog interface { Print(...interface{}) Printf(string, ...interface{}) Println(...interface{}) Fatal(...interface{}) Fatalf(string, ...interface{}) Fatalln(...interface{}) Panic(...interface{}) Panicf(string, ...interface{}) Panicln(...interface{}) }
StdLog is interface for builtin log