-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathlog.go
More file actions
45 lines (40 loc) · 900 Bytes
/
log.go
File metadata and controls
45 lines (40 loc) · 900 Bytes
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
package main
import (
"encoding/json"
"fmt"
"os"
"github.com/astaxie/beego/logs"
)
type logconfig struct {
Filename string `json:"filename"`
Level int `json:"level"`
MaxLines int `json:"maxlines"`
MaxSize int `json:"maxsize"`
Daily bool `json:"daily"`
MaxDays int `json:"maxdays"`
Color bool `json:"color"`
}
var logCfg = logconfig{
Filename: os.Args[0],
Level: logs.LevelInformational,
Daily: true,
MaxSize: 10 * 1024 * 1024,
MaxLines: 100 * 1024,
MaxDays: 7,
Color: false,
}
func LogInit() error {
logCfg.Filename = fmt.Sprintf("%s%c%s", RunlogDirGet(), os.PathSeparator, "runlog.log")
value, err := json.Marshal(&logCfg)
if err != nil {
return err
}
err = logs.SetLogger(logs.AdapterFile, string(value))
if err != nil {
return err
}
logs.Async(100)
logs.EnableFuncCallDepth(true)
logs.SetLogFuncCallDepth(3)
return nil
}