0

I have use Python Paste Deploy script to deploy a Flask+Gunicorn project. However, i can not write access_log_format in deploy script with (h)s %(l)s %(u)s %(t)s "%(r)s" %(s)s %(b)s "%(f)". Because we %(h)s format has special meaning in Paste Deploy script. As descripted in the doc:

You can use variable substitution, which will pull variables from 
the section [DEFAULT] (case sensitive!) with markers like %
(var_name)s. The special variable %(here)s is the directory
containing the configuration file;

However can i get around this?

Seb D.
  • 5,046
  • 1
  • 28
  • 36
andy
  • 3,951
  • 9
  • 29
  • 40
  • have you tried wrapping the string with quotes? (e.g. `access_log_format = '%(h)s'`) – Ofir Oct 19 '15 at 14:35
  • Can you move the `access_log_format` field to a section besides `[DEFAULT]`? The wording implies that the variable substitution works in that configuration section only. In my own Pyramid application, the logging configuration looks a lot like the examples found in the [Pyramid logging configuration](http://docs.pylonsproject.org/projects/pyramid/en/latest/narr/logging.html#logging-configuration) – Ian Marcinkowski Oct 20 '15 at 19:56
  • @IanMarcinkowski No, i put it in [server:main] section, not the [DEFAULT] one. – andy Oct 21 '15 at 02:20

1 Answers1

0

There are two components of your application that you are trying to configure in this case - Gunicorn and your Flask application (which is using Paste Deploy). Gunicorn is responsible for the access logging, while Flask / Paste Deploy are configured using your existing configuration. Paste Deploy is responsible for the magical variable substitution in its own configuration files, which conflicts with the Gunicorn access log configuration.

You can provide a separate configuration file for Gunicorn, which will contain your access log formatting. For example:

gunicorn -c gunicorn.conf --paste demo.conf

gunicorn.conf:

accesslog = access.log
access_log_format = %(h)s %(l)s %(u)s %(t)s "%(r)s" %(s)s %(b)s "%(f)s" "%(a)s"
Ian Marcinkowski
  • 408
  • 1
  • 3
  • 11
  • No, it can not work in paste deploy. something like this will be the error message. Error: Error in file demo.conf: Bad value substitution: section: [server:main] option : access_log_format key : h rawval : "%(h)s" – andy Oct 21 '15 at 02:18
  • 1
    Have you thought of passing the access log format on the command line? I am not seeing any compatible way to provide the access log format to Gunicorn via a Paster-formatted config file. Are you running the application from the command line using `gunicorn` or `pserve`? – Ian Marcinkowski Oct 21 '15 at 14:24
  • 1
    You could create 2 configuration files; one for Gunicorn and one for your Flask application. The access log you are trying to configure is part of Gunicorn, not the Flask application. Try something like this: `gunicorn -c gunicorn.conf --paste application.conf [...]` – Ian Marcinkowski Oct 21 '15 at 14:34
  • @IanMarchinkowski, that seems good to me. I will give it a try. I finally tried that with access log format argument specified in the command line. – andy Oct 22 '15 at 08:23
  • Great! I will update my answer. Let me know if you have any more trouble. – Ian Marcinkowski Oct 22 '15 at 13:24