Ejemplo n.º 1
0
  def testConfigureLoggingWithUnknownCustomFacility(self):
    """Test ConfigureLogging custom syslog facility."""
    self.StubSetup()
    self.mox.StubOutWithMock(gmacpyutil, '_ConfigureHandler')
    self.mox.StubOutWithMock(gmacpyutil, 'MultilineSysLogHandler')
    self.mox.StubOutWithMock(gmacpyutil.logging.handlers, 'SysLogHandler')
    gmacpyutil.logging.handlers.SysLogHandler.LOG_USER = 1
    gmacpyutil.logging.handlers.SysLogHandler.facility_names = {'known': 999}

    mock_syslog = self.mox.CreateMockAnything()
    mock_logger = self.mox.CreateMockAnything()

    stream_handler = self.mox.CreateMock(gmacpyutil.logging.StreamHandler)
    mock_logger.handlers = [stream_handler]

    gmacpyutil.logging.getLogger().AndReturn(mock_logger)
    mock_logger.setLevel(mox.IgnoreArg())

    gmacpyutil.logging.error(mox.IgnoreArg(), mox.IgnoreArg())
    gmacpyutil.MultilineSysLogHandler(facility=1).AndReturn(mock_syslog)
    gmacpyutil._ConfigureHandler(mock_syslog, mock_logger,
                                 gmacpyutil.LOG_FORMAT_SYSLOG, mox.IgnoreArg())

    gmacpyutil.logging.StreamHandler().AndReturn(stream_handler)
    gmacpyutil._ConfigureHandler(stream_handler, mock_logger,
                                 mox.IgnoreArg(), mox.IgnoreArg())

    gmacpyutil.logging.debug(mox.IgnoreArg(), mox.IgnoreArg())

    self.mox.ReplayAll()
    self.assertEqual(None, gmacpyutil.ConfigureLogging(facility='unknown'))
    self.mox.VerifyAll()
Ejemplo n.º 2
0
  def testConfigureLogging(self):
    """Test ConfigureLogging, syslog and stderr, debug log level."""
    self.StubSetup()
    self.mox.StubOutWithMock(gmacpyutil, '_ConfigureHandler')
    self.mox.StubOutWithMock(gmacpyutil, 'MultilineSysLogHandler')
    self.mox.StubOutWithMock(gmacpyutil.logging.handlers, 'SysLogHandler')
    gmacpyutil.logging.handlers.SysLogHandler.LOG_USER = 1

    level = gmacpyutil.logging.DEBUG
    mock_syslog = self.mox.CreateMockAnything()
    mock_logger = self.mox.CreateMockAnything()

    stream_handler = self.mox.CreateMock(gmacpyutil.logging.StreamHandler)
    stream_handler2 = self.mox.CreateMock(gmacpyutil.logging.StreamHandler)
    mock_logger.handlers = [stream_handler, stream_handler2]

    gmacpyutil.logging.getLogger().AndReturn(mock_logger)
    mock_logger.setLevel(level)

    gmacpyutil.MultilineSysLogHandler(facility=1).AndReturn(mock_syslog)
    gmacpyutil._ConfigureHandler(mock_syslog, mock_logger,
                                 gmacpyutil.LOG_FORMAT_SYSLOG, level)

    gmacpyutil.logging.StreamHandler().AndReturn(stream_handler)
    gmacpyutil._ConfigureHandler(stream_handler, mock_logger,
                                 gmacpyutil.LOG_FORMAT_STDERR, level)

    gmacpyutil.logging.debug('Logging enabled at level %s', level)
    self.mox.ReplayAll()
    self.assertEqual(None, gmacpyutil.ConfigureLogging(debug_level=level,
                                                       show_level=False))
    self.mox.VerifyAll()
Ejemplo n.º 3
0
    def testConfigureLogging(self):
        """Test ConfigureLogging, syslog and stderr, debug log level."""
        self.StubSetup()
        self.mox.StubOutWithMock(gmacpyutil, '_ConfigureHandler')
        self.mox.StubOutWithMock(gmacpyutil, 'MultilineSysLogHandler')
        self.mox.StubOutWithMock(gmacpyutil.logging.handlers, 'SysLogHandler')
        gmacpyutil.logging.handlers.SysLogHandler.LOG_USER = 1

        level = gmacpyutil.logging.DEBUG
        mock_syslog = self.mox.CreateMockAnything()
        mock_logger = self.mox.CreateMockAnything()

        stream_handler = self.mox.CreateMock(gmacpyutil.logging.StreamHandler)
        stream_handler2 = self.mox.CreateMock(gmacpyutil.logging.StreamHandler)
        mock_logger.handlers = [stream_handler, stream_handler2]

        gmacpyutil.logging.getLogger().AndReturn(mock_logger)
        mock_logger.setLevel(level)

        gmacpyutil.MultilineSysLogHandler(facility=1).AndReturn(mock_syslog)
        gmacpyutil._ConfigureHandler(mock_syslog, mock_logger,
                                     gmacpyutil.LOG_FORMAT_SYSLOG, level)

        gmacpyutil.logging.StreamHandler().AndReturn(stream_handler)
        gmacpyutil._ConfigureHandler(stream_handler, mock_logger,
                                     gmacpyutil.LOG_FORMAT_STDERR, level)

        gmacpyutil.logging.debug('Logging enabled at level %s', level)
        self.mox.ReplayAll()
        self.assertEqual(
            None,
            gmacpyutil.ConfigureLogging(debug_level=level, show_level=False))
        self.mox.VerifyAll()
