How to disable stackdriver logging in a spring application for a GCP project without creating a new docker image

110 Views Asked by At

I have a spring application packaged inside a docker image and running in GKE pods. I want to disable stackdriver logging but only for this application in gke. Is there any env variable/property I can change in my spring application to disable this? I am using these two jars -

<dependency>
            <groupId>com.google.cloud</groupId>
            <artifactId>spring-cloud-gcp-starter</artifactId>
        </dependency>
        <dependency>
            <groupId>com.google.cloud</groupId>
            <artifactId>spring-cloud-gcp-starter-logging</artifactId>
        </dependency>

I found one method i.e. to change application.properties to

spring.cloud.gcp.logging.enabled=false
stackdriver.log.level=OFF

But for this I will have to create a new docker image and redeploy. Is there any way I can do directly in my kubernetes yaml/env variable?

Update - these two variables in application.properties only worked once(stopped logging to stackdriver) and now its again logging to stackdriver. Strange behaviour.

1

There are 1 best solutions below

2
Robert Moskal On BEST ANSWER

There's no need to rebuild your container image. Spring applications can pull application properties from environment variables. Probably for some very good reason, the names require remapping. So

spring.cloud.gcp.logging.enabled becomes SPRING_CLOUD_GCP_LOGGING_ENABLED.

Your k8s pod definition allows passing in environment variables as part of a container specification (just like docker compose):

 spec:
      containers:
      - name: my-container
        image: myimage:latest
        env:
        - name: SPRING_CLOUD_GCP_LOGGING_ENABLED
          value: false

Apply the changes to the pod with the following. Your pod will be restarted.

kubectl apply -f <pod-definition-file.yaml>

stackdriver.log.level is left for you. I can't promise you that any of this will turn off logging, only that this will update application properties without requiring you to rebuild the container.