-
Notifications
You must be signed in to change notification settings - Fork 3
/
init.go
69 lines (62 loc) · 1.18 KB
/
init.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
package main
import (
"flag"
"io"
"io/ioutil"
"log"
"math/rand"
"os"
"regexp"
"time"
)
// nolint: gochecknoinits
func init() {
var err error
// command line flags
flag.StringVar(&cmdAddress, "address", "unix:/run/nginx-js-challenge.sock", `IP:PORT or Unix Socket path prefixd with "unix:"`)
flag.BoolVar(&cmdLogDateTime, "log-date-time", true, "add date/time to log output")
flag.BoolVar(&cmdDebug, "debug", false, "enable debug logging")
flag.Parse()
// seed random source
rand.Seed(time.Now().UTC().UnixNano())
// define custom log flags
var logFlag int
if cmdLogDateTime {
logFlag = log.Ldate | log.Ltime
} else {
logFlag = 0
}
// define debug log output
var debugWriter io.Writer
if cmdDebug {
debugWriter = os.Stdout
logFlag |= log.Lshortfile
} else {
debugWriter = ioutil.Discard
}
// initialize loggers
Info = log.New(
os.Stdout,
"INFO: ",
logFlag,
)
Error = log.New(
os.Stderr,
"ERROR: ",
logFlag,
)
Debug = log.New(
debugWriter,
"DEBUG: ",
logFlag,
)
Bot = log.New(
os.Stdout,
"BOT: ",
logFlag,
)
reUUID, err = regexp.Compile(regExpUUIDv4)
if err != nil {
Error.Fatalf("regexp compile error: %s\n", err.Error())
}
}