format,colorful,level log and redirect escape log.
Recommended: [%D %T] [%L] (%S) %M
NO
Format
Details
Output Example
1
%T
Time
15:04:05 MST
2
%t
Time
15:04
3
%D
Date
2006/01/02
4
%d
Date
01/02/06
5
%L
Level
DEBUG,INFO,WARNING,ERROR
6
%S
Source
filename,lineno,funcname
7
%M
Message
output text
Level Define
NO
Level
Details
1
DEBUG
for debug output
2
INFO
for general output
3
WARN
for warnning output
4
ERROR
for error output
5
FATAL
for fatal output
Log Install
go get -u github.com/flyaways/log
Get started
package main
import (
"fmt""os""os/signal""github.com/flyaways/log"
)
funcinit() {
//Collector for escape ouputlog.Collector()
}
funcmain() {
op:=log.New(
log.LogConfig{
Level: log.INFO,
FirstRollover: true,
Blocking: false,
BufferLength: 10240,
PrefixName: "op.log",
When: log.Hour,
BackupCount: 72,
Format: log.OpFormat}, //log.AccessFormat
)
ifop==nil {
fmt.Fprintf(os.Stderr, "init logger error\n")
return
}
op.Debug("Go is an open source project developed by a team at Google and many contributors from the open source community.")
op.Info("Go is distributed under a BSD-style license.")
op.Warn("A low traffic mailing list for important announcements, such as new releases.")
op.Error("We encourage all Go users to subscribe to golang-announce.")
//op.Fatal("Go is an open source programming language that makes it easy to build simple, reliable, and efficient software.")signals:=make(chan os.Signal, 1)
signal.Notify(signals, os.Interrupt)
<-signals
}