2015-10-19 47 views
0

我已經使用Python粘貼部署腳本部署Flask + Gunicorn項目。然而,我不能在部署腳本中寫access_log_format(h)s%(l)s%(u)s%(t)s「%(r)s」%(s)s%(b)s 「%(f)」。因爲我們%(h)s格式在Paste Deploy腳本中有特殊含義。如文檔中所述:如何在Python中隱藏百分比字符粘貼部署配置文件?

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; 

但是,我可以解決這個問題嗎?

+0

你嘗試過包裝與引號括起來的? (例如'access_log_format ='%(h)s'') – Ofir

+0

您可以將'access_log_format'字段移動到除[DEFAULT]之外的部分嗎?措詞意味着變量替換僅在該配置部分中起作用。 在我自己的金字塔應用程序中,日誌記錄配置看起來很像[金字塔日誌記錄配置]中找到的示例(http://docs.pylonsproject.org/projects/pyramid/en/latest/narr/logging.html#日誌配置) –

+0

@IanMarcinkowski不,我把它放在[server:main]部分,而不是[DEFAULT]之一。 – andy

回答

0

在這種情況下,您嘗試配置應用程序的兩個組件--Gunicorn和Flask應用程序(使用粘貼部署)。 Gunicorn負責訪問日誌記錄,而Flask/Paste Deploy則使用您現有的配置進行配置。 Paste Deploy負責在其自己的配置文件中進行魔術變量替換,這與Gunicorn訪問日誌配置衝突。

您可以爲Gunicorn提供一個單獨的配置文件,它將包含您的訪問日誌格式。例如:

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" 
+0

不,它不能在粘貼部署中工作。像這樣的東西將是錯誤信息。 錯誤:錯誤文件demo.conf:壞值替換: 部分:服務器:主] 選項:access_log_format 鍵:H rawval: 「%(H)S」 – andy

+1

你有沒有想過傳球命令行上的訪問日誌格式?我沒有看到任何通過Paster格式的配置文件向Gunicorn提供訪問日誌格式的兼容方式。 您是否正在使用'gunicorn'或'pserve'從命令行運行應用程序? –

+1

您可以創建2個配置文件;一個用於Gunicorn,一個用於Flask應用程序。您嘗試配置的訪問日誌是Gunicorn的一部分,而不是Flask應用程序。嘗試像這樣:'gunicorn -c gunicorn.conf --paste application.conf [0123]' –