-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtools.go
55 lines (47 loc) · 831 Bytes
/
tools.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
package syncer
import (
"fmt"
"time"
)
var LogLevel int
const DEFAULT_LOCK_TIMEOUT string = "30s"
const (
LOG_INFO = iota
LOG_WARNING
LOG_ERROR
)
func logger(level int, msgs ...interface{}) {
if level < LogLevel {
return
}
msgs = append([]interface{}{getPrefix(level)}, msgs...)
fmt.Println(msgs...)
}
func getPrefix(level int) string {
switch level {
case 0:
return "[INFO]"
case 1:
return "[WARNING]"
default:
return "[ERROR]"
}
}
func getLogLevel(level string) int {
switch level {
case "info":
return 0
case "warning":
return 1
default:
return 2
}
}
func getLockTimeoutDuration(timeout string) time.Duration {
locktimeout, err := time.ParseDuration(timeout)
if err != nil {
logger(LOG_ERROR, err)
locktimeout, _ = time.ParseDuration(DEFAULT_LOCK_TIMEOUT)
}
return locktimeout
}