Exemplo n.º 1
0
def test_formatted_message(logger):
    message = get_unique_message()
    template = message + '_%s_%s'
    graylog_response = log_warning(logger, template, args=('hello', 'gelf'))
    assert graylog_response['message'] == message + '_hello_gelf'
    assert graylog_response['level'] == SYSLOG_LEVEL_WARNING
    assert 'full_message' not in graylog_response
Exemplo n.º 2
0
def test_static_fields(logger):
    message = get_unique_message()
    graylog_response = log_warning(logger, message, fields=['ozzy', 'van_halen'])
    assert graylog_response['message'] == message
    assert graylog_response['ozzy'] == 'diary of a madman'
    assert graylog_response['van_halen'] == 1984
    assert graylog_response['_id'] != 42
    assert 'id' not in graylog_response
Exemplo n.º 3
0
def test_debug_mode(logger):
    message = get_unique_message()
    graylog_response = log_warning(logger, message)
    assert graylog_response['message'] == message
    assert graylog_response['file'] == 'helper.py'
    assert graylog_response['module'] == 'helper'
    assert graylog_response['func'] == 'log_warning'
    assert graylog_response['logger_name'] == 'test'
    assert 'line' in graylog_response
Exemplo n.º 4
0
def test_simple_message(logger):
    message = get_unique_message()
    graylog_response = log_warning(logger, message)
    assert graylog_response['message'] == message
    assert graylog_response['level'] == SYSLOG_LEVEL_WARNING
    assert 'full_message' not in graylog_response
    assert 'file' not in graylog_response
    assert 'module' not in graylog_response
    assert 'func' not in graylog_response
    assert 'logger_name' not in graylog_response
    assert 'line' not in graylog_response
Exemplo n.º 5
0
def test_source(logger):
    original_source = socket.gethostname()
    with mock.patch('socket.gethostname', return_value='different_domain'):
        message = get_unique_message()
        graylog_response = log_warning(logger, message)
        assert graylog_response['source'] == original_source