Example #1
0
 def test_set_bad_level(self):
     w = Wryte(name=str(uuid.uuid4()))
     assert w.logger.getEffectiveLevel() == 20
     w.set_level('deboog')
     assert w.logger.getEffectiveLevel() == 20
Example #2
0
 def test_set_bad_level(self):
     w = Wryte(name=str(uuid.uuid4()))
     with pytest.raises(ValueError):
         w.set_level('deboog')
Example #3
0

def read_config(path):
    wryter.info('Loading application configuration...')
    wryter.debug('Reading Config {0}'.format(path))
    # ...
    raise Exception('Enabling Debug...')


config_file_read = False

wryter.info('Starting application...')

try:
    config = read_config(PATH)
    config_file_read = True
except Exception as ex:
    # Can also pass `set_level` to `critical`, not just to `error`.
    wryter.error('Failed to read config ({})'.format(ex),
                 {'context': 'some_context'},
                 _set_level='debug')
    # do_something to reread the file, but this time with debug logging enabled.
    config = read_config(PATH)
    config_file_read = True
finally:
    if config_file_read:
        wryter.info('Success loading config...')
        wryter.set_level('info')
    else:
        raise RuntimeError('Completely failed to read config')
Example #4
0
 def test_set_level(self):
     w = Wryte(name=str(uuid.uuid4()))
     assert w.get_level() == logging.INFO
     w.set_level('debug')
     assert w.get_level() == logging.DEBUG