added new proxy-server configuration options for access_log_facility and
access_log_name
This commit is contained in:
parent
f9fa63686c
commit
461bf8df71
@ -48,11 +48,11 @@ import logging
|
||||
logging.thread = eventlet.green.thread
|
||||
logging.threading = eventlet.green.threading
|
||||
logging._lock = logging.threading.RLock()
|
||||
# setup access level logging
|
||||
ACCESS = 25
|
||||
logging._levelNames[ACCESS] = 'ACCESS'
|
||||
# setup notice level logging
|
||||
NOTICE = 25
|
||||
logging._levelNames[NOTICE] = 'NOTICE'
|
||||
# syslog priority "notice" is used for proxy access log lines
|
||||
SysLogHandler.priority_map['ACCESS'] = 'notice'
|
||||
SysLogHandler.priority_map['NOTICE'] = 'notice'
|
||||
|
||||
# These are lazily pulled from libc elsewhere
|
||||
_sys_fallocate = None
|
||||
@ -315,15 +315,14 @@ class LogAdapter(object):
|
||||
def getEffectiveLevel(self):
|
||||
return self.logger.getEffectiveLevel()
|
||||
|
||||
def access(self, msg, *args):
|
||||
def notice(self, msg, *args):
|
||||
"""
|
||||
Convenience function for proxy access request log level. Only
|
||||
proxy access log messages should use this method. The python
|
||||
Convenience function for syslog priority LOG_NOTICE. The python
|
||||
logging lvl is set to 25, just above info. SysLogHandler is
|
||||
monkey patched to map this log lvl to the LOG_NOTICE syslog
|
||||
priority.
|
||||
"""
|
||||
self.logger.log(ACCESS, msg, *args)
|
||||
self.logger.log(NOTICE, msg, *args)
|
||||
|
||||
def exception(self, msg, *args):
|
||||
_junk, exc, _junk = sys.exc_info()
|
||||
|
@ -168,10 +168,10 @@ def run_wsgi(conf_file, app_section, *args, **kwargs):
|
||||
signal.signal(signal.SIGHUP, signal.SIG_DFL)
|
||||
signal.signal(signal.SIGTERM, signal.SIG_DFL)
|
||||
run_server()
|
||||
logger.info('Child %d exiting normally' % os.getpid())
|
||||
logger.notice('Child %d exiting normally' % os.getpid())
|
||||
return
|
||||
else:
|
||||
logger.info('Started child %s' % pid)
|
||||
logger.notice('Started child %s' % pid)
|
||||
children.append(pid)
|
||||
try:
|
||||
pid, status = os.wait()
|
||||
@ -182,8 +182,8 @@ def run_wsgi(conf_file, app_section, *args, **kwargs):
|
||||
if err.errno not in (errno.EINTR, errno.ECHILD):
|
||||
raise
|
||||
except KeyboardInterrupt:
|
||||
logger.info('User quit')
|
||||
logger.notice('User quit')
|
||||
break
|
||||
greenio.shutdown_safe(sock)
|
||||
sock.close()
|
||||
logger.info('Exited')
|
||||
logger.notice('Exited')
|
||||
|
@ -1612,6 +1612,16 @@ class BaseApplication(object):
|
||||
self.logger = logger
|
||||
if conf is None:
|
||||
conf = {}
|
||||
if 'access_log_name' in conf or 'access_log_facility' in conf:
|
||||
access_log_conf = {
|
||||
'log_name': conf.get('access_log_name', conf.get('log_name',
|
||||
'proxy-server')),
|
||||
'log_facility': conf.get('access_log_facility',
|
||||
conf.get('log_facility', 'LOG_LOCAL0')),
|
||||
}
|
||||
self.access_logger = get_logger(access_log_conf)
|
||||
else:
|
||||
self.access_logger = self.logger
|
||||
swift_dir = conf.get('swift_dir', '/etc/swift')
|
||||
self.node_timeout = int(conf.get('node_timeout', 10))
|
||||
self.conn_timeout = float(conf.get('conn_timeout', 0.5))
|
||||
@ -1790,7 +1800,7 @@ class Application(BaseApplication):
|
||||
if getattr(req, 'client_disconnect', False) or \
|
||||
getattr(response, 'client_disconnect', False):
|
||||
status_int = 499
|
||||
self.logger.access(' '.join(quote(str(x)) for x in (
|
||||
self.access_logger.info(' '.join(quote(str(x)) for x in (
|
||||
client or '-',
|
||||
req.remote_addr or '-',
|
||||
time.strftime('%d/%b/%Y/%H/%M/%S', time.gmtime()),
|
||||
|
@ -307,8 +307,8 @@ Error: unable to locate %s
|
||||
logger.debug('test5')
|
||||
self.assertEquals(sio.getvalue(),
|
||||
'test1\ntest3\ntest4\n')
|
||||
# make sure access lvl logs by default
|
||||
logger.access('test6')
|
||||
# make sure notice lvl logs by default
|
||||
logger.notice('test7')
|
||||
self.assertEquals(sio.getvalue(),
|
||||
'test1\ntest3\ntest4\ntest6\n')
|
||||
|
||||
|
@ -1802,11 +1802,12 @@ class TestObjectController(unittest.TestCase):
|
||||
|
||||
class Logger(object):
|
||||
|
||||
def access(self, msg):
|
||||
def info(self, msg):
|
||||
self.msg = msg
|
||||
|
||||
orig_logger = prosrv.logger
|
||||
prosrv.logger = Logger()
|
||||
orig_access_logger = prosrv.access_logger
|
||||
prosrv.logger = prosrv.access_logger = Logger()
|
||||
sock = connect_tcp(('localhost', prolis.getsockname()[1]))
|
||||
fd = sock.makefile()
|
||||
fd.write(
|
||||
@ -1822,11 +1823,13 @@ class TestObjectController(unittest.TestCase):
|
||||
prosrv.logger.msg)
|
||||
exp = 'host1'
|
||||
self.assertEquals(prosrv.logger.msg[:len(exp)], exp)
|
||||
prosrv.access_logger = orig_access_logger
|
||||
prosrv.logger = orig_logger
|
||||
# Turn on header logging.
|
||||
|
||||
orig_logger = prosrv.logger
|
||||
prosrv.logger = Logger()
|
||||
orig_access_logger = prosrv.access_logger
|
||||
prosrv.logger = prosrv.access_logger = Logger()
|
||||
prosrv.log_headers = True
|
||||
sock = connect_tcp(('localhost', prolis.getsockname()[1]))
|
||||
fd = sock.makefile()
|
||||
@ -1840,6 +1843,7 @@ class TestObjectController(unittest.TestCase):
|
||||
self.assert_('Goofy-Header%3A%20True' in prosrv.logger.msg,
|
||||
prosrv.logger.msg)
|
||||
prosrv.log_headers = False
|
||||
prosrv.access_logger = orig_access_logger
|
||||
prosrv.logger = orig_logger
|
||||
|
||||
def test_chunked_put_utf8_all_the_way_down(self):
|
||||
|
Loading…
x
Reference in New Issue
Block a user