Beispiel #1
0
 def __init__(self,
              module_name_filters=(default_module_name_filter, ),
              module_filters=(),
              recursive=True):
     self._module_name_filters = list(module_name_filters)
     self._module_fiters = list(module_filters)
     self._recursive = recursive
     self._logger = logging.get_logger(self.__class__.__name__)
Beispiel #2
0
def test_get_logger_returns_a_console_logger_when_log_file_is_none(
        capsys, patched_config_dict):
    patched_config_dict['log_file'] = None
    l = logging.get_logger('test_name0')
    test_message = 'this is a test message'
    l.error(test_message)
    capted = capsys.readouterr()
    assert test_message in capted.out
Beispiel #3
0
def test_log_exception_does_log_and_suppresses(capsys):
    logger = logging.get_logger("name1")
    exception_message = "This is a message"
    with logging.log_exception(logger, to_suppress=(Exception, )):
        raise Exception(exception_message)
    output = capsys.readouterr().out
    assert exception_message in output
    assert 'ERROR' in output
Beispiel #4
0
def test_log_exception_does_log(capsys):
    logger = logging.get_logger("name")
    exception_message = "This is a message"
    with pytest.raises(Exception):
        with logging.log_exception(logger):
            raise Exception(exception_message)
    output = capsys.readouterr().out
    assert exception_message in output
    assert 'ERROR' in output
Beispiel #5
0
def test_log_exception_does_not_log_on_ignore(capsys):
    logger = logging.get_logger("name2")
    typeerror_message = "this is a TypeError"
    with pytest.raises(TypeError):
        with logging.log_exception(logger, to_ignore=(TypeError, )):
            raise TypeError(typeerror_message)
    output = capsys.readouterr().out
    assert typeerror_message not in output
    assert 'ERROR' not in output
Beispiel #6
0
def test_get_logger_returns_a_file_logger_when_log_file_in_config(
        patched_config_dict):
    t = tempfile.mktemp()
    patched_config_dict['log_file'] = t
    l = logging.get_logger('test_name2')
    test_message = 'this is a test message'
    l.error(test_message)
    with open(t) as f:
        assert test_message in f.read()
    os.unlink(t)
Beispiel #7
0
def test_get_logger_returns_a_console_logger_when_log_file_not_in_config(
        capsys, patched_config_dict):
    with contextlib.suppress():
        patched_config_dict.pop('log_file')
    l = logging.get_logger('test_name1')
    test_message = 'this is a test message'
    l.error(test_message)

    capted = capsys.readouterr()
    assert test_message in capted.out
Beispiel #8
0
 def __init__(self, params, handlers=None, exchange=None):
     """
     creates a new consumer. a consumer is a threaded entity that can handle many channels at once.
     :param params: the pika connection params to the server
     :param handlers: topic -> (lambda message, decoder) map, as would be passed individually to self.register
     """
     self._logger = get_logger(self.__class__.__name__)
     self._connection_params = params
     self._connection_lock = threading.Lock()
     self._io_list_lock = threading.Lock()
     self._connection = None
     self.handlers = handlers or {}
     self.thread_prefix = f"rabbitmq-consumer-{''.join(random.sample(string.ascii_lowercase, 5))}"
     self._running = False
     self._exchange = exchange or self.Exchange
     self._ensure_connection()
Beispiel #9
0
import functools
import json
import pathlib
import time
import click
import urlpath
from contextlib import suppress

from . import repository, db_dispatcher
from cortex import configuration
from cortex.utils import logging, dispatchers, databases
from cortex.utils.plugin_runner import PluginRunner

module_logger = logging.get_logger(__file__)

@click.group("parsers")
def cli():
    pass


def _get_db_or_die(url):
    db = databases.repository.get_database(url)
    if not db:
        click.prompt(f"Error: no DB for url {url}")
        exit(-1)
    return db

@cli.command('save')
@click.argument('name')
@click.argument('path', type=click.Path(exists=True))
@click.option('-d', '--database', type=urlpath.URL)
Beispiel #10
0
def test_get_logger_registers_custom_handlers():
    mock = MagicMock(spec=logging.logging.Handler)
    mock.level = logging.logging.INFO
    l = logging.get_logger('test_name3', custom_handlers=(mock, ))
    assert mock in l.handlers
Beispiel #11
0
def test_get_logger_sets_logger_name():
    assert logging.get_logger('test_name').name == 'test_name'