Beispiel #1
0
def test_repeated_event():
	logger = Centraloger(_conn)
	logger.logEvent(logging.makeLogRecord({
		'msg': 'first form (%s)',
		'args': ('first',),
		'levelno': logging.DEBUG,
	}))

	logger.logEvent(logging.makeLogRecord({
		'msg': 'second form (%s)',
		'args': ('second',),
		'levelno': logging.DEBUG,
	}))

	logger.logEvent(logging.makeLogRecord({
		'msg': 'first form (%s)',
		'args': ('third, but first',),
		'levelno': logging.DEBUG,
	}))

	evt = logger.getEvent()
	assert evt['repeats'] == 2.0
	assert evt['msg'] == 'first form (%s)'

	evt = logger.getEvent()
	assert evt['repeats'] == 1.0
	assert evt['msg'] == 'second form (%s)'

	evt = logger.getEvent()
	assert evt == None

	print sys._getframe(0).f_code.co_name, 'ok.'
Beispiel #2
0
def test_log_as_log():
    logger = logging.getLogger('test')
    logger.warning('doing something', exc_info=True)

    l = Centraloger(_conn)
    evt = l.getEvent()
    evt = logging.makeLogRecord(evt['args'])
    assert evt.exc_text == 'None'

    print sys._getframe(0).f_code.co_name, 'ok.'
Beispiel #3
0
def test_log_as_log():
	logger = logging.getLogger('test')
	logger.warning('doing something', exc_info=True)

	l = Centraloger(_conn)
	evt = l.getEvent()
	evt = logging.makeLogRecord(evt['args'])
	assert evt.exc_text=='None'

	print sys._getframe(0).f_code.co_name, 'ok.'
Beispiel #4
0
def test_in_exception():
    try:
        print 0 / 0
    except:
        logger = logging.getLogger('test')
        logger.error('something\'s wrong?', exc_info=True)

    l = Centraloger(_conn)
    evt = l.getEvent()
    evt = logging.makeLogRecord(evt['args'])
    print evt.message
    print evt.exc_text
    assert evt.exc_text != None

    print sys._getframe(0).f_code.co_name, 'ok.'
Beispiel #5
0
def test_one_event():
	logger = Centraloger(_conn)
	logger.logEvent(logging.makeLogRecord({
		'msg': 'hi there (%s)',
		'args': ('everybody',),
		'levelno': logging.DEBUG,
	}))

	evt = logger.getEvent()
	assert evt['repeats'] == 1.0

	evt = logger.getEvent()
	assert evt == None

	print sys._getframe(0).f_code.co_name, 'ok.'
Beispiel #6
0
def test_in_exception():
	try:
		print 0/0
	except:
		logger = logging.getLogger('test')
		logger.error('something\'s wrong?', exc_info=True)

	l = Centraloger(_conn)
	evt = l.getEvent()
	evt = logging.makeLogRecord(evt['args'])
	print evt.message
	print evt.exc_text
	assert evt.exc_text != None

	print sys._getframe(0).f_code.co_name, 'ok.'
Beispiel #7
0
def test_one_event():
    logger = Centraloger(_conn)
    logger.logEvent(
        logging.makeLogRecord({
            'msg': 'hi there (%s)',
            'args': ('everybody', ),
            'levelno': logging.DEBUG,
        }))

    evt = logger.getEvent()
    assert evt['repeats'] == 1.0

    evt = logger.getEvent()
    assert evt == None

    print sys._getframe(0).f_code.co_name, 'ok.'
Beispiel #8
0
def test_spaced_events():
    logger = Centraloger(_conn)
    logger.logEvent(
        logging.makeLogRecord({
            'msg': 'first form (%s)',
            'args': ('first', ),
            'levelno': logging.DEBUG,
        }))

    logger.logEvent(
        logging.makeLogRecord({
            'msg': 'second form (%s)',
            'args': ('second', ),
            'levelno': logging.DEBUG,
        }))

    # wait a little, so third event isn't grouped with first
    print '...sleep...'
    time.sleep(1.5)

    logger.logEvent(
        logging.makeLogRecord({
            'msg': 'first form (%s)',
            'args': ('third, but first', ),
            'levelno': logging.DEBUG,
        }))

    evt = logger.getEvent()
    assert evt['repeats'] == 1.0
    assert evt['msg'] == 'first form (%s)'

    evt = logger.getEvent()
    assert evt['repeats'] == 1.0
    assert evt['msg'] == 'second form (%s)'

    evt = logger.getEvent()
    assert evt['repeats'] == 1.0
    assert evt['msg'] == 'first form (%s)'

    evt = logger.getEvent()
    assert evt == None

    print sys._getframe(0).f_code.co_name, 'ok.'
Beispiel #9
0
def test_repeated_event():
    logger = Centraloger(_conn)
    logger.logEvent(
        logging.makeLogRecord({
            'msg': 'first form (%s)',
            'args': ('first', ),
            'levelno': logging.DEBUG,
        }))

    logger.logEvent(
        logging.makeLogRecord({
            'msg': 'second form (%s)',
            'args': ('second', ),
            'levelno': logging.DEBUG,
        }))

    logger.logEvent(
        logging.makeLogRecord({
            'msg': 'first form (%s)',
            'args': ('third, but first', ),
            'levelno': logging.DEBUG,
        }))

    evt = logger.getEvent()
    assert evt['repeats'] == 2.0
    assert evt['msg'] == 'first form (%s)'

    evt = logger.getEvent()
    assert evt['repeats'] == 1.0
    assert evt['msg'] == 'second form (%s)'

    evt = logger.getEvent()
    assert evt == None

    print sys._getframe(0).f_code.co_name, 'ok.'
Beispiel #10
0
def test_empty_gather():
    logger = Centraloger(_conn)
    assert logger.getEvent() == None

    print sys._getframe(0).f_code.co_name, 'ok.'
Beispiel #11
0
def setup_python_logger():
    handler = CentralogHandler(Centraloger(_conn))
    logger = logging.getLogger('test')
    logger.addHandler(handler)
    print sys._getframe(0).f_code.co_name, 'ok.'
Beispiel #12
0
def test_spaced_events():
	logger = Centraloger(_conn)
	logger.logEvent(logging.makeLogRecord({
		'msg': 'first form (%s)',
		'args': ('first',),
		'levelno': logging.DEBUG,
	}))

	logger.logEvent(logging.makeLogRecord({
		'msg': 'second form (%s)',
		'args': ('second',),
		'levelno': logging.DEBUG,
	}))

	# wait a little, so third event isn't grouped with first
	print '...sleep...'
	time.sleep(1.5)

	logger.logEvent(logging.makeLogRecord({
		'msg': 'first form (%s)',
		'args': ('third, but first',),
		'levelno': logging.DEBUG,
	}))

	evt = logger.getEvent()
	assert evt['repeats'] == 1.0
	assert evt['msg'] == 'first form (%s)'

	evt = logger.getEvent()
	assert evt['repeats'] == 1.0
	assert evt['msg'] == 'second form (%s)'

	evt = logger.getEvent()
	assert evt['repeats'] == 1.0
	assert evt['msg'] == 'first form (%s)'

	evt = logger.getEvent()
	assert evt == None

	print sys._getframe(0).f_code.co_name, 'ok.'
Beispiel #13
0
def test_empty_gather():
	logger = Centraloger(_conn)
	assert logger.getEvent() == None

	print sys._getframe(0).f_code.co_name, 'ok.'