def test_get_channel_logger(settings, logging, os): logger = Mock() handler = Mock() formatter = Mock() def os_join(*args): return '/'.join(args) settings.CHANNEL_LOGGING_DIR = '/path/to/channels' settings.CHANNEL_LOGGING_DB = False os.path.exists.return_value = True os.path.join = os_join # Mocked returns logging.getLogger.return_value = logger logging.Formatter.return_value = formatter with patch.object(log, 'ChannelLogFileHandler'): log.ChannelLogFileHandler.return_value = handler log.get_channel_logger('#foo') # Gets the right logger logging.getLogger.assert_called_with('channel_logger/#foo') logger.setLevel.assert_called_with(logging.INFO) assert logger.propagate is False # Sets the handler correctly log.ChannelLogFileHandler.assert_called_with('/path/to/channels/#foo') handler.setFormatter.assert_called_with(formatter) # Sets the formatter correctly logging.Formatter.assert_called_with('%(utctime)s - %(nick)s - %(message)s') # Logger uses the handler logger.addHandler.assert_called_with(handler)
def test_get_channel_logger_creates_log_dirs(settings, logging, os): def os_join(*args): return '/'.join(args) settings.CHANNEL_LOGGING_DIR = '/path/to/channels' settings.CHANNEL_LOGGING_DB = False os.path.exists.return_value = False os.path.join = os_join log.get_channel_logger('#foo') os.makedirs.assert_called_with('/path/to/channels/#foo')
def get_channel_logger(self, channel): """ Gets a channel logger, keeping track of previously requested ones. (see :ref:`builtin.channel_logging`) :param str channel: A channel name """ if channel not in self.channel_loggers: self.channel_loggers[channel] = log.get_channel_logger(channel) return self.channel_loggers[channel]
def get_channel_logger(self, channel): """ Gets a channel logger, keeping track of previously requested ones. (see :ref:`builtin.channel_logging`) :param channel: A channel name :returns: a python logger suitable for channel logging """ if channel not in self.channel_loggers: self.channel_loggers[channel] = log.get_channel_logger(channel) return self.channel_loggers[channel]
def test_get_channel_logger(settings, logging, os): logger = Mock() handler = Mock() formatter = Mock() def os_join(*args): return '/'.join(args) settings.CHANNEL_LOGGING_DIR = '/path/to/channels' settings.CHANNEL_LOGGING_DB = False os.path.exists.return_value = True os.path.join = os_join # Mocked returns logging.getLogger.return_value = logger logging.Formatter.return_value = formatter with patch.object(log, 'ChannelLogFileHandler'): log.ChannelLogFileHandler.return_value = handler log.get_channel_logger('#foo') # Gets the right logger logging.getLogger.assert_called_with('channel_logger/#foo') logger.setLevel.assert_called_with(logging.INFO) assert logger.propagate is False # Sets the handler correctly log.ChannelLogFileHandler.assert_called_with('/path/to/channels/#foo') handler.setFormatter.assert_called_with(formatter) # Sets the formatter correctly logging.Formatter.assert_called_with( '%(utctime)s - %(nick)s - %(message)s') # Logger uses the handler logger.addHandler.assert_called_with(handler)