-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy patherror.go
112 lines (93 loc) · 1.37 KB
/
error.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
//
//
//
package main
import (
"fmt"
"os"
)
const (
E_PATH = 0
E_STATUS = 1
E_CRIT = 2
E_ERR = 3
E_WARNING = 4
E_NOTICE = 5
E_INFO = 6
E_DEBUG = 7
E_MAX = 8
E_WARN = 4
)
var eFile *os.File
var eCount [E_MAX]int
//
func eOpen() (err error) {
if len(oP.LogFile) == 0 {
eFile = os.Stdout
return
}
eFile, err = os.OpenFile(oP.LogFile, os.O_WRONLY|os.O_CREATE|os.O_APPEND, 0600)
return
}
//
func eClose() (err error) {
if eFile == os.Stdout {
return
}
eFile.Close()
return
}
//
func eMsg(l int, err error, f string, a ...interface{}) {
defer func() {
// if (l == E_CRIT) || (!oP.IgnoreError && (l == E_ERROR)) {
if l == E_CRIT {
os.Exit(1)
}
}()
eCount[l]++
if l > oP.LogLevel {
return
}
c := ""
switch l {
case E_PATH:
case E_STATUS:
case E_CRIT:
c = "C: "
case E_ERR:
c = "E: "
case E_WARNING:
c = "W: "
case E_NOTICE:
c = "N: "
case E_INFO:
c = "I: "
case E_DEBUG:
c = "D: "
}
if a == nil {
c += fmt.Sprintf(f)
} else {
c += fmt.Sprintf(f, a...)
}
if err != nil {
if len(f) != 0 {
c += fmt.Sprintf(": ")
}
c += fmt.Sprintf("%s", err)
}
fmt.Fprintln(eFile, c)
}
//
func eStatus() {
eMsg(E_DEBUG, nil,
"\nTotal Files:%d Crit:%d Err:%d Warn:%d Notice:%d Info:%d",
eCount[E_PATH],
eCount[E_CRIT],
eCount[E_ERR],
eCount[E_WARNING],
eCount[E_NOTICE],
eCount[E_INFO],
)
}