-
Notifications
You must be signed in to change notification settings - Fork 15
/
logger.go
64 lines (56 loc) · 1.12 KB
/
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package main
import (
. "github.com/OrlovEvgeny/TinyJPG/config"
"fmt"
"log"
"os"
)
//
type LogVerbose struct {
ID int
ImagePath string
beforeSize int64
afterSize int64
}
//
type LoggerWorker struct {
ErrorLog string
InfoLog string
}
// process info-log writer
func (lw *LoggerWorker) processInfo() {
logfile, err := os.OpenFile(lw.InfoLog, os.O_WRONLY|os.O_CREATE, 0666)
if err != nil {
log.Fatal(err)
}
defer logfile.Close()
for {
textLog := <-LogInfoChannel
if Config.General.Verbose {
fmt.Println(textLog)
} else {
logfile.WriteString(textLog)
}
}
}
// process error-log writer
func (lw *LoggerWorker) processErr() {
logfile, err := os.OpenFile(lw.ErrorLog, os.O_WRONLY|os.O_CREATE, 0666)
if err != nil {
log.Fatal(err)
}
defer logfile.Close()
for {
textLog := <-LogErrChannel
if Config.General.Verbose {
fmt.Println(textLog)
} else {
logfile.WriteString(textLog)
}
}
}
//
func (v *LogVerbose) push() {
textLog := fmt.Sprintf("worker id: %d was compressed >> %s Before Size: %d, After size: %d \n", v.ID, v.ImagePath, v.beforeSize, v.afterSize)
LogInfoChannel <- textLog
}