pygelf icon indicating copy to clipboard operation
pygelf copied to clipboard

Support RFC 5424 timestamp

Open ypid-geberit opened this issue 7 years ago • 2 comments

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

ypid-geberit avatar Feb 05 '19 10:02 ypid-geberit

Sure, will give it a look.

keeprocking avatar Feb 05 '19 11:02 keeprocking

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.

ypid-geberit avatar Mar 15 '19 10:03 ypid-geberit