pythondockersysloguvicorngelf

uvicorn suppresses python's syslog for gelf driver


I have a docker container running logging with gelf to a logging instance via udp -- all fine!

The container is based on Ubuntu 18 where rsyslog is running as a service, which works well.

Inside the container is a FastAPI application running with uvicorn webserver. It also works perfectly and uvicorn is perfectly logging to the logging instance.

Here comes what is not working, but usually works with non-FastAPI python projects. I use python's syslog to log more stuff.

The app with syslog looks like this (I created an easy example to debug for myself):

from fastapi import FastAPI
import syslog

syslog.openlog(facility=syslog.LOG_LOCAL0)

app = FastAPI()

syslog.syslog(syslog.LOG_INFO, 'startup done')

@app.get("/")
async def root():
    syslog.syslog(syslog.LOG_INFO, 'get hello')
    return {"message": "Hello World"}

The logs at the logging instance don't show the syslog messages. Only uvicorn's messages:

INFO:     Started server process [21]
INFO:     Waiting for application startup.
INFO:     Application startup complete.
INFO:     Uvicorn running on http://0.0.0.0:80 (Press CTRL+C to quit)
INFO:     172.17.0.1:35346 - "GET / HTTP/1.1" 200 OK

For further debugging I checked rsyslog's log file, and it contains the syslog messages:

Dec 23 17:21:39 /uvicorn: startup done
Dec 23 17:21:50 /uvicorn: get hello

and here is the rsyslog configuration at /etc/rsyslog.d

local0.* {
   action(type="omfile" file="/var/log/test.log" fileOwner="syslog" fileGroup="syslog" fileCreateMode="0640")
   stop
}

What am I missing here? Why is gelf ignoring rsyslog? What do I need to understand about uvicorn concerning syslog? or what can I do?

Thanks


Solution

  • The problem results from gelf ignoring syslog. A simple print in python will be recognized though.

    Solution: I built myself a log function in python which will log to syslog and print out whatever I want to log.