pygelf
pygelf copied to clipboard
Support RFC 5424 timestamp
Would you be open to supporting a timestamp format as specified by RFC 5424 (section 6.2.3) for readability? I know that this is not specified by GELF 1.1 so I would suggest to make it configurable using a timestamp_format='rfc-3339' parameter.
Related standards: ISO 8601, RFC 3339.
Ref: https://github.com/severb/graypy/issues/99
Sure, will give it a look.
There was a workaround discussed in https://github.com/severb/graypy/issues/99
The same works for pygelf as well:
import logging
import datetime
from pygelf import GelfTcpHandler
class RFC3339TimestampFilter(logging.Filter):
def filter(self, record):
record.timestamp = datetime.datetime.fromtimestamp(record.created, datetime.timezone.utc).astimezone().isoformat()
return True
logger = logging.getLogger()
logger.addHandler(GelfTcpHandler(host='127.0.0.1', port=9401, include_extra_fields=True))
logger.addFilter(RFC3339TimestampFilter())
logger.error('hello gelf')
You may close this issue if you like.