forked from lcook/pulsar
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
66 lines (57 loc) · 1.25 KB
/
main.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
/*
* SPDX-License-Identifier: BSD-2-Clause
*
* Copyright (c) Lewis Cook <lcook@FreeBSD.org>
*/
package main
import (
"flag"
"fmt"
nested "github.com/antonfisher/nested-logrus-formatter"
"github.com/lcook/pulsar/internal/bot"
"github.com/lcook/pulsar/internal/version"
log "github.com/sirupsen/logrus"
)
func main() {
var (
cfgFile string
color bool
showVersion bool
verbosity int
)
flag.IntVar(&verbosity, "V", 1, "Log verbosity level (1-3)")
flag.StringVar(&cfgFile, "c", "config.json", "JSON configuration file path")
flag.BoolVar(&showVersion, "v", false, "Display pulsar version")
flag.BoolVar(&color, "d", false, "Disable color output in logs")
flag.Parse()
log.SetFormatter(&nested.Formatter{
ShowFullLevel: true,
TrimMessages: true,
TimestampFormat: "[02/Jan/2006:15:04:05]",
NoFieldsColors: true,
NoColors: color,
})
if showVersion {
fmt.Println(version.Build)
return
}
/*
* Clamp the verbosity with an lower bound of 1 and
* upper bound of 3 (1-3).
*/
if verbosity < 1 {
verbosity = 1
}
if verbosity > 3 {
verbosity = 3
}
switch verbosity {
case 1:
log.SetLevel(log.InfoLevel)
case 2:
log.SetLevel(log.DebugLevel)
case 3:
log.SetLevel(log.TraceLevel)
}
bot.Run(cfgFile)
}