1
From fa2a6c6b6aee59b1a98fa7b93f55405457449bf0 Mon Sep 17 00:00:00 2001
2
From: Edward Hope-Morley <edward.hope-morley@canonical.com>
3
Date: Thu, 18 Jun 2015 13:38:58 +0100
4
Subject: [PATCH] Add support for syslog connect retries
6
If we have requested logging to syslog and syslog is
7
not yet ready we shoudl allow for retry attempts. This
8
patch provides a new option syslog-connect-retries to
9
allow for retries with a 5 second interval between
13
Co-authored-by: Liang Chen <liang.chen@canonical.com>
15
nova/openstack/common/log.py
17
Change-Id: I88269a75c56c68443230620217a469aebee523f8
19
nova/openstack/common/log.py | 58 +++++++++++++++++++++++++++++++++++---------
20
1 file changed, 46 insertions(+), 12 deletions(-)
22
diff --git a/nova/openstack/common/log.py b/nova/openstack/common/log.py
23
index cdc439a..71700b7 100644
24
--- a/nova/openstack/common/log.py
25
+++ b/nova/openstack/common/log.py
26
@@ -34,7 +34,9 @@ import logging.config
27
import logging.handlers
35
from oslo.config import cfg
36
@@ -118,6 +120,10 @@ logging_cli_opts = [
37
help='Use syslog for logging. '
38
'Existing syslog format is DEPRECATED during I, '
39
'and then will be changed in J to honor RFC5424'),
40
+ cfg.IntOpt('syslog-connect-retries',
42
+ help='Number of attempts with a five second interval to retry '
43
+ 'connecting to syslog. (if use-syslog=True)'),
44
cfg.BoolOpt('use-syslog-rfc-format',
45
# TODO(bogdando) remove or use True after existing
46
# syslog format deprecation in J
47
@@ -490,18 +496,6 @@ def _setup_logging_from_conf():
48
for handler in log_root.handlers:
49
log_root.removeHandler(handler)
52
- facility = _find_facility_from_conf()
53
- # TODO(bogdando) use the format provided by RFCSysLogHandler
54
- # after existing syslog format deprecation in J
55
- if CONF.use_syslog_rfc_format:
56
- syslog = RFCSysLogHandler(address='/dev/log',
59
- syslog = logging.handlers.SysLogHandler(address='/dev/log',
61
- log_root.addHandler(syslog)
63
logpath = _get_log_file_path()
65
filelog = logging.handlers.WatchedFileHandler(logpath)
66
@@ -548,6 +542,46 @@ def _setup_logging_from_conf():
67
logger = logging.getLogger(mod)
68
logger.setLevel(level)
71
+ retries = CONF.syslog_connect_retries
72
+ syslog_ready = False
75
+ facility = _find_facility_from_conf()
76
+ # TODO(bogdando) use the format provided by RFCSysLogHandler
77
+ # after existing syslog format deprecation in J
78
+ if CONF.use_syslog_rfc_format:
79
+ syslog = RFCSysLogHandler(address='/dev/log',
82
+ syslog = logging.handlers.SysLogHandler(address='/dev/log',
84
+ log_root.addHandler(syslog)
86
+ except socket.error:
87
+ if CONF.syslog_connect_retries <= 0:
88
+ log_root.error(_('Connection to syslog failed and no '
89
+ 'retry attempts requested'))
93
+ log_root.info(_('Connection to syslog failed - '
94
+ 'retrying in 5 seconds'))
97
+ log_root.error(_('Connection to syslog failed and '
98
+ 'max retry attempts reached'))
105
+ if not syslog_ready:
106
+ log_root.error(_('Unable to add syslog handler. Verify that '
107
+ 'syslog is running.'))