简体   繁体   中英

Google Cloud logging driver for docker doesn't collect logs

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.

在此处输入图片说明

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM