-
Notifications
You must be signed in to change notification settings - Fork 2
/
gowatch.go
52 lines (43 loc) · 1.46 KB
/
gowatch.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
package main
import (
"code.google.com/p/getopt"
"fmt"
"github.com/fxnn/gowatch/config"
"github.com/fxnn/gowatch/mapper"
"github.com/fxnn/gowatch/parser"
"github.com/fxnn/gowatch/summary"
"log"
"strings"
)
func main() {
configFilePath := getopt.StringLong("config", 'c', "", "Path to configuration file", "/path/to/config.yml")
getopt.Parse()
if !getopt.Lookup("config").Seen() {
log.Fatal("No configuration file given. Specify one using `-c /path/to/config.yml`")
}
config := config.ReadConfigByFilename(*configFilePath)
multiplexer := summary.NewMultiplexer()
summarizerTitles := make([]string, len(config.Summary))
for i, summaryConfig := range config.Summary {
multiplexer.AddSummarizer(summaryConfig.CreateSummarizer())
if summaryConfig.Title != "" {
summarizerTitles[i] = summaryConfig.Title
} else {
summarizerTitles[i] = summaryConfig.Do
}
}
for _, logfile := range config.Logfiles {
linesource := parser.NewFileLineSource(logfile.Filename)
parser := logfile.CreateParser(linesource, logfile.Where.CreatePredicate())
entries := parser.Parse()
logfileMapper := mapper.NewConfigurationBasedMapper(logfile)
mappedEntries := logfileMapper.Map(entries)
multiplexer.SummarizeAsync(mappedEntries)
}
for i, summarizer := range multiplexer.Summarizers {
title := summarizerTitles[i]
fmt.Printf("%s\n", title)
fmt.Printf("%s\n", strings.Repeat("=", len(title)))
fmt.Printf("%s\n\n", summarizer.StringAfterSummarizeAsyncCompleted())
}
}