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