Documentation ¶
Overview ¶
Package log is a simple and configurable Logging in Go, with level, log and log.
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/fangdingjun/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/fangdingjun 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/fangdingjun/go-log" ) func main() { logger := &log.Logger{ Level: log.INFO, Formatter: new(log.TextFormatter), Out: &log.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/fangdingjun/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 FilelineCaller(skip int) (file string, line int)
- 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 IsTerminal(w io.Writer) 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 AlwaysNewFileWriter
- type DailyFileWriter
- type FixedSizeFileWriter
- type Formatter
- type Interface
- type JSONFormatter
- type Level
- 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
- type TextFormatter
Constants ¶
This section is empty.
Variables ¶
var Default = New()
Default is a default Logger instance
var Exit = os.Exit
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 FilelineCaller ¶
FilelineCaller returns file and line for caller
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 IsTerminal ¶
IsTerminal returns whether is a valid tty for io.Writer
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
Types ¶
type AlwaysNewFileWriter ¶
type AlwaysNewFileWriter struct { Name string MaxCount int // contains filtered or unexported fields }
AlwaysNewFileWriter create new log for every process
type DailyFileWriter ¶
DailyFileWriter create new log for every day
type FixedSizeFileWriter ¶
type FixedSizeFileWriter struct { Name string MaxSize int64 MaxCount int // contains filtered or unexported fields }
FixedSizeFileWriter create new log if log size exceed
type Interface ¶
type Interface 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{}) }
Interface is interface for this logger
type JSONFormatter ¶
type JSONFormatter struct { AppName string TimeFormat string // contains filtered or unexported fields }
JSONFormatter is a json 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 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) 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) 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) 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) 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
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
type TextFormatter ¶
type TextFormatter struct { AppName string TimeFormat string // contains filtered or unexported fields }
TextFormatter is a text line formatter