Skip to content

Commit

Permalink
Allow setting different log levels for log categories/tags
Browse files Browse the repository at this point in the history
  • Loading branch information
a-hassanin committed Dec 7, 2023
1 parent 2be616a commit 5c4ff27
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 2 deletions.
3 changes: 3 additions & 0 deletions jobs/bosh-dns/spec
Original file line number Diff line number Diff line change
Expand Up @@ -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.categories:
description: "Categories for logging to provide individual configuration to the logger."
3 changes: 2 additions & 1 deletion jobs/bosh-dns/templates/config.json.erb
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@
logging: {
format: {
timestamp: p('logging.format.timestamp')
}
},
categories: p('logging.categories')
}
}.to_json
%>
24 changes: 23 additions & 1 deletion src/bosh-dns/dns/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,22 @@ func (c Config) GetLogLevel() (boshlog.LogLevel, error) {
return level, nil
}

func (c Config) GetLogCategories() []boshlog.LogCategory {
var categories []boshlog.LogCategory

for _, category := range c.Logging.Categories {
loggerLevelValue, err := boshlog.Levelify(category.LogLevel)
if err != nil {
continue
}
categories = append(categories, boshlog.LogCategory{
Name: category.Name,
LogLevel: loggerLevelValue,
})
}
return categories
}

func (c Config) UseRFC3339Formatting() bool {
return strings.EqualFold(c.Logging.Format.TimeStamp, RFCFormatting)
}
Expand Down Expand Up @@ -91,8 +107,14 @@ type InternalUpcheckDomain struct {
DNSQuery string `json:"dns_query"`
}

type LogCategory struct {
Name string `json:"name"`
LogLevel string `json:"log_level"`
}

type LoggingConfig struct {
Format FormatConfig `json:"format,omitempty"`
Format FormatConfig `json:"format,omitempty"`
Categories []LogCategory `json:"categories,omitempty"`
}

type FormatConfig struct {
Expand Down
1 change: 1 addition & 0 deletions src/bosh-dns/dns/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ func mainExitCode() int {
if config.UseRFC3339Formatting() {
logger.UseRFC3339Timestamps()
}
logger.UseCategories(config.GetLogCategories())
logTag := "main"
logger.Info(logTag, "bosh-dns starting")
defer logger.FlushTimeout(5 * time.Second) //nolint:errcheck
Expand Down

0 comments on commit 5c4ff27

Please sign in to comment.