2
votes

I'm running a Docker container with a Python application that writes logs to the stdout with the Python standard logging lib. The container is not hosted in any Google Cloud product but on my own machine.

I configured docker to use the gcplogs driver as described on this guide and the official driver docs.

The docker container runs with no problems. However, no logs are being collected because I don't see anything on the Stackdriver logging viewer, other than some weird "ping" log entries that are produced on each execution of the docker container.

enter image description here

The python logger is configured via dictConfig:

'console': {
    'level': 'DEBUG',
    'class': 'logging.StreamHandler',
    'formatter': 'simple',
    'stream': 'ext://sys.stdout'
},

The docker container is ran with this command:

docker run --env-file `pwd`/.env \
       --label app=oncrm \
       --log-driver=gcplogs \
       --log-opt gcp-meta-name= host_name\
       --log-opt gcp-project=cloud_project_id \
       --log-opt labels=app \
       --name oncrm \
       --net host \
       --rm \
       -v `pwd`/data:/code/data \
       -v `pwd`/logs:/code/logs \
docker_image sh update_subs.sh

The driver documentation doesn't really specify where are log being collected from but it does mention that the driver should also work outside the Google Cloud Platform/Products.

Environment:

  • Python 3.6.4 (official DockerHub image for Alpine3.7)
  • Docker-ce 18.03.0
  • Ubuntu 17.10
  • Stackdriver Premium tier
1
Do you have gcloud installed on your machine ? Are you logged ? - Alexandre
@Alexandre I had it, and it is logged-in. However, that won't make a difference because login credentials are obtained via GOOGLE_APPLICATION_CREDENTIALS which is the only authentication method supported by the driver. Before setting that env var I had authentication error messages, but that's not the case anymore. - Layo
Is Stackdriver logging API is Enabled ? console.cloud.google.com/apis/api/logging.googleapis.com/… Is your credential has Stackdriver logging scope ? - Alexandre
Yep, I also checked that. - Layo

1 Answers

0
votes

You probably need to switch your logging resource from Global to the specific project that you are logging to per your gcp-project opt in the docker command. There is a Google Project option in that menu in the Stackdriver logging UI.