mirror of
https://github.com/frappe/gunicorn.git
synced 2026-01-14 11:09:11 +08:00
add support for logging configuration in paster ini-files
This commit is contained in:
parent
fce191c0db
commit
d546d490e5
30
examples/log_app.ini
Normal file
30
examples/log_app.ini
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
[app:main]
|
||||||
|
paste.app_factory = log_app:app_factory
|
||||||
|
|
||||||
|
[server:main]
|
||||||
|
use = egg:gunicorn#main
|
||||||
|
host = 127.0.0.1
|
||||||
|
port = 8080
|
||||||
|
|
||||||
|
|
||||||
|
[loggers]
|
||||||
|
keys=root
|
||||||
|
|
||||||
|
[handlers]
|
||||||
|
keys=console
|
||||||
|
|
||||||
|
[formatters]
|
||||||
|
keys=default
|
||||||
|
|
||||||
|
[logger_root]
|
||||||
|
level=INFO
|
||||||
|
qualname=root
|
||||||
|
handlers=console
|
||||||
|
|
||||||
|
[handler_console]
|
||||||
|
class=StreamHandler
|
||||||
|
formatter=default
|
||||||
|
args=(sys.stdout, )
|
||||||
|
|
||||||
|
[formatter_default]
|
||||||
|
format=[%(asctime)s] [%(levelname)-7s] - %(process)d:%(name)s:%(funcName)s - %(message)s
|
||||||
14
examples/log_app.py
Normal file
14
examples/log_app.py
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
import logging
|
||||||
|
|
||||||
|
log = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
def app_factory(global_options, **local_options):
|
||||||
|
return app
|
||||||
|
|
||||||
|
def app(environ, start_response):
|
||||||
|
start_response("200 OK", [])
|
||||||
|
log.debug("Hello Debug!")
|
||||||
|
log.info("Hello Info!")
|
||||||
|
log.warn("Hello Warn!")
|
||||||
|
log.error("Hello Error!")
|
||||||
|
return ["Hello World!\n"]
|
||||||
@ -6,6 +6,7 @@
|
|||||||
import os
|
import os
|
||||||
import pkg_resources
|
import pkg_resources
|
||||||
import sys
|
import sys
|
||||||
|
import ConfigParser
|
||||||
|
|
||||||
from paste.deploy import loadapp, loadwsgi
|
from paste.deploy import loadapp, loadwsgi
|
||||||
SERVER = loadwsgi.SERVER
|
SERVER = loadwsgi.SERVER
|
||||||
@ -26,6 +27,7 @@ class PasterApplication(Application):
|
|||||||
|
|
||||||
self.cfgurl = 'config:%s' % cfgfname
|
self.cfgurl = 'config:%s' % cfgfname
|
||||||
self.relpath = os.path.dirname(cfgfname)
|
self.relpath = os.path.dirname(cfgfname)
|
||||||
|
self.cfgfname = cfgfname
|
||||||
|
|
||||||
sys.path.insert(0, self.relpath)
|
sys.path.insert(0, self.relpath)
|
||||||
pkg_resources.working_set.add_entry(self.relpath)
|
pkg_resources.working_set.add_entry(self.relpath)
|
||||||
@ -63,6 +65,24 @@ class PasterApplication(Application):
|
|||||||
def load(self):
|
def load(self):
|
||||||
return loadapp(self.cfgurl, relative_to=self.relpath)
|
return loadapp(self.cfgurl, relative_to=self.relpath)
|
||||||
|
|
||||||
|
def configure_logging(self):
|
||||||
|
# from paste.script.command
|
||||||
|
parser = ConfigParser.ConfigParser()
|
||||||
|
parser.read([self.cfgfname])
|
||||||
|
if parser.has_section('loggers'):
|
||||||
|
if sys.version_info >= (2, 6):
|
||||||
|
from logging.config import fileConfig
|
||||||
|
else:
|
||||||
|
# Use our custom fileConfig -- 2.5.1's with a custom Formatter class
|
||||||
|
# and less strict whitespace (which were incorporated into 2.6's)
|
||||||
|
from paste.script.util.logging_config import fileConfig
|
||||||
|
|
||||||
|
config_file = os.path.abspath(self.cfgfname)
|
||||||
|
fileConfig(config_file, dict(__file__=config_file,
|
||||||
|
here=os.path.dirname(config_file)))
|
||||||
|
else:
|
||||||
|
super(PasterApplication, self).configure_logging()
|
||||||
|
|
||||||
class PasterServerApplication(Application):
|
class PasterServerApplication(Application):
|
||||||
|
|
||||||
def __init__(self, app, gcfg=None, host="127.0.0.1", port=None, *args, **kwargs):
|
def __init__(self, app, gcfg=None, host="127.0.0.1", port=None, *args, **kwargs):
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user