Skip to content

Commit e467be4

Browse files
committed
Add pbm-agent's flags and env vars for logger
That includes: - log-path - log-level - log-json
1 parent e7ce3dd commit e467be4

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

cmd/pbm-agent/main.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,20 @@ func main() {
4949
versionFormat = versionCmd.Flag("format", "Output format <json or \"\">").
5050
Default("").
5151
String()
52+
53+
logPath = pbmCmd.Flag("log-path", "Path to file").
54+
Envar("LOG_PATH").
55+
Default("/dev/stderr").
56+
String()
57+
logJSON = pbmCmd.Flag("log-json", "Enable JSON output").
58+
Envar("LOG_JSON").
59+
Bool()
60+
logLevel = pbmCmd.Flag(
61+
"log-level",
62+
"Minimal log level based on severity level: D, I, W, E or F, low to high. Choosing one includes higher levels too.").
63+
Envar("LOG_LEVEL").
64+
Default(log.D).
65+
Enum(log.D, log.I, log.W, log.E, log.F)
5266
)
5367

5468
cmd, err := pbmCmd.DefaultEnvars().Parse(os.Args[1:])
@@ -75,6 +89,11 @@ func main() {
7589
hidecreds()
7690

7791
fmt.Print(perconaSquadNotice)
92+
logOpts := &log.Opts{
93+
LogPath: *logPath,
94+
LogLevel: *logLevel,
95+
LogJSON: *logJSON,
96+
}
7897

7998
err = runAgent(url, *dumpConns)
8099
stdlog.Println("Exit:", err)

pbm/log/logger.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,14 @@ func New(cn *mongo.Collection, rs, node string) Logger {
3434
out: os.Stderr,
3535
rs: rs,
3636
node: node,
37+
38+
// Opts represents options that are specified by the user.
39+
type Opts struct {
40+
LogPath string
41+
LogJSON bool
42+
LogLevel string
43+
}
44+
3745
}
3846
}
3947

0 commit comments

Comments
 (0)