forked from ezotrank/logsend
/
main.go
59 lines (51 loc) · 1.52 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
package main
import (
"flag"
"fmt"
"github.com/ezotrank/logsend/logsend"
logpkg "log"
"os"
"runtime"
)
var (
watchDir = flag.String("watch-dir", "./tmp", "log directories")
config = flag.String("config", "config.json", "path to config.json file")
check = flag.Bool("check", false, "check config.json")
debug = flag.Bool("debug", false, "turn on debug messages")
continueWatch = flag.Bool("continue-watch", false, "watching folder for new files")
logFile = flag.String("log", "", "log file")
dryRun = flag.Bool("dry-run", false, "not send data")
memprofile = flag.String("memprofile", "", "memory profiler")
maxprocs = flag.Int("maxprocs", 0, "max count of cpu")
)
func main() {
flag.Parse()
if *logFile != "" {
file, err := os.OpenFile(*logFile, os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0666)
if err != nil {
fmt.Errorf("Failed to open log file: %+v\n", err)
}
defer file.Close()
logsend.Conf.Logger = logpkg.New(file, "", logpkg.Ldate|logpkg.Ltime|logpkg.Lshortfile)
}
if *maxprocs <= 0 {
*maxprocs = runtime.NumCPU()
}
runtime.GOMAXPROCS(*maxprocs)
fmt.Printf("set GOMAXPROCS to %v\n", *maxprocs)
logsend.Conf.Debug = *debug
logsend.Conf.ContinueWatch = *continueWatch
logsend.Conf.WatchDir = *watchDir
logsend.Conf.Memprofile = *memprofile
logsend.Conf.DryRun = *dryRun
if *check {
_, err := logsend.LoadConfig(*config)
if err != nil {
fmt.Println(err)
os.Exit(1)
}
fmt.Println("ok")
os.Exit(0)
}
logsend.WatchFiles(*watchDir, *config)
}