-
Notifications
You must be signed in to change notification settings - Fork 0
/
base.go
104 lines (86 loc) · 1.87 KB
/
base.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
package main
import (
"io"
"log"
)
const (
DMRoot = ".dm"
DMConfigFile = "config.ini"
DatasetFile = "datasets.ini"
GlobalIgnoreFile = "ignore.txt"
)
const GlobalIgnoreDefault = `
# Created by https://www.toptal.com/developers/gitignore/api/macos
# Edit at https://www.toptal.com/developers/gitignore?templates=macos
### macOS ###
# General
.DS_Store
.AppleDouble
.LSOverride
# Icon must end with two \r
Icon
# Thumbnails
._*
# Files that might appear in the root of a volume
.DocumentRevisions-V100
.fseventsd
.Spotlight-V100
.TemporaryItems
.Trashes
.VolumeIcon.icns
.com.apple.timemachine.donotpresent
# Directories potentially created on remote AFP share
.AppleDB
.AppleDesktop
Network Trash Folder
Temporary Items
.apdisk
### macOS Patch ###
# iCloud generated files
*.icloud
# End of https://www.toptal.com/developers/gitignore/api/macos
`
var (
DebugLogger *log.Logger
InfoLogger *log.Logger
WarnLogger *log.Logger
ErrorLogger *log.Logger
)
const (
LevelDebug = 40
LevelInfo = 30
LevelWarning = 20
LevelError = 10
LevelOff = 0
)
func initLoggers(loggerOut io.Writer, logLevel int) {
const logFlags int = log.Ldate | log.Ltime | log.Lshortfile
DebugLogger = log.New(loggerOut, "DEBUG: ", logFlags)
InfoLogger = log.New(loggerOut, "INFO: ", logFlags)
WarnLogger = log.New(loggerOut, "WARNING: ", logFlags)
ErrorLogger = log.New(loggerOut, "ERROR: ", logFlags)
if logLevel < LevelDebug {
DebugLogger.SetOutput(io.Discard)
}
if logLevel < LevelInfo {
InfoLogger.SetOutput(io.Discard)
}
if logLevel < LevelWarning {
WarnLogger.SetOutput(io.Discard)
}
if logLevel < LevelError {
ErrorLogger.SetOutput(io.Discard)
}
}
func checkError(e error) {
if e != nil {
ErrorLogger.Fatalln(e)
}
}
// Remove trailing slash if necessary
func removeTrailSlash(p string) string {
if p[len(p)-1] == '/' {
p = p[:len(p)-1]
}
return p
}