This repository has been archived by the owner on Sep 20, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 11
/
main.go
64 lines (50 loc) · 1.64 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
// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
// or more contributor license agreements. Licensed under the Elastic License;
// you may not use this file except in compliance with the Elastic License.
package main
import (
"flag"
"fmt"
"log"
"github.com/spf13/cobra"
"github.com/elastic/elastic-agent-inputs/inputs/loadgenerator"
"github.com/elastic/elastic-agent-inputs/pkg/config"
"github.com/elastic/elastic-agent-libs/logp"
)
type logWriter struct {
l *logp.Logger
}
func (l logWriter) Write(p []byte) (n int, err error) {
l.l.Info(string(p))
return len(p), nil
}
func main() {
// Initialise the logger as early as possible
logConfig := logp.DefaultConfig(logp.DefaultEnvironment)
logConfig.Beat = "agent-inputs"
logConfig.ToStderr = true
logConfig.ToFiles = false
if err := logp.Configure(logConfig); err != nil {
panic(fmt.Errorf("could not initialise logger: %w", err))
}
logger := logp.L()
// Sets the output destination for the standard logger, if any package uses
// the std lib logger, we get a nice JSON output
log.SetOutput(logWriter{logger})
rootCmd := &cobra.Command{
Use: "agent-inputs",
}
rootCmd.PersistentFlags().AddGoFlag(flag.CommandLine.Lookup("path.config"))
rootCmd.PersistentFlags().AddGoFlag(flag.CommandLine.Lookup("c"))
cfg, err := config.ReadConfig()
if err != nil {
logger.Fatalf("could not read config file: %s", err)
}
if err := logp.Configure(cfg.Log); err != nil {
logger.Fatalf("applying logger configuration: %v", err)
}
rootCmd.AddCommand(loadgenerator.Command(logger, cfg.LoadGenerator))
if err := rootCmd.Execute(); err != nil {
logger.Fatal(err)
}
}