graypy icon indicating copy to clipboard operation
graypy copied to clipboard

Fails to log silently with specific extra field

Open gnudiff opened this issue 7 years ago • 3 comments

If I add extra field named 'status' to the extra fields dict when logging, graypy will drop the message without any error (nothing gets logged). Example:

import logging
import graypy

mylog=logging.getLogger('order.processing')
handler=graypy.GELFHandler('mylogserver',debugging_fields=True)
mylog.addHandler(handler)
#the following line works
mylog.info("Test123",extra={'fld1':1,'fld2':2})
# the following line doesn't output anything to GrayLog:
mylog.info("Test with status", extra={'fld1':1,'fld2':2, 'status':'OK'})

gnudiff avatar May 18 '18 11:05 gnudiff

Do you know why this happens?

severb avatar Nov 11 '18 00:11 severb

I'm currently working on another refactoring build https://github.com/nklapste/graypy/pull/3 and have worked into testing this issue.

I was unable to create this issue/failure with my tests:


#!/usr/bin/python
# -*- coding: utf-8 -*-

"""pytests for addressing potential issues with adding an ``status`` extra
field withing a given log and having the log failing to appear within graylog.

Related issue:
- Fails to log silently with specific extra field #85

URL:
- https://github.com/severb/graypy/issues/85
"""

import pytest

from tests.integration import LOCAL_GRAYLOG_UP
from tests.integration.helper import get_unique_message, get_graylog_response
from tests.helper import handler, logger


@pytest.mark.skipif(not LOCAL_GRAYLOG_UP,
                    reason="local graylog instance not up")
def test_non_status_field_log(logger):
    message = get_unique_message()
    logger.error(message, extra={"foo": "bar"})
    graylog_response = get_graylog_response(message, fields=["foo"])
    assert message == graylog_response["message"]
    assert "bar" == graylog_response["foo"]


@pytest.mark.skipif(not LOCAL_GRAYLOG_UP,
                    reason="local graylog instance not up")
def test_status_field_issue(logger):
    message = get_unique_message()
    logger.error(message, extra={"status": "OK"})
    graylog_response = get_graylog_response(message, fields=["status"])
    assert message == graylog_response["message"]
    assert "OK" == graylog_response["status"]


@pytest.mark.skipif(not LOCAL_GRAYLOG_UP,
                    reason="local graylog instance not up")
def test_status_field_issue_multi(logger):
    message = get_unique_message()
    logger.error(message, extra={"foo": "bar", "status": "OK"})
    graylog_response = get_graylog_response(message, fields=["foo", "status"])
    assert message == graylog_response["message"]
    assert "bar" == graylog_response["foo"]
    assert "OK" == graylog_response["status"]

Note: these tests are logging to a active graylog docker container.

Possibly when this branch gets finished and (hopefully) merged. This issue will likely be resolved.

nklapste avatar Nov 18 '18 23:11 nklapste

@gnudiff does this issue persist with graypy version 1.1.X+?

Currently the implemented test cases in https://github.com/severb/graypy/blob/master/tests/integration/test_status_issue.py seem to validate this issue as resolved as of version 1.1.X+.

nklapste avatar Mar 19 '19 21:03 nklapste