2

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
Layo
  • 677
  • 6
  • 16
  • Do you have gcloud installed on your machine ? Are you logged ? – Alexandre Apr 25 '18 at 10:13
  • @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 Apr 26 '18 at 14:43
  • Is Stackdriver logging API is Enabled ? https://console.cloud.google.com/apis/api/logging.googleapis.com/overview Is your credential has Stackdriver logging scope ? – Alexandre Apr 27 '18 at 08:26
  • Yep, I also checked that. – Layo Apr 28 '18 at 09:26

1 Answers1

0

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.

ty.
  • 10,924
  • 9
  • 52
  • 71