Exemplo n.º 1
0
 def test_minimal_logger(self):
     log = misc.minimal_logger(__name__)
     log = misc.minimal_logger(__name__, debug=True)
 
     # set logging back to non-debug
     misc.minimal_logger(__name__, debug=False)
     pass
Exemplo n.º 2
0
def test_minimal_logger_logging_is_enabled(caplog):
    with patch('cement.utils.misc.MinimalLogger.logging_is_enabled',
               new_callable=PropertyMock) as mock:
        mock.return_value = True

        log = misc.minimal_logger(__name__, True)

        log.info('info test')
        log.warning('warning test')
        log.error('error test')
        log.fatal('fatal test')
        log.debug('debug test')

        assert (__name__, 20, 'info test') in caplog.record_tuples
        assert (__name__, 30, 'warning test') in caplog.record_tuples
        assert (__name__, 40, 'error test') in caplog.record_tuples
        assert (__name__, 50, 'fatal test') in caplog.record_tuples
        assert (__name__, 10, 'debug test') in caplog.record_tuples

        mock.return_value = False
        log.info('do not log this')
        log.warning('do not log this')
        log.error('do not log this')
        log.fatal('do not log this')
        log.debug('do not log this')
        for logged in caplog.record_tuples:
            assert logged[2] != 'do not log this'
Exemplo n.º 3
0
Arquivo: log.py Projeto: tpoeppke/reds
def get_logger(name):
    """Returns the logger from Cement with proper console format."""
    console_formatter = logging.Formatter("%(message)s")
    logger = minimal_logger(name)
    # The first handler is the console handler and we want clean output 
    # to the console.
    logger.backend.handlers[0].setFormatter(console_formatter)
    return logger
Exemplo n.º 4
0
    def test_minimal_logger(self):
        log = misc.minimal_logger(__name__)
        log = misc.minimal_logger(__name__, debug=True)
        log.info('info test')
        log.warning('warning test')
        log.error('error test')
        log.fatal('fatal test')
        log.debug('debug test')

        log.info('info test with namespce', 'test_namespace')

        log.info('info test with extra kwargs', extra=dict(foo='bar'))

        log.info('info test with extra kwargs', extra=dict(namespace='foo'))

        # set logging back to non-debug
        misc.minimal_logger(__name__, debug=False)
Exemplo n.º 5
0
    def test_minimal_logger(self):
        log = misc.minimal_logger(__name__)
        log = misc.minimal_logger(__name__, debug=True)
        log.info("info test")
        log.warn("warn test")
        log.error("error test")
        log.fatal("fatal test")
        log.debug("debug test")

        log.info("info test with namespce", "test_namespace")

        log.info("info test with extra kwargs", extra=dict(foo="bar"))

        log.info("info test with extra kwargs", extra=dict(namespace="foo"))

        # set logging back to non-debug
        misc.minimal_logger(__name__, debug=False)
        pass
Exemplo n.º 6
0
    def test_framework_logging_is_true(self):
        del os.environ['CEMENT_FRAMEWORK_LOGGING']

        app = self.make_app(APP, argv=None, framework_logging=True)
        app.setup()
        self.eq(os.environ['CEMENT_FRAMEWORK_LOGGING'], '1')

        ml = minimal_logger(__name__)
        self.eq(ml.logging_is_enabled, True)
Exemplo n.º 7
0
def test_framework_logging():
    # is true

    del os.environ['CEMENT_FRAMEWORK_LOGGING']

    with TestApp(framework_logging=True):
        assert os.environ['CEMENT_FRAMEWORK_LOGGING'] == '1'

    ml = minimal_logger(__name__)
    assert ml.logging_is_enabled is True

    # is false

    del os.environ['CEMENT_FRAMEWORK_LOGGING']

    with TestApp(framework_logging=False):
        assert os.environ['CEMENT_FRAMEWORK_LOGGING'] == '0'

    ml = minimal_logger(__name__)
    assert ml.logging_is_enabled is False
