forked from grafana/loki
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
74 lines (60 loc) · 2.02 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
67
68
69
70
71
72
73
74
package main
import (
"flag"
"fmt"
"os"
"reflect"
"k8s.io/klog"
"github.com/cortexproject/cortex/pkg/util"
"github.com/go-kit/kit/log/level"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/common/version"
"github.com/weaveworks/common/logging"
_ "github.com/grafana/loki/pkg/build"
"github.com/grafana/loki/pkg/cfg"
"github.com/grafana/loki/pkg/logentry/stages"
"github.com/grafana/loki/pkg/promtail"
"github.com/grafana/loki/pkg/promtail/config"
)
func init() {
prometheus.MustRegister(version.NewCollector("promtail"))
}
func main() {
printVersion := flag.Bool("version", false, "Print this builds version information")
dryRun := flag.Bool("dry-run", false, "Start Promtail but print entries instead of sending them to Loki.")
// Load config, merging config file and CLI flags
var config config.Config
if err := cfg.Parse(&config); err != nil {
fmt.Println("Unable to parse config:", err)
os.Exit(1)
}
// Handle -version CLI flag
if *printVersion {
fmt.Println(version.Print("promtail"))
os.Exit(0)
}
// Init the logger which will honor the log level set in cfg.Server
if reflect.DeepEqual(&config.ServerConfig.Config.LogLevel, &logging.Level{}) {
fmt.Println("Invalid log level")
os.Exit(1)
}
util.InitLogger(&config.ServerConfig.Config)
// Use Stderr instead of files for the klog.
klog.SetOutput(os.Stderr)
// Set the global debug variable in the stages package which is used to conditionally log
// debug messages which otherwise cause huge allocations processing log lines for log messages never printed
if config.ServerConfig.Config.LogLevel.String() == "debug" {
stages.Debug = true
}
p, err := promtail.New(config, *dryRun)
if err != nil {
level.Error(util.Logger).Log("msg", "error creating promtail", "error", err)
os.Exit(1)
}
level.Info(util.Logger).Log("msg", "Starting Promtail", "version", version.Info())
defer p.Shutdown()
if err := p.Run(); err != nil {
level.Error(util.Logger).Log("msg", "error starting promtail", "error", err)
os.Exit(1)
}
}