1

I set my /etc/docker/daemon.json to send container logs to GCP:

{
  "log-driver": "gcplogs",
  "log-opts": {
    "gcp-meta-name": "some-cool-name",
    "gcp-project": "some-project-name"
  }
}

This works fine, but it seems there is no distinction between STDERR and STDOUT, both entries have a Severity of 'Default'

In container:

root@0bbcf70a30ed:/var/www/app# echo 'xx' > /proc/1/fd/2
root@0bbcf70a30ed:/var/www/app# echo 'xx' > /proc/1/fd/1

In GCP:

Google Cloud Logging Screenshot

Is there anything I can do to make the logs from STDERR have a Severity of 'Error' ?

And if not, is there anything I can do to make all STDERR entries have a string like 'ERROR' prepended, so I can at least filter on them?

For example, in my Dockerfile I do:

RUN touch /var/log/apache2/error.log
RUN ln -sf /proc/1/fd/2 /var/log/apache2/error.log

This makes sure the apache2 error logs go to the containers' STDERR. If I could somehow make all those logging entries have a string like 'ERROR' prepended, I would at least have a semi-workable solution.

But really, having STDERR entries automatically get Severity 'Error' is ideal.

natli
  • 3,782
  • 11
  • 51
  • 82
  • The [logs structure](https://cloud.google.com/stackdriver/docs/solutions/gke/using-logs#application_logs) in Cloud logging cannot be changed, but you can create your own logging that will be used by cloud logging. [This post](https://stackoverflow.com/questions/56807817/python-google-cloud-function-logging-severity-and-duplicates) can give you an idea. This [documentation](https://cloud.google.com/logging/docs/setup) may also help. – Alex G Jan 29 '21 at 09:54
  • 1
    The [log structure](https://cloud.google.com/stackdriver/docs/solutions/gke/using-logs#application_logs) you linked states separate names for stderr and stdout - but this is for GKE. The problem I'm facing with GCP's log engine for Docker is that the log name is **always** 'gcplogs-docker-driver' - I know I can do custom logging in the client(s) but that's not a realistic solution. – natli Feb 08 '21 at 13:27

0 Answers0