New upstream version 0.6
Eric Dorland
3 years ago
14 | 14 |
|
15 | 15 |
type globals struct {
|
16 | 16 |
sync.Mutex
|
17 | |
logLevel Severity
|
18 | |
useSyslog *bool
|
19 | |
appName string
|
20 | |
syslogFacility string
|
21 | |
systemLogger *systemLogger
|
22 | |
fileName *string
|
23 | |
outFd *os.File
|
24 | |
lastMessage string
|
25 | |
lastOccurrence time.Time
|
26 | |
occurrences uint64
|
|
17 |
logLevel Severity
|
|
18 |
useSyslog *bool
|
|
19 |
truncateLogFile *bool
|
|
20 |
appName string
|
|
21 |
syslogFacility string
|
|
22 |
systemLogger *systemLogger
|
|
23 |
fileName *string
|
|
24 |
outFd *os.File
|
|
25 |
lastMessage string
|
|
26 |
lastOccurrence time.Time
|
|
27 |
occurrences uint64
|
27 | 28 |
}
|
28 | 29 |
|
29 | 30 |
var (
|
|
173 | 174 |
_globals.Unlock()
|
174 | 175 |
}
|
175 | 176 |
|
|
177 |
func TruncateLogFile(value bool) {
|
|
178 |
_globals.Lock()
|
|
179 |
_globals.truncateLogFile = &value
|
|
180 |
_globals.Unlock()
|
|
181 |
}
|
|
182 |
|
176 | 183 |
func UseLogFile(fileName string) {
|
177 | 184 |
_globals.Lock()
|
178 | 185 |
_globals.fileName = &fileName
|
179 | 186 |
_globals.Unlock()
|
180 | 187 |
}
|
181 | 188 |
|
182 | |
func GetFileDescriptor() (*os.File) {
|
|
189 |
func GetFileDescriptor() *os.File {
|
183 | 190 |
_globals.Lock()
|
184 | 191 |
createFileDescriptor()
|
185 | 192 |
_globals.Unlock()
|
|
194 | 201 |
|
195 | 202 |
func createFileDescriptor() {
|
196 | 203 |
if _globals.fileName != nil && len(*_globals.fileName) > 0 && _globals.outFd == nil {
|
197 | |
outFd, err := os.OpenFile(*_globals.fileName, os.O_WRONLY|os.O_APPEND|os.O_CREATE, 0644)
|
|
204 |
mode := os.O_WRONLY | os.O_CREATE
|
|
205 |
if _globals.truncateLogFile != nil && *_globals.truncateLogFile {
|
|
206 |
mode |= os.O_TRUNC
|
|
207 |
} else {
|
|
208 |
mode |= os.O_APPEND
|
|
209 |
}
|
|
210 |
outFd, err := os.OpenFile(*_globals.fileName, mode, 0644)
|
198 | 211 |
if err == nil {
|
199 | 212 |
_globals.outFd = outFd
|
200 | 213 |
}
|
3 | 3 |
|
4 | 4 |
require (
|
5 | 5 |
github.com/hashicorp/go-syslog v1.0.0
|
6 | |
golang.org/x/sys v0.0.0-20190909082730-f460065e899a
|
|
6 |
golang.org/x/sys v0.0.0-20200602225109-6fdc65e7d980
|
7 | 7 |
)
|
0 | 0 |
github.com/hashicorp/go-syslog v1.0.0 h1:KaodqZuhUoZereWVIYmpUgZysurB1kBLX2j0MwMrUAE=
|
1 | 1 |
github.com/hashicorp/go-syslog v1.0.0/go.mod h1:qPfqrKkXGihmCqbJM2mZgkZGvKG1dFdvsLplgctolz4=
|
2 | |
golang.org/x/sys v0.0.0-20190909082730-f460065e899a h1:mIzbOulag9/gXacgxKlFVwpCOWSfBT3/pDyyCwGA9as=
|
3 | |
golang.org/x/sys v0.0.0-20190909082730-f460065e899a/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
|
2 |
golang.org/x/sys v0.0.0-20200602225109-6fdc65e7d980 h1:OjiUf46hAmXblsZdnoSXsEUSKU8r1UEzcL5RVZ4gO9Y=
|
|
3 |
golang.org/x/sys v0.0.0-20200602225109-6fdc65e7d980/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|