Ejemplo n.º 4
0
    def testConfigureLoggingStderrNoExisting(self):
        self.StubSetup()
        self.mox.StubOutWithMock(gmacpyutil, '_ConfigureHandler')

        level = gmacpyutil.logging.DEBUG
        mock_logger = self.mox.CreateMockAnything()

        stream_handler = self.mox.CreateMock(gmacpyutil.logging.StreamHandler)
        mock_logger.handlers = []

        gmacpyutil.logging.getLogger().AndReturn(mock_logger)
        mock_logger.setLevel(level)

        gmacpyutil.logging.StreamHandler().AndReturn(stream_handler)
        gmacpyutil._ConfigureHandler(stream_handler, mock_logger,
                                     gmacpyutil.LOG_FORMAT_STDERR_LEVEL, level)

        gmacpyutil.logging.debug('Logging enabled at level %s', level)
        self.mox.ReplayAll()
        self.assertEqual(
            None,
            gmacpyutil.ConfigureLogging(debug_level=level,
                                        stderr=True,
                                        syslog=False))
        self.mox.VerifyAll()
Ejemplo n.º 5
0
    def testConfigureLoggingWithUnknownCustomFacility(self):
        """Test ConfigureLogging custom syslog facility."""
        self.StubSetup()
        self.mox.StubOutWithMock(gmacpyutil, '_ConfigureHandler')
        self.mox.StubOutWithMock(gmacpyutil, 'MultilineSysLogHandler')
        self.mox.StubOutWithMock(gmacpyutil.logging.handlers, 'SysLogHandler')
        gmacpyutil.logging.handlers.SysLogHandler.LOG_USER = 1
        gmacpyutil.logging.handlers.SysLogHandler.facility_names = {
            'known': 999
        }

        mock_syslog = self.mox.CreateMockAnything()
        mock_logger = self.mox.CreateMockAnything()

        stream_handler = self.mox.CreateMock(gmacpyutil.logging.StreamHandler)
        mock_logger.handlers = [stream_handler]

        gmacpyutil.logging.getLogger().AndReturn(mock_logger)
        mock_logger.setLevel(mox.IgnoreArg())

        gmacpyutil.logging.error(mox.IgnoreArg(), mox.IgnoreArg())
        gmacpyutil.MultilineSysLogHandler(facility=1).AndReturn(mock_syslog)
        gmacpyutil._ConfigureHandler(mock_syslog, mock_logger,
                                     gmacpyutil.LOG_FORMAT_SYSLOG,
                                     mox.IgnoreArg())

        gmacpyutil.logging.StreamHandler().AndReturn(stream_handler)
        gmacpyutil._ConfigureHandler(stream_handler, mock_logger,
                                     mox.IgnoreArg(), mox.IgnoreArg())

        gmacpyutil.logging.debug(mox.IgnoreArg(), mox.IgnoreArg())

        self.mox.ReplayAll()
        self.assertEqual(None, gmacpyutil.ConfigureLogging(facility='unknown'))
        self.mox.VerifyAll()
Ejemplo n.º 6
0
  def testConfigureHandler(self):
    formatter = self.mox.CreateMock(gmacpyutil.logging.Formatter)
    self.StubSetup()
    debug_level = gmacpyutil.logging.INFO

    logger = self.mox.CreateMockAnything()
    handler = self.mox.CreateMockAnything()

    gmacpyutil.logging.Formatter(
        gmacpyutil.LOG_FORMAT_SYSLOG).AndReturn(formatter)
    handler.setFormatter(formatter)
    handler.setLevel(debug_level)
    logger.addHandler(handler)

    self.mox.ReplayAll()
    gmacpyutil._ConfigureHandler(handler, logger,
                                 gmacpyutil.LOG_FORMAT_SYSLOG, debug_level)
    self.mox.VerifyAll()
Ejemplo n.º 7
0
    def testConfigureHandler(self):
        formatter = self.mox.CreateMock(gmacpyutil.logging.Formatter)
        self.StubSetup()
        debug_level = gmacpyutil.logging.INFO

        logger = self.mox.CreateMockAnything()
        handler = self.mox.CreateMockAnything()

        gmacpyutil.logging.Formatter(
            gmacpyutil.LOG_FORMAT_SYSLOG).AndReturn(formatter)
        handler.setFormatter(formatter)
        handler.setLevel(debug_level)
        logger.addHandler(handler)

        self.mox.ReplayAll()
        gmacpyutil._ConfigureHandler(handler, logger,
                                     gmacpyutil.LOG_FORMAT_SYSLOG, debug_level)
        self.mox.VerifyAll()
Ejemplo n.º 8
0
  def testConfigureLoggingStderrNoExisting(self):
    self.StubSetup()
    self.mox.StubOutWithMock(gmacpyutil, '_ConfigureHandler')

    level = gmacpyutil.logging.DEBUG
    mock_logger = self.mox.CreateMockAnything()

    stream_handler = self.mox.CreateMock(gmacpyutil.logging.StreamHandler)
    mock_logger.handlers = []

    gmacpyutil.logging.getLogger().AndReturn(mock_logger)
    mock_logger.setLevel(level)

    gmacpyutil.logging.StreamHandler().AndReturn(stream_handler)
    gmacpyutil._ConfigureHandler(stream_handler, mock_logger,
                                 gmacpyutil.LOG_FORMAT_STDERR_LEVEL, level)

    gmacpyutil.logging.debug('Logging enabled at level %s', level)
    self.mox.ReplayAll()
    self.assertEqual(None, gmacpyutil.ConfigureLogging(debug_level=level,
                                                       stderr=True,
                                                       syslog=False))
    self.mox.VerifyAll()