Skip to content
This repository has been archived by the owner on Jul 26, 2022. It is now read-only.

Commit

Permalink
feat: Log base w/ configurable pid and hostname keys (#868)
Browse files Browse the repository at this point in the history
* Log base w/ configurable pid and hostname keys

- `hostname` isn't always desireable and is somewhat inaccurate given
os.hostname is the pod name in kubernetes

* Documentation for configurable log base
  • Loading branch information
SocalNick authored Nov 17, 2021
1 parent f4e5037 commit ca549f5
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 0 deletions.
2 changes: 2 additions & 0 deletions charts/kubernetes-external-secrets/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ The following table lists the configurable parameters of the `kubernetes-externa
| `env.AWS_INTERMEDIATE_ROLE_ARN` | Specifies a role to be assumed before assuming role arn specified in external secrets | |
| `env.LOG_LEVEL` | Set the application log level | `info` |
| `env.LOG_MESSAGE_KEY` | Set the key for log messages log text, for example when running on GCP it might be nice to set to `message` | `msg` |
| `env.LOG_BASE_PID_KEY` | Set the key for log messages process id | `pid` |
| `env.LOG_BASE_HOSTNAME_KEY` | Set the key for log messages hostname, for example, you might choose to use `pod_name` | `hostname` |
| `env.USE_HUMAN_READABLE_LOG_LEVELS` | Sets log levels as string instead of ints eg `info` instead of `30`, setting this to any value will switch | `nil` |
| `env.METRICS_PORT` | Specify the port for the prometheus metrics server | `3001` |
| `env.ROLE_PERMITTED_ANNOTATION` | Specify the annotation key where to lookup the role arn permission boundaries | `iam.amazonaws.com/permitted` |
Expand Down
5 changes: 5 additions & 0 deletions config/environment.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ const pollerIntervalMilliseconds = process.env.POLLER_INTERVAL_MILLISECONDS
? Number(process.env.POLLER_INTERVAL_MILLISECONDS) : 10000

const logLevel = process.env.LOG_LEVEL || 'info'
const os = require('os')
const logBasePidKey = process.env.LOG_BASE_PID_KEY || 'pid'
const logBaseHostnameKey = process.env.LOG_BASE_HOSTNAME_KEY || 'hostname'
const logBase = { [logBasePidKey]: process.pid, [logBaseHostnameKey]: os.hostname() }
const useHumanReadableLogLevels = 'USE_HUMAN_READABLE_LOG_LEVELS' in process.env
const logMessageKey = process.env.LOG_MESSAGE_KEY || 'msg'

Expand Down Expand Up @@ -70,6 +74,7 @@ module.exports = {
enforceNamespaceAnnotation,
pollingDisabled,
logLevel,
logBase,
useHumanReadableLogLevels,
logMessageKey,
watchTimeout,
Expand Down
1 change: 1 addition & 0 deletions config/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ const logger = pino({
redact: ['err.options.headers', 'err.options.json.jwt'],
messageKey: envConfig.logMessageKey || 'msg',
level: envConfig.logLevel,
base: envConfig.logBase,
formatters: {
level (label, number) {
return { level: envConfig.useHumanReadableLogLevels ? label : number }
Expand Down

0 comments on commit ca549f5

Please sign in to comment.