-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathLogger.go
More file actions
52 lines (43 loc) · 983 Bytes
/
Logger.go
File metadata and controls
52 lines (43 loc) · 983 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
46
47
48
49
50
51
52
package main
import (
"fmt"
"os"
"github.com/sirupsen/logrus"
)
const logDir = "flight-logs/"
func init() {
if _, err := os.Stat(logDir); os.IsNotExist(err) {
os.Mkdir(logDir, os.ModeDir|0755)
}
file, err := os.OpenFile(logDir+"main.log", os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0666)
if err == nil {
logrus.SetOutput(file)
} else {
logrus.Info("Failed to log to file, using default stderr")
}
}
// LogFatalAndExitIfNotNull prints an logs and error and exits if err not null
func LogFatalAndExitIfNotNull(err error) {
if err != nil {
fmt.Println(err)
logrus.Fatal(err)
os.Exit(1)
}
}
// LogErrorIfNotNull prints and logs an error if err not null
func LogErrorIfNotNull(err error) {
if err != nil {
fmt.Println(err)
logrus.Error(err)
}
}
// LogWarning prints and logs a string
func LogWarning(str string) {
fmt.Println(str)
logrus.Warning(str)
}
// LogInfo prints and logs a string
func LogInfo(str string) {
fmt.Println(str)
logrus.Info(str)
}