Skip to content

Issues with the logging.Handler interface #7

Closed

Description

@aknapp

So, I'm trying to integrate fluent into one of our apps, and I'm running into some issues using the logging.Handler interface.

First off, when I use the event interface, everything looks like I expect it to:

fluent_sender.setup('app', host='localhost', port=24224)
fluent_event.Event('info', {'connect': ''})

This gives me this output, which is exactly what I want:
2012-12-02T14:00:09-08:00 app.info {"connect":""}

When I try to use the logging.Handler interface, I get something different:

self.logger = logging.getLogger(self.__class__.__name__)
self.logger.addHandler(handler.FluentHandler('app', host='localhost', port=24224))
self.logger.info({'connect': ''})

This gives me this:
2012-12-02T13:08:05-08:00 app {"sys_module":"app","sys_name":"fluent","sys_host":"hostname","connect":""}
(that is all on one line)

Ideally, I would like the output to be the same as when I use the event interface. Also, when I specify multiple items in the log, like so:

self.logger.info({'level': 'info', 'connect': ''})

The fields in the log are not ordered, and show up in different order all the time.

Am I doing something wrong here? Can you point me in the right direction if so?

Thanks,
Andy

Activity

  1. EvaSDK commented on Dec 13, 2013

    @EvaSDK
    Contributor

    The sys_* keys are added specifically in this class and are not (currently ?) overridable.

    See https://github.com/fluent/fluent-logger-python/blob/master/fluent/handler.py#L18

    As for the order of the fields, well this is the nature of python dict, the order is not stable.
    If you want it to be displayed in order, you will most likely want to implement a logging formatter that will be used for console or file output.

    See http://docs.python.org/2/library/logging.html#logging.Formatter for that.

  2. EvaSDK commented on Jun 17, 2015

    @EvaSDK
    Contributor

    I think your concerns should be cleared with logger format customization available in v0.4.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions