add UDP protocol support for logger

When a syslog daemon fails and SysLogHandler cannot reconnect to
it, server processes (proxy, container, object, and more)
would start consuming 100 % CPU and stop responding to requests.
It is because the server process go into an infinite loop if they
fail to reconnect to /dev/log.
This problem happens only when using unix_sockets.

This change enables us to use syslog without unix_sockets and fixes bug 780025.

Change-Id: Ibcc99a1a148b1008036146bf3bd079a9be24982c
This commit is contained in:
Kota Tsuyuzaki 2012-06-22 04:47:52 -07:00
parent fcab7b7358
commit f0eb25a973
4 changed files with 20 additions and 9 deletions

View File

@ -78,3 +78,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

@ -511,6 +511,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
@ -542,13 +544,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

@ -1865,7 +1865,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