def test_stream_handler(self): with mock.patch('sys.stderr', new_callable=six.StringIO) as m_stderr: LoggingApp().init(use_test_profile=True) log.warning(u'test warn log') log.info(u'test info log') output = m_stderr.getvalue().strip().splitlines() assert len(output) == 2, output assert output[0] == 'WARNING - keg_apps.logging - test warn log' assert output[1] == 'INFO - keg_apps.logging - test info log'
def test_syslog_handler(self): with mock.patch('keg.logging.SysLogHandler.emit') as m_emit: LoggingApp().init(use_test_profile=True, config={'KEG_LOG_SYSLOG_ENABLED': True}) log.warning('test warn log') log.info('test info log') calls = m_emit.call_args_list assert len(calls) == 2 args, kwargs = calls[0] log_record = args[0] assert log_record.message == 'test warn log' args, kwargs = calls[1] log_record = args[0] assert log_record.message == 'test info log'
def test_default_log_file(self, tmpdir): tmpdir = str(tmpdir) @signals.config_ready.connect def apply_config(app): app.config['KEG_LOG_DPATH'] = tmpdir app = LoggingApp().init() log.warning('test warn log') log.info('test info log') log_fpath = pathlib.Path(app.logging.log_fpath()) with log_fpath.open('r', encoding='utf-8') as fh: contents = fh.read() assert 'test warn log' in contents assert 'test info log' not in contents