Exemplo n.º 8
0
    def test_framework_logging_is_false(self):
        del os.environ['CEMENT_FRAMEWORK_LOGGING']

        app = self.make_app(APP, argv=None, framework_logging=False)
        app.setup()
        self.eq(os.environ['CEMENT_FRAMEWORK_LOGGING'], '0')

        ml = minimal_logger(__name__)
        self.eq(ml.logging_is_enabled, False)

        # coverage... should default to True if no key in os.environ
        del os.environ['CEMENT_FRAMEWORK_LOGGING']
        self.eq(ml.logging_is_enabled, True)
Exemplo n.º 9
0
def test_minimal_logger_with_arguments(caplog):
    with patch('cement.utils.misc.MinimalLogger.logging_is_enabled',
               new_callable=PropertyMock) as mock:
        log = misc.minimal_logger(__name__)
        mock.return_value = True

        log.info('info test with namespace', 'test_namespace')
        assert caplog.records[0].namespace == 'test_namespace'
        assert caplog.records[0].message == 'info test with namespace'

        log.info('info test with extra kwargs', extra=dict(foo='bar'))
        assert caplog.records[1].foo == 'bar'

        log.info('info test with extra kwargs', extra=dict(namespace='foo'))
        assert caplog.records[2].namespace == 'foo'
Exemplo n.º 10
0
def test_minimal_logger_get_kwargs():
    log = misc.minimal_logger(__name__)

    # no keywords
    kw = log._get_logging_kwargs(__name__ + '.bogus')
    assert 'extra' in kw.keys()
    assert kw['extra']['namespace'] == __name__ + '.bogus'

    # keywords with extra
    extra_dict = {'extra': {}}
    kw = log._get_logging_kwargs(__name__ + '.bogus', **extra_dict)
    assert kw['extra']['namespace'] == __name__ + '.bogus'

    # keywords with extra and namespace
    extra_dict = {'extra': {'namespace': __name__ + '.fake'}}
    kw = log._get_logging_kwargs('fake', **extra_dict)
    assert kw['extra']['namespace'] == __name__ + '.fake'
Exemplo n.º 11
0
import re

from cement.utils.misc import minimal_logger

from ebcli.core import io
from ebcli.core.ebglobals import Constants
from ebcli.lib import elasticbeanstalk, heuristics, utils
from ebcli.objects.exceptions import NotFoundError
from ebcli.objects.platform import PlatformVersion
from ebcli.objects.solutionstack import SolutionStack
from ebcli.operations import commonops, platformops
from ebcli.resources.strings import prompts, strings

CUSTOM_PLATFORM_OPTION = 'Custom Platform'

LOG = minimal_logger(__name__)


def get_default_solution_stack():
	return commonops.get_config_setting_from_branch_or_default('default_platform')


def find_solution_stack_from_string(solution_string, find_newer=False):
	"""
	Method returns a SolutionStack object representing the given `solution_string`.

	If the `solution_string` matches ARNs and complete names of solution stacks, the exact
	match is returned. In the event when there are multiple matches, the latest version is
	returned.

	:param solution_string: A string in one of the following (case-insensitive) forms:
Exemplo n.º 12
0
from dateutil import tz, parser
import locale
import threading
import traceback

from botocore.compat import six
from cement.utils.misc import minimal_logger
import copy

from ebcli.lib import elasticbeanstalk, utils
from ebcli.lib.aws import InvalidParameterValueError
from ebcli.resources.strings import responses

Queue = six.moves.queue.Queue
locale.setlocale(locale.LC_ALL, 'C')
LOG = minimal_logger(__name__)


class DataPoller(object):
    def __init__(self, app_name, env_name):
        locale.setlocale(locale.LC_TIME, 'C')
        self.app_name = app_name
        self.env_name = env_name
        self.data_queue = Queue()
        self.data = None
        self.no_instances_time = None
        self.instance_info = defaultdict(dict)

    def get_fresh_data(self):
        new_data = self.data
        while not self.data_queue.empty() or new_data is None:
Exemplo n.º 13
0
 def test_minimal_logger_deprecated_warn(self):
     log = misc.minimal_logger(__name__)
     log.warn('warning test')