Vitaly Karasik DevOps
Vitaly Karasik DevOps

Reputation: 488

How to add a timestamp to my Python app uwsgi log?

My Python application sends logs to stderr, UWSGI redirects it into /var/log/uwsgi/app/myapplication.log. What is the simplest way to prefix my app log output with a timestamp? I prefer to do this with uwsgi.ini config, w/o change application code.

TIA, Vitaly

Upvotes: 5

Views: 4850

Answers (3)

okrutny
okrutny

Reputation: 1110

To make this work in ini file, i had to add log-strftime param, like:

log-date = %%Y-%%m-%%d %%H:%%M:%%S
logformat-strftime
log-format = [%(ftime)]

prints:

[2019-08-05 13:49:16]

Upvotes: 4

holmberd
holmberd

Reputation: 2609

UWSGI ini file example

daemonize = /var/log/uwsgi/app.log
log-reopen = true
log-date = [%%Y:%%m:%%d %%H:%%M:%%S]

Output: [2018:10:15 23:05:39] - spawned uWSGI worker 3 (pid: 26668, cores: 1)

Upvotes: 4

roberto
roberto

Reputation: 12933

--logdate will do the trick.

eventually it takes an optional strftime-like string:

--logdate="%s"

will add the unix time as well as

--logdate="%d/%m/%Y"

will add the day/month/year prefix

Upvotes: 3

Related Questions