3ba00c25e1
(From the original bug report): Currently used pattern in RFCSysLogHandler will fail for Python 2.6.x (using super(RFCSysLogHandler, self)). In order to fix the broken Python 2.6.x compatibility, old style explicit superclass method calls should be used instead. Uses e.g. logging.handlers.SysLogHandler.__init__(self,...) rather than super(RFCSysLogHandler, self).__init__(...) Change-Id: Ia81e00e4a7763a887703d0ef83e475f314eab28d Closes-Bug: #1306559
48 lines
2.1 KiB
Python
48 lines
2.1 KiB
Python
# Copyright (c) 2014 Hewlett-Packard Development Company, L.P.
|
|
#
|
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
# you may not use this file except in compliance with the License.
|
|
# You may obtain a copy of the License at
|
|
#
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
#
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
# implied.
|
|
# See the License for the specific language governing permissions and
|
|
# limitations under the License.
|
|
import logging
|
|
import unittest
|
|
|
|
from muranoapi.openstack.common import log
|
|
|
|
|
|
class SysLogHandlersTestCase(unittest.TestCase):
|
|
"""Test for standard and RFC compliant Syslog handlers."""
|
|
def setUp(self):
|
|
self.facility = logging.handlers.SysLogHandler.LOG_USER
|
|
self.rfclogger = log.RFCSysLogHandler(address='/dev/log',
|
|
facility=self.facility)
|
|
self.rfclogger.binary_name = 'Foo_application'
|
|
self.logger = logging.handlers.SysLogHandler(address='/dev/log',
|
|
facility=self.facility)
|
|
self.logger.binary_name = 'Foo_application'
|
|
|
|
def test_rfc_format(self):
|
|
"""Ensure syslog msg contains APP-NAME for RFC wrapped handler"""
|
|
logrecord = logging.LogRecord('name', 'WARN', '/tmp', 1,
|
|
'Message', None, None)
|
|
expected = logging.LogRecord('name', 'WARN', '/tmp', 1,
|
|
'Foo_application Message', None, None)
|
|
self.assertEqual(self.rfclogger.format(logrecord),
|
|
expected.getMessage())
|
|
|
|
def test_standard_format(self):
|
|
"""Ensure syslog msg isn't modified for standard handler"""
|
|
logrecord = logging.LogRecord('name', 'WARN', '/tmp', 1,
|
|
'Message', None, None)
|
|
expected = logrecord
|
|
self.assertEqual(self.logger.format(logrecord),
|
|
expected.getMessage())
|