/
log.go
57 lines (45 loc) · 1 KB
/
log.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 config
import (
"fmt"
"os"
"github.com/jcelliott/lumber"
)
var (
Console *lumber.ConsoleLogger
Log *lumber.FileLogger
LogFile string
)
// init
func init() {
// set log file
LogFile = Root + "/nanobox.log"
// create a console logger
Console = lumber.NewConsoleLogger(lumber.INFO)
// create a file logger
if Log, err = lumber.NewAppendLogger(LogFile); err != nil {
Fatal("[config/log] lumber.NewAppendLogger() failed", err.Error())
}
}
// Debug
func Debug(msg string) {
if Verbose {
// let there be newlines
fmt.Println(msg)
}
}
// Error
func Error(msg, err string) {
fmt.Printf("%s (See %s for details)\n", msg, LogFile)
Log.Error(err)
}
// Fatal
func Fatal(msg, err string) {
fmt.Printf("A fatal error occurred (See %s for details). Exiting...\n", LogFile)
Log.Fatal(fmt.Sprintf("%s - %s", msg, err))
// add a mutex lock in so that if multiple errors are happening at the same
// time we dont try closing the log twice
mutex.Lock()
Log.Close()
os.Exit(1)
}