Introduce ENABLE_JSON_LOGGING env variable (#1158)
This commit is contained in:
parent
38e15183a2
commit
692c721854
|
|
@ -37,6 +37,10 @@ spec:
|
||||||
image: "{{ .Values.image.registry }}/{{ .Values.image.repository }}:{{ .Values.image.tag }}"
|
image: "{{ .Values.image.registry }}/{{ .Values.image.repository }}:{{ .Values.image.tag }}"
|
||||||
imagePullPolicy: {{ .Values.image.pullPolicy }}
|
imagePullPolicy: {{ .Values.image.pullPolicy }}
|
||||||
env:
|
env:
|
||||||
|
{{- if .Values.enableJsonLogging }}
|
||||||
|
- name: ENABLE_JSON_LOGGING
|
||||||
|
value: "true"
|
||||||
|
{{- end }}
|
||||||
{{- if eq .Values.configTarget "ConfigMap" }}
|
{{- if eq .Values.configTarget "ConfigMap" }}
|
||||||
- name: CONFIG_MAP_NAME
|
- name: CONFIG_MAP_NAME
|
||||||
value: {{ template "postgres-operator.fullname" . }}
|
value: {{ template "postgres-operator.fullname" . }}
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,9 @@ podLabels: {}
|
||||||
|
|
||||||
configTarget: "ConfigMap"
|
configTarget: "ConfigMap"
|
||||||
|
|
||||||
|
# JSON logging format
|
||||||
|
enableJsonLogging: false
|
||||||
|
|
||||||
# general configuration parameters
|
# general configuration parameters
|
||||||
configGeneral:
|
configGeneral:
|
||||||
# choose if deployment creates/updates CRDs with OpenAPIV3Validation
|
# choose if deployment creates/updates CRDs with OpenAPIV3Validation
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@ package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"flag"
|
"flag"
|
||||||
"log"
|
log "github.com/sirupsen/logrus"
|
||||||
"os"
|
"os"
|
||||||
"os/signal"
|
"os/signal"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
@ -36,6 +36,8 @@ func init() {
|
||||||
flag.BoolVar(&config.NoTeamsAPI, "noteamsapi", false, "Disable all access to the teams API")
|
flag.BoolVar(&config.NoTeamsAPI, "noteamsapi", false, "Disable all access to the teams API")
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
|
config.EnableJsonLogging = os.Getenv("ENABLE_JSON_LOGGING") == "true"
|
||||||
|
|
||||||
configMapRawName := os.Getenv("CONFIG_MAP_NAME")
|
configMapRawName := os.Getenv("CONFIG_MAP_NAME")
|
||||||
if configMapRawName != "" {
|
if configMapRawName != "" {
|
||||||
|
|
||||||
|
|
@ -63,6 +65,9 @@ func init() {
|
||||||
func main() {
|
func main() {
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
|
if config.EnableJsonLogging {
|
||||||
|
log.SetFormatter(&log.JSONFormatter{})
|
||||||
|
}
|
||||||
log.SetOutput(os.Stdout)
|
log.SetOutput(os.Stdout)
|
||||||
log.Printf("Spilo operator %s\n", version)
|
log.Printf("Spilo operator %s\n", version)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -56,3 +56,7 @@ The following environment variables are accepted by the operator:
|
||||||
* **CRD_READY_WAIT_INTERVAL**
|
* **CRD_READY_WAIT_INTERVAL**
|
||||||
defines the interval between consecutive attempts waiting for the
|
defines the interval between consecutive attempts waiting for the
|
||||||
`postgresql` CRD to be created. The default is 5s.
|
`postgresql` CRD to be created. The default is 5s.
|
||||||
|
|
||||||
|
* **ENABLE_JSON_LOGGING**
|
||||||
|
Set to `true` for JSON formatted logging output.
|
||||||
|
The default is false.
|
||||||
|
|
|
||||||
|
|
@ -71,6 +71,9 @@ type Controller struct {
|
||||||
// NewController creates a new controller
|
// NewController creates a new controller
|
||||||
func NewController(controllerConfig *spec.ControllerConfig, controllerId string) *Controller {
|
func NewController(controllerConfig *spec.ControllerConfig, controllerId string) *Controller {
|
||||||
logger := logrus.New()
|
logger := logrus.New()
|
||||||
|
if controllerConfig.EnableJsonLogging {
|
||||||
|
logger.SetFormatter(&logrus.JSONFormatter{})
|
||||||
|
}
|
||||||
|
|
||||||
var myComponentName = "postgres-operator"
|
var myComponentName = "postgres-operator"
|
||||||
if controllerId != "" {
|
if controllerId != "" {
|
||||||
|
|
|
||||||
|
|
@ -114,6 +114,8 @@ type ControllerConfig struct {
|
||||||
CRDReadyWaitTimeout time.Duration
|
CRDReadyWaitTimeout time.Duration
|
||||||
ConfigMapName NamespacedName
|
ConfigMapName NamespacedName
|
||||||
Namespace string
|
Namespace string
|
||||||
|
|
||||||
|
EnableJsonLogging bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// cached value for the GetOperatorNamespace
|
// cached value for the GetOperatorNamespace
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue