-
Notifications
You must be signed in to change notification settings - Fork 3
/
logging.go
43 lines (40 loc) · 957 Bytes
/
logging.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
package core
import (
"log"
"os"
"github.com/hashicorp/go-hclog"
"github.com/hexbotio/hex/models"
)
func Logging(config *models.Config) {
logOptions := hclog.LoggerOptions{
Name: "hex",
Level: hclog.Info,
}
if config.Quiet {
logOptions.Level = hclog.Error
}
if config.Debug {
logOptions.Level = hclog.Debug
}
if config.Trace {
logOptions.Level = hclog.Trace
}
if config.LogFile != "" {
if !FileExists(config.LogFile) {
nf, err := os.Create(config.LogFile)
if err != nil {
log.Fatal("ERROR: Cannot create log file at "+config.LogFile, err)
}
nf.Close()
}
f, err := os.OpenFile(config.LogFile, os.O_RDWR|os.O_APPEND, 0660)
if err != nil {
log.Fatal("ERROR: Cannot get to log file at "+config.LogFile, err)
}
logOptions.Output = f
}
config.Logger = hclog.New(&logOptions)
config.Logger.Info(". . .")
config.Logger.Info("Starting HexBot " + config.Version)
config.Logger.Info("http://hexbot.io")
}