Gunicorn: pass enviroment varable to .conf file

Created on 6 Feb 2019  路  5Comments  路  Source: benoitc/gunicorn

I would like to know if it possible to pass env variable to the .confi file?

i add a custom handler like

[handler_customer_log]
class=logging.FileHandler
formatter=customer
args=(os.environ[logpath])

but i get an exception.

Feedback Requested Question

Most helpful comment

@tilgovi thanks, i used your solution.

All 5 comments

shouldn鈥檛 it be a string? which error do you get?

i am not sure..., i am trying to found how can i pass the log file name dynamically and not predefine as a string in args

@MatanTubul I don't think you can do that with logging configuration. You could, though, use a custom callable that returns a FileHandler constructed as you need. Rather than specify class=logging.FileHandler specify your own function that uses the environment variable to construct and return a file handler.

@MatanTubul what exception did you get? For sure anyway os.environ takes a string as a parameter. Like @tilgovi is saying you can set the logging configuration. About passing arguments, the old but still valid way is to give to the command line some shell variables and set them via a shell script or your launcher like supervisord, systemd...

@tilgovi thanks, i used your solution.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ttcqaq picture ttcqaq  路  4Comments

leonardbinet picture leonardbinet  路  4Comments

benoitc picture benoitc  路  4Comments

mw44118 picture mw44118  路  4Comments

bywangxp picture bywangxp  路  4Comments