-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
57 lines (52 loc) · 1014 Bytes
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package main
import (
log "github.com/sirupsen/logrus"
"gopkg.in/natefinch/lumberjack.v2"
"io"
"os"
"os/signal"
"path/filepath"
"syscall"
)
// SysDir 系统目录
const (
logDir = "log/"
logFilePath = logDir + "server.log"
)
func init() {
logInit()
}
func main() {
stopCh := make(chan os.Signal, 1)
signal.Notify(stopCh, os.Interrupt, os.Kill, syscall.SIGTERM, syscall.SIGQUIT)
go func() {
<-stopCh
GracefulStop()
os.Exit(0)
}()
if err := Start(); err != nil {
log.Fatal(err)
}
}
func logInit() {
log.SetLevel(log.InfoLevel)
log.SetReportCaller(true)
log.SetFormatter(&log.TextFormatter{
TimestampFormat: "2006-01-02 15:04:05",
FullTimestamp: true,
})
cwd, err := os.Getwd()
if err != nil {
log.Fatalln("get pwd err: :", err)
return
}
logWriter := io.MultiWriter(
os.Stdout,
&lumberjack.Logger{
Filename: filepath.Join(cwd, logFilePath),
MaxSize: 10, // MB
MaxAge: 2, //days
})
log.SetOutput(logWriter)
log.Infoln("log 初始化完毕")
}