def run(): out = StringIO() log.addHandler(StreamHandler(out)) with LoggingHandler(): for x in xrange(500): log.warning('this is not handled') assert out.getvalue().count('\n') == 500
def setUp(self): super(StepTest, self).setUp() self._handler = LoggingHandler() self._handler.push_application() self.actions = { 'start': False, 'error': False, 'end': False, 'success': False } @gossip.register('slash.step_start', token="step") def step_start(): self.actions['start'] = True @gossip.register('slash.step_end', token="step") def step_end(): self.actions['end'] = True @gossip.register('slash.step_success', token="step") def step_success(): self.actions['success'] = True self._verify(end=False) @gossip.register('slash.step_error', token="step") def step_error(): self.actions['error'] = True self._verify(success=False, end=False, error=True)
def setUp(self): super(TestCase, self).setUp() self._handler = LoggingHandler() self._handler.push_application() self.override_config("hooks.swallow_exceptions", False) self.override_config("log.console_level", 10000) # silence console in tests
def setUp(self): super(TestCase, self).setUp() self._handler = LoggingHandler() self._handler.push_application() self.addCleanup(self._handler.pop_application) gossip.get_group('slash').set_exception_policy( gossip.RaiseImmediately()) self.override_config("log.console_level", 10000) # silence console in tests
def test_redirect_logbook(self): import logging from logbook.compat import LoggingHandler out = StringIO() logger = logging.getLogger() old_handlers = logger.handlers[:] handler = logging.StreamHandler(out) handler.setFormatter(logging.Formatter( '%(name)s:%(levelname)s:%(message)s')) logger.handlers[:] = [handler] try: with LoggingHandler(): self.log.warn("This goes to logging") pieces = out.getvalue().strip().split(':') self.assertEqual(pieces, [ 'testlogger', 'WARNING', 'This goes to logging' ]) finally: logger.handlers[:] = old_handlers
from pathlib import Path from logbook.compat import LoggingHandler from aiohttp.web import Application from aiogram import Bot, Dispatcher from aiogram.contrib.middlewares.i18n import I18nMiddleware from .conf import config PROJECT_NAME = 'alarmbot' LOCALES_DIR = Path(__file__).parent.parent / 'locales' app = Application() # Initialize bot and dispatcher bot = Bot(token=config.TELEGRAM_TOKEN) dp = Dispatcher(bot) i18n = I18nMiddleware(PROJECT_NAME, LOCALES_DIR) dp.middleware.setup(i18n) LoggingHandler().push_application()
ctx = process_algo_params(ctx, **kwargs) algorithm = ctx.algorithm algomodule = ctx.algomodule with LiveTraderAPI(algorithm): start_shell(algorithm, algomodule) @click.command() def version(): from ._version import VERSION click.echo('v{}'.format(VERSION)) def extract_filename(algofile): algofilename = algofile algofilename = os.path.basename(algofilename) if '.py' in algofilename: algofilename = algofilename[:-3] return algofilename main.add_command(run) main.add_command(shell) main.add_command(version) if __name__ == '__main__': from logbook.compat import LoggingHandler with LoggingHandler(): main()