Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add console as logging encoding type #4549

Merged
merged 3 commits into from
Oct 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions common/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -317,14 +317,20 @@ type (

// Logger contains the config items for logger
Logger struct {
// Stdout is true if the output needs to goto standard out
// Stdout is true then the output needs to goto standard out
// By default this is false and output will go to standard error
Stdout bool `yaml:"stdout"`
// Level is the desired log level
Level string `yaml:"level"`
// OutputFile is the path to the log output file
// Stdout must be false, otherwise Stdout will take precedence
OutputFile string `yaml:"outputFile"`
// levelKey is the desired log level, defaults to "level"
// LevelKey is the desired log level, defaults to "level"
LevelKey string `yaml:"levelKey"`
// Encoding decides the format, supports "console" and "json".
// "json" will print the log in JSON format(better for machine), while "console" will print in plain-text format(more human friendly)
// Default is "json"
Encoding string `yaml:"encoding"`
}

// DCRedirectionPolicy contains the frontend datacenter redirection policy
Expand All @@ -340,6 +346,12 @@ type (
// Statsd is the configuration for statsd reporter
Statsd *Statsd `yaml:"statsd"`
// Prometheus is the configuration for prometheus reporter
// Some documentation below because the tally library is missing it:
// In this configuration, default timerType is "histogram", alternatively "summary" is also supported.
// In some cases, summary is better. Choose it wisely.
// For histogram, default buckets are defined in https://github.com/uber/cadence/blob/master/common/metrics/tally/prometheus/buckets.go#L34
// For summary, default objectives are defined in https://github.com/uber-go/tally/blob/137973e539cd3589f904c23d0b3a28c579fd0ae4/prometheus/reporter.go#L70
// You can customize the buckets/objectives if the default is not good enough.
Prometheus *prometheus.Configuration `yaml:"prometheus"`
// Tags is the set of key-value pairs to be reported
// as part of every metric
Expand Down
12 changes: 11 additions & 1 deletion common/config/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
package config

import (
"fmt"
"os"
"strings"

Expand Down Expand Up @@ -60,11 +61,20 @@ func (cfg *Logger) NewZapLogger() (*zap.Logger, error) {
}
}

encoding := "json"
if cfg.Encoding != "" {
if cfg.Encoding == "json" || cfg.Encoding == "console" {
encoding = cfg.Encoding
} else {
return nil, fmt.Errorf("invalid encoding for log, only supporting json or console")
}
}

config := zap.Config{
Level: zap.NewAtomicLevelAt(parseZapLevel(cfg.Level)),
Development: false,
Sampling: nil, // consider exposing this to config for our external customer
Encoding: "json",
Encoding: encoding,
EncoderConfig: encodeConfig,
OutputPaths: []string{outputPath},
ErrorOutputPaths: []string{outputPath},
Expand Down