-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathmain.go
57 lines (46 loc) · 1.22 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
package main
import (
"embed"
"flag"
"github.com/cskr/pubsub"
"github.com/sirupsen/logrus"
"github.com/spf13/viper"
"os"
)
var (
// use go embed to package up the webServerFiles
//go:embed web/dist
webServerFiles embed.FS
// use go embed to serve up the defaultConfigFile
//go:embed logstation.default.conf
defaultConfigFile []byte
// define a logger
logger = logrus.New()
)
func main() {
// set the logger to output to stdout
logger.SetOutput(os.Stdout)
// process config file
configFilePtr := flag.String("c", "logstation.conf", "path to config file")
flag.Parse()
HandleConfigFile(*configFilePtr)
// preprocess all the regex patterns
patterns := ParseRegexPatterns()
// setup message broker
pubSub := pubsub.New(1)
// collect settings for tailingMethod
tailingMethod := viper.GetString("tailingMethod")
polling := false
if tailingMethod == "polling" {
polling = true
}
pollingTimeMS := viper.GetInt("pollingTimeMS")
// process all log files to watch
logFiles := viper.GetStringSlice("logs")
for _, logFile := range logFiles {
//begin watching the file in a goroutine for concurrency
go Follow(logFile, pubSub, patterns, polling, pollingTimeMS)
}
// startup the web server
StartWebServer(pubSub)
}