def test_context_type(self): """Test the different types of context * Dicts * Nested dicts * JSON strings * kwargs * kv strings * bad object """ w = Wryte(name=str(uuid.uuid4())) w.info('Message 1', k1='v1', k2='v2') w.info('Message 2', {'k1': 'v1', 'k2': 'v2'}) w.info('Message 3', '{"k1": "v1", "k2": "v2"}') w.info('Message 4', {'k1': 'v1', 'k2': {'k3': 'v3'}}) w.info( 'Message 5', { 'k3': 'v3', 'k4': 'v4' }, { 'k7': 'v7', 'k8': { 'k9': 'v9' } }, '{"k5": "v5", "k6": "v6"}', 'bla', k1='v1', k2='v2', )
def test_logging_levels(self): w = Wryte(name=str(uuid.uuid4())) w.event('Event') w.log('info', 'My Message') w.debug('Debug Message') w.info('Info Message') w.warning('Warning Message') w.warn('Warning Message') w.error('Error Message') w.critical('Critical Message')
def _test_simple_message(count): w = Wryte(color=False, simple=False) w.remove_handler('_console') timing = [] for _ in range(5): now = datetime.now() for _ in range(count): w.info('My Message') timing.append((datetime.now() - now).total_seconds() * 1000.0) return numpy.average(timing[1:])
def test_simple_context(self): w = Wryte(color=False) timing = [] for _ in range(5): now = datetime.now() for _ in range(10): w.info('My Message', {'key': 'value'}) timing.append((datetime.now() - now).total_seconds() * 1000.0) # This is just a benchmark. This should NEVER take this long. assert numpy.average(timing[1:]) < 10
def test_no_color(self): w = Wryte(name=str(uuid.uuid4()), color=False) w.info('My Message')
def test_ugly(self): w = Wryte(name=str(uuid.uuid4()), pretty=False) w.info('My Message', k='v')
def test_json(self): w = Wryte(name=str(uuid.uuid4()), jsonify=True) w.info('My Message')
def test_simple(self): w = Wryte(name=str(uuid.uuid4()), simple=True) w.info('My Message') w.event('My Event') w.debug('My Message', {'k': 'v'})
def test_aws(self): os.environ['WRYTE_EC2_ENABLED'] = 'true' w = Wryte(name=str(uuid.uuid4())) w.info('Message')
wryter = Wryte(level='INFO') PATH = 'x' 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...')
from wryte import Wryte wryter = Wryte(name='Wryte', level='info') wryter.info('Logging an error level message:') wryter.log('error', 'w00t') wryter.info('Logging an event:', w00t='d') wryter.event('w00t') wryter.info('Binding more dicts to the logger:') wryter.bind({'bound1': 'value1'}, bound2='value2') wryter.info('bind_test') wryter.info('Unbinding keys:') wryter.unbind('bound1') wryter.critical('unbind_test') wryter.error('w00t', _set_level='debug') wryter.debug('test-kwargs', key1='value') wryter.error('message', _set_level='info', x='y', a='b') wryter.debug('test-kwargs', key1='value') wryter.info('w00t', ['ttt'])