diff --git a/jobs/bosh-dns-windows/spec b/jobs/bosh-dns-windows/spec index 86985824c..2b71a3504 100644 --- a/jobs/bosh-dns-windows/spec +++ b/jobs/bosh-dns-windows/spec @@ -167,7 +167,10 @@ properties: logging.format.timestamp: description: "Format for the timestamp in the component logs. Valid values are 'rfc3339' and 'deprecated'." default: "rfc3339" - + + logging.tags: + description: "Provide logging configuration for log tags to overwrite the default logger behavior (e.g log_level property)" + post_start.timeout: description: "Number of seconds to attempt to retry Resolve-DnsName before timing out the post-start script" default: 60 diff --git a/jobs/bosh-dns/spec b/jobs/bosh-dns/spec index a9e0abcba..404a4fc08 100644 --- a/jobs/bosh-dns/spec +++ b/jobs/bosh-dns/spec @@ -174,3 +174,6 @@ properties: logging.format.timestamp: description: "Format for the timestamp in the component logs. Valid values are 'rfc3339' and 'deprecated'." default: "rfc3339" + + logging.tags: + description: "Provide logging configuration for log tags to overwrite the default logger behavior (e.g log_level property)" diff --git a/jobs/bosh-dns/templates/config.json.erb b/jobs/bosh-dns/templates/config.json.erb index eef010c52..85c2582da 100644 --- a/jobs/bosh-dns/templates/config.json.erb +++ b/jobs/bosh-dns/templates/config.json.erb @@ -46,7 +46,8 @@ logging: { format: { timestamp: p('logging.format.timestamp') - } + }, + tags: p('logging.tags') } }.to_json %> diff --git a/src/bosh-dns/dns/config/config.go b/src/bosh-dns/dns/config/config.go index e91edd2a3..4f9150a33 100644 --- a/src/bosh-dns/dns/config/config.go +++ b/src/bosh-dns/dns/config/config.go @@ -54,6 +54,22 @@ func (c Config) GetLogLevel() (boshlog.LogLevel, error) { return level, nil } +func (c Config) GetLoggingTags() []boshlog.LogTag { + var tags []boshlog.LogTag + + for _, logTag := range c.Logging.Tags { + loggerLevelValue, err := boshlog.Levelify(logTag.LogLevel) + if err != nil { + continue + } + tags = append(tags, boshlog.LogTag{ + Name: logTag.Name, + LogLevel: loggerLevelValue, + }) + } + return tags +} + func (c Config) UseRFC3339Formatting() bool { return strings.EqualFold(c.Logging.Format.TimeStamp, RFCFormatting) } @@ -91,8 +107,14 @@ type InternalUpcheckDomain struct { DNSQuery string `json:"dns_query"` } +type LogTag struct { + Name string `json:"name"` + LogLevel string `json:"log_level"` +} + type LoggingConfig struct { Format FormatConfig `json:"format,omitempty"` + Tags []LogTag `json:"tags,omitempty"` } type FormatConfig struct { diff --git a/src/bosh-dns/dns/config/config_test.go b/src/bosh-dns/dns/config/config_test.go index 83371fd6b..0aedfbeb3 100644 --- a/src/bosh-dns/dns/config/config_test.go +++ b/src/bosh-dns/dns/config/config_test.go @@ -390,6 +390,20 @@ var _ = Describe("Config", func() { }) }) + Context("LoggingTags", func() { + It("returns levelified logging tags", func() { + configFilePath := writeConfigFile(`{"address": "127.0.0.1", "port": 53, "logging":{"tags": [ + {"name": "ForwardHandler", "log_level": "DEBUG"}, {"name": "TEST", "log_level": "INVALID"}, + {"name": "main", "log_level": "ERROR"}]}}`) + + dnsConfig, err := config.LoadFromFile(configFilePath) + Expect(err).ToNot(HaveOccurred()) + + Expect(dnsConfig.GetLoggingTags()).To(Equal( + []boshlog.LogTag{{Name: "ForwardHandler", LogLevel: 0}, {Name: "main", LogLevel: 3}})) + }) + }) + Context("AppendDefaultDNSPortIfMissing", func() { It("allows multiple recursors to be configured with default port of 53", func() { recursors, err := config.AppendDefaultDNSPortIfMissing([]string{"8.8.8.8", "10.244.4.4:9700", "2001:db8::1", "[2001:db8::1]:1234"}) diff --git a/src/bosh-dns/dns/main.go b/src/bosh-dns/dns/main.go index a0a438bf5..6e697cee0 100644 --- a/src/bosh-dns/dns/main.go +++ b/src/bosh-dns/dns/main.go @@ -78,6 +78,7 @@ func mainExitCode() int { if config.UseRFC3339Formatting() { logger.UseRFC3339Timestamps() } + logger.UseTags(config.GetLoggingTags()) logTag := "main" logger.Info(logTag, "bosh-dns starting") defer logger.FlushTimeout(5 * time.Second) //nolint:errcheck