Merge "add UDP protocol support for logger"

This commit is contained in:
Jenkins 2012-07-12 20:55:07 +00:00 committed by Gerrit Code Review
commit 0ab4f2ab4a
4 changed files with 20 additions and 9 deletions

View File

@ -79,3 +79,4 @@ Ye Jia Xu (xyj.asmy@gmail.com)
Pete Zaitcev (zaitcev@kotori.zaitcev.us)
Josh Kearney (josh@jk0.org)
Vincent Untz (vuntz@suse.com)
Tsuyuzaki Kota (tsuyuzaki.kota@lab.ntt.co.jp)

View File

@ -94,7 +94,8 @@ class ProxyLoggingMiddleware(object):
self.app = app
self.log_hdrs = conf.get('log_headers', 'no').lower() in TRUE_VALUES
access_log_conf = {}
for key in ('log_facility', 'log_name', 'log_level'):
for key in ('log_facility', 'log_name', 'log_level', 'log_udp_host',
'log_udp_port'):
value = conf.get('access_' + key, conf.get(key, None))
if value:
access_log_conf[key] = value

View File

@ -533,6 +533,8 @@ def get_logger(conf, name=None, log_to_console=False, log_route=None,
log_facility = LOG_LOCAL0
log_level = INFO
log_name = swift
log_udp_host = (disabled)
log_udp_port = logging.handlers.SYSLOG_UDP_PORT
log_statsd_host = (disabled)
log_statsd_port = 8125
log_statsd_default_sample_rate = 1
@ -564,13 +566,19 @@ def get_logger(conf, name=None, log_to_console=False, log_route=None,
# facility for this logger will be set by last call wins
facility = getattr(SysLogHandler, conf.get('log_facility', 'LOG_LOCAL0'),
SysLogHandler.LOG_LOCAL0)
log_address = conf.get('log_address', '/dev/log')
try:
handler = SysLogHandler(address=log_address, facility=facility)
except socket.error, e:
if e.errno != errno.ENOTSOCK: # Socket operation on non-socket
raise e
handler = SysLogHandler(facility=facility)
udp_host = conf.get('log_udp_host')
if udp_host:
udp_port = conf.get('log_udp_port', logging.handlers.SYSLOG_UDP_PORT)
handler = SysLogHandler(address=(udp_host, udp_port),
facility=facility)
else:
log_address = conf.get('log_address', '/dev/log')
try:
handler = SysLogHandler(address=log_address, facility=facility)
except socket.error, e:
if e.errno != errno.ENOTSOCK: # Socket operation on non-socket
raise e
handler = SysLogHandler(facility=facility)
handler.setFormatter(formatter)
logger.addHandler(handler)
get_logger.handler4logger[logger] = handler

View File

@ -1870,7 +1870,8 @@ class BaseApplication(object):
if logger is None:
self.logger = get_logger(conf, log_route='proxy-server')
access_log_conf = {}
for key in ('log_facility', 'log_name', 'log_level'):
for key in ('log_facility', 'log_name', 'log_level',
'log_udp_host', 'log_udp_port'):
value = conf.get('access_' + key, conf.get(key, None))
if value:
access_log_conf[key] = value