Giter Club home page Giter Club logo

gelf-formatter's People

Contributors

0mbi avatar dependabot[bot] avatar girstenbrei avatar joaodrp avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

gelf-formatter's Issues

gelf-formatter induces logging error in django when uncaptured exception is raised

Problem:
Despite the fact that exception should be captured, when
doing so in a django request handler, gelf-formatter produces
a logging error caused by

TypeError: Object of type WSGIRequest is not JSON serializable

Solution:
This can be fixed by converting value to string for non json serialzable objects:
log_record[_prefix(key)] = str(value)

Add python 3.8 tests

To test against the newest python version, it should be added to tox.ini and .travis.yml

Is this project still maintained?

Hey! My team is looking for exactly something with the idea of just have the gelf formatter to use with fluentd on k8s, which seems to be exactly the purpose of this library, but I wonder if the project is still maintained because of the long open PRs and issues

Ignore additional fields at any level

In #1 a new functionality was added to make it possible to ignore specific attributes at the root level. Example:

attrs = ["secret", "password"]

formatter = GelfFormatter(ignored_attrs=attrs)
# or
formatter.ignored_attrs = attrs

logging.debug("app config", extra={"connection": "local", "secret": "verySecret!", "mysql": {"user": "test", "password": "will_be_logged"}})
{"version": "1.1", "short_message": "app config", "timestamp": 1557346554.989846, "level": 6, "host": "my-server", "_connection": "local", "_mysql": {"user": "test", "password": "will_be_logged"}}

This issue is to propose the ability of ignoring fields at any depth. In the example above, this would allow us to ignore the mysql/password attribute as well.

One way to achieve this is to accept a special syntax on the ignored_attrs list, where the depth level is represented by a dot ., e.g.:

attrs = ["secret", "mysql.password"]

The format function would then need to inspect the extra values taking into account nested fields.

asctime is not logged

Hi!

Firsly gelf-formatter is awesome, I don't understand how other projects even justify blocking entire program execution to send logs over network...

WIth that said, tailing logs on server is bit more complicated with gelf format and I wanted to add a human readable timestamp. Fortunately this awesome library supports adding allowed_reserved_attrs, however asctime does not seem to work, whereas other attributes work.

This is the configuration:
gelf_formatter = GelfFormatter(allowed_reserved_attrs=["processName", "asctime", "filename", "created"]

Log line:
{"version": "1.1", "short_message": "beat: Waking up in 5.00 minutes.", "timestamp": 1576665042.5591564, "level": 7, "host": "playsignage-int-2019", "_filename": "beat.py", "_created": 1576665042.5591564, "_processName": "MainProcess"}

The log line contains extra attrs, such as _processName, _filename and _created, however asctime is missing...any ideas?

No way to control format of JSON

Hello!

Seems that there is no way to change output of this formatter because it simply calls json.dumps(...). Personally I was needed to add indent=2 and ensure_ascii=False keyword arguments into dumps call to be able to format log output in proper readable way. I think that solution can be very simple: jsut add something like dumps_args={} to constructor, for example:

def __init__(self, allowed_reserved_attrs=[], ignored_attrs=[], dumps_args={}):
        """Initializes a GelfFormatter."""
        super(GelfFormatter, self).__init__()
        ...
        self.dumps_args = dumps_args
...
        return json.dumps(log_record, **self.dumps_args)

It is quite simple and works well.

Access intermediate log_record

I would like to be able to get at the intermediate log_record used in the GelfFormatter.

My use case is advanced adding/removing of fields from the logs. I could then subclass GelfFormatter to access the data without having to json.loads(gelf_message).

A simple idea of this could be to move the implementation logic from format to a new method def convert(self, record) -> dict in the GelfFormatter. The format method would only consist of return json.dumps(self.convert(record)) but easily used in subclasses to add additional functionality.

This would keep the current API and I'm happy to discuss the name convert ๐Ÿ˜ƒ. What do y'all think?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.