Skip to content

Commit 87f9756

Browse files
author
ffffwh
committed
set log level in plugin config #559
(cherry picked from commit fe75f1a)
1 parent 5bb62d2 commit 87f9756

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

drivers/mysql/driver.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ var (
6868
hclspec.NewLiteral(`15`)),
6969
"publish_metrics": hclspec.NewDefault(hclspec.NewAttr("publish_metrics", "bool", false),
7070
hclspec.NewLiteral(`false`)),
71+
"log_level": hclspec.NewDefault(hclspec.NewAttr("log_level", "string", false),
72+
hclspec.NewLiteral(`"Info"`)),
7173
})
7274

7375
// taskConfigSpec is the hcl specification for the driver config section of
@@ -306,6 +308,7 @@ type DriverConfig struct {
306308
DataDir string `codec:"data_dir"`
307309
StatsCollectionInterval int `codec:"stats_collection_interval"`
308310
PublishMetrics bool `codec:"publish_metrics"`
311+
LogLevel string `codec:"log_level"`
309312
}
310313

311314
func (d *Driver) SetConfig(c *base.Config) (err error) {
@@ -324,6 +327,13 @@ func (d *Driver) SetConfig(c *base.Config) (err error) {
324327
d.config = &dconfig
325328
d.logger.Info("SetConfig 2", "config", d.config)
326329

330+
logLevel := hclog.LevelFromString(d.config.LogLevel)
331+
if logLevel == hclog.NoLevel {
332+
return fmt.Errorf("invalid log level %v", d.config.LogLevel)
333+
}
334+
d.logger.SetLevel(logLevel)
335+
d.logger.Info("log level was set", "level", logLevel.String())
336+
327337
if d.config.ApiAddr != "" && d.config.NomadAddr == "" {
328338
return fmt.Errorf("nomad_addr cannot be empty when api_addr is set")
329339
}

0 commit comments

Comments
 (0)