forked from prbinu/cert-scanner
-
Notifications
You must be signed in to change notification settings - Fork 0
/
logger.go
44 lines (36 loc) · 794 Bytes
/
logger.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
// Copyright (c) 2016, Yahoo Inc.
// Copyrights licensed under the New BSD License. See the
// accompanying LICENSE.txt file for terms.
package main
import (
"log"
"os"
)
const capacity = 32768
type Logger struct {
file string
fp *os.File
done chan bool
}
func NewLogger(fileName string, done chan bool) (l *Logger) {
if _, err := os.Stat(fileName); err == nil {
_ = os.Rename(fileName, fileName+".old")
}
fp, err := os.Create(fileName)
if err != nil {
// We should stop here
log.Fatal(err)
}
return &Logger{fileName, fp, done}
}
func (l *Logger) Process(record chan []byte) {
defer l.fp.Close()
for event := range record {
_, err := l.fp.Write(event)
if err != nil {
log.Println(err)
}
}
log.Println(l.file + ": exiting... log-done")
l.done <- true
}