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 support for json logging #50

Merged
merged 7 commits into from
Feb 20, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 2 additions & 0 deletions deploy/injector-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ spec:
value: ":8080"
- name: AGENT_INJECT_LOG_LEVEL
value: "info"
- name: AGENT_INJECT_LOG_FORMAT
- value: "json"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Format is off here.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think he default should be json. It's nice that there's a configurable for this now, however, not everyone is going to want JSON by default.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree, default log settings should be similar to hashicorp/vault. Fixed.

- name: AGENT_INJECT_VAULT_ADDR
value: "https://vault.$(NAMESPACE).svc:8200"
- name: AGENT_INJECT_VAULT_IMAGE
Expand Down
7 changes: 5 additions & 2 deletions subcommand/injector/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ type Command struct {

flagListen string // Address of Vault Server
flagLogLevel string // Log verbosity
flagLogFormat string // Log format
flagCertFile string // TLS Certificate to serve
flagKeyFile string // TLS private key to serve
flagAutoName string // MutatingWebhookConfiguration for updating
Expand Down Expand Up @@ -101,8 +102,10 @@ func (c *Command) Run(args []string) int {
return 1
}

logger := hclog.Default().Named("handler")
logger.SetLevel(level)
logger := hclog.New(&hclog.LoggerOptions{
Name: "handler",
Level: level,
JSONFormat: (c.flagLogFormat == "json")})

// Build the HTTP handler and server
injector := agentInject.Handler{
Expand Down
8 changes: 7 additions & 1 deletion subcommand/injector/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ type Specification struct {
// LogLevel is the AGENT_INJECT_LOG_LEVEL environment variable.
LogLevel string `split_words:"true"`

// LogFormat is the AGENT_INJECT_LOG_FORMAT environment variable
LogFormat string `split_words:"true"`

// TLSAuto is the AGENT_INJECT_TLS_AUTO environment variable.
TLSAuto string `envconfig:"tls_auto"`

Expand Down Expand Up @@ -83,7 +86,6 @@ func (c *Command) logLevel() (hclog.Level, error) {
default:
return level, fmt.Errorf("unknown log level: %s", c.flagLogLevel)
}

return level, nil
}

Expand All @@ -103,6 +105,10 @@ func (c *Command) parseEnvs() error {
c.flagLogLevel = envs.LogLevel
}

if envs.LogFormat != "" {
c.flagLogFormat = envs.LogFormat
}

if envs.TLSAuto != "" {
c.flagAutoName = envs.TLSAuto
}
Expand Down