-
Notifications
You must be signed in to change notification settings - Fork 0
/
loggers.go
90 lines (74 loc) · 1.7 KB
/
loggers.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
package main
import (
"fmt"
"github.com/fatih/color"
"io"
"log"
"os"
)
var logFile io.Writer = nil
var debugTacticsLogFlag = false
var gameLogFlag = true
var fileLogFlag = true
var debugTacticsInMM = false
var debugTacticsLogFlagStored = false
var gameLogFlagStored = true
var fileLogFlagStored = true
var htmlLogFlag = false
var logFileName = "gameLog.txt"
func logToFile(format string, a ...interface{}) {
if fileLogFlag && logFile != nil {
fmt.Fprintf(logFile, format, a...)
}
}
func bidLog(format string, a ...interface{}) {
if gameLogFlag {
fmt.Printf(format, a...)
}
logToFile(format, a...)
}
func gameLog(format string, a ...interface{}) {
if gameLogFlag {
fmt.Printf(format, a...)
}
logToFile(format, a...)
}
func htmlLog(format string, a ...interface{}) {
if htmlLogFlag {
red := color.New(color.Bold, color.FgYellow).SprintFunc()
s := fmt.Sprintf(format, a...)
fmt.Printf(red(s))
}
}
func debugTacticsLog(format string, a ...interface{}) {
if debugTacticsLogFlag {
fmt.Printf(format, a...)
}
logToFile(format, a...)
}
var MINMAX_PREFIX = "MM: "
func debugMinmaxLog(format string, a ...interface{}) {
debugTacticsLog(MINMAX_PREFIX+format, a...)
}
func createFile(logFileName string) *os.File {
file, err := os.Create(logFileName)
if err != nil {
log.Fatal("Cannot create file", err)
}
return file
}
func disableLogs() {
debugTacticsLogFlagStored = debugTacticsLogFlag
gameLogFlagStored = gameLogFlag
fileLogFlagStored = fileLogFlag
if !debugTacticsInMM {
debugTacticsLogFlag = false
gameLogFlag = false
fileLogFlag = false
}
}
func restoreLogs() {
debugTacticsLogFlag = debugTacticsLogFlagStored
gameLogFlag = gameLogFlagStored
fileLogFlag = fileLogFlagStored
}