-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
48 lines (41 loc) · 845 Bytes
/
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
package main
import (
"bufio"
"fmt"
"io"
"os"
"github.com/life4/logit/logit"
"github.com/spf13/pflag"
)
func run(args []string, stream io.Reader) error {
parser := pflag.NewFlagSet("logit", pflag.ContinueOnError)
var cpath string
parser.StringVarP(&cpath, "config", "c", "logit.toml", "path to the config file")
err := parser.Parse(args)
if err != nil {
if err == pflag.ErrHelp {
return nil
}
return fmt.Errorf("cli error: %v", err)
}
log, err := logit.ReadLogger(cpath)
if err != nil {
return fmt.Errorf("config error: %v", err)
}
scanner := bufio.NewScanner(stream)
for scanner.Scan() {
err = log.Log(log.SafeParse(scanner.Text()))
if err != nil {
fmt.Println(err)
}
}
log.Wait()
return nil
}
func main() {
err := run(os.Args[1:], os.Stdin)
if err != nil {
fmt.Println(err)
os.Exit(1)
}
}