diff options
author | Zuul <zuul@review.openstack.org> | 2018-11-06 14:29:45 +0000 |
---|---|---|
committer | Gerrit Code Review <review@openstack.org> | 2018-11-06 14:29:45 +0000 |
commit | 059873c93255743efd3dc15e4361f306010961b5 (patch) | |
tree | b57df05ac095ae426b469c01f274d0f53ebc3057 | |
parent | a9ba6c544cbbd4bd804dcd5e38d72106ea0b8b8f (diff) | |
parent | 74e8e48a95e8cd9fa2746ffc32db742061924d93 (diff) | |
download | oslo-log-059873c93255743efd3dc15e4361f306010961b5.tar.gz |
Merge "Add Windows Event Log handler"3.41.0
-rw-r--r-- | oslo_log/_options.py | 3 | ||||
-rw-r--r-- | oslo_log/log.py | 8 | ||||
-rwxr-xr-x[-rw-r--r--] | oslo_log/tests/unit/test_log.py | 19 | ||||
-rw-r--r-- | releasenotes/notes/windows-eventlog-2beb0a6010e342eb.yaml | 4 |
4 files changed, 34 insertions, 0 deletions
diff --git a/oslo_log/_options.py b/oslo_log/_options.py index e216248..8f01043 100644 --- a/oslo_log/_options.py +++ b/oslo_log/_options.py @@ -108,6 +108,9 @@ generic_log_opts = [ default=False, help='Log output to standard error. ' + _IGNORE_MESSAGE), + cfg.BoolOpt('use_eventlog', + default=False, + help='Log output to Windows Event Log.'), ] log_opts = [ diff --git a/oslo_log/log.py b/oslo_log/log.py index b39e821..d663ec4 100644 --- a/oslo_log/log.py +++ b/oslo_log/log.py @@ -361,6 +361,14 @@ def _setup_logging_from_conf(conf, project, version): journal = handlers.OSJournalHandler() log_root.addHandler(journal) + if conf.use_eventlog: + if platform.system() == 'Windows': + eventlog = logging.handlers.NTEventLogHandler(project) + log_root.addHandler(eventlog) + else: + raise RuntimeError(_("Windows Event Log is not available on this " + "platform.")) + # if None of the above are True, then fall back to standard out if not logpath and not conf.use_stderr and not conf.use_journal: # pass sys.stdout as a positional argument diff --git a/oslo_log/tests/unit/test_log.py b/oslo_log/tests/unit/test_log.py index fdaceef..aa3b98c 100644..100755 --- a/oslo_log/tests/unit/test_log.py +++ b/oslo_log/tests/unit/test_log.py @@ -140,6 +140,25 @@ class CommonLoggerTestsMixIn(object): 'info', 'debug', 'log'): self.assertRaises(AttributeError, getattr, log, func) + @mock.patch('platform.system', return_value='Linux') + def test_eventlog_missing(self, platform_mock): + self.config(use_eventlog=True) + self.assertRaises(RuntimeError, + log._setup_logging_from_conf, + self.CONF, + 'test', + 'test') + + @mock.patch('platform.system', return_value='Windows') + @mock.patch('logging.handlers.NTEventLogHandler') + @mock.patch('oslo_log.log.getLogger') + def test_eventlog(self, loggers_mock, handler_mock, platform_mock): + self.config(use_eventlog=True) + log._setup_logging_from_conf(self.CONF, 'test', 'test') + handler_mock.assert_called_once_with('test') + mock_logger = loggers_mock.return_value.logger + mock_logger.addHandler.assert_any_call(handler_mock.return_value) + class LoggerTestCase(CommonLoggerTestsMixIn, test_base.BaseTestCase): def setUp(self): diff --git a/releasenotes/notes/windows-eventlog-2beb0a6010e342eb.yaml b/releasenotes/notes/windows-eventlog-2beb0a6010e342eb.yaml new file mode 100644 index 0000000..ccdfc6f --- /dev/null +++ b/releasenotes/notes/windows-eventlog-2beb0a6010e342eb.yaml @@ -0,0 +1,4 @@ +features: + - | + Added Windows EventLog functionality to oslo.log. Set use_eventlog to true + in the service's configuration file to use it. |