添加日志模式
This commit is contained in:
parent
2707a8f0a9
commit
59bdf56c51
23
log.go
23
log.go
@ -3,8 +3,31 @@ package gost
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
|
"strings"
|
||||||
|
"os"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
//设置日志模式
|
||||||
|
func SetLogMode(LogMode string) {
|
||||||
|
if LogMode != "" {
|
||||||
|
var split []string = strings.Split(LogMode, ":")
|
||||||
|
if split[0] == "file" {
|
||||||
|
logFile, err := os.OpenFile(split[1], os.O_RDWR | os.O_CREATE | os.O_APPEND, 0770)
|
||||||
|
if err != nil {
|
||||||
|
panic(err.Error())
|
||||||
|
} else {
|
||||||
|
log.SetOutput(logFile)
|
||||||
|
}
|
||||||
|
//defer logFile.Close()
|
||||||
|
}
|
||||||
|
if split[0] == "shell" {
|
||||||
|
if split[1] == "stdout" {
|
||||||
|
log.SetOutput(os.Stdout)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
log.SetFlags(log.LstdFlags | log.Lshortfile)
|
log.SetFlags(log.LstdFlags | log.Lshortfile)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user