fluent-logger-python icon indicating copy to clipboard operation
fluent-logger-python copied to clipboard

Issues with the logging.Handler interface

Open aknapp opened this issue 12 years ago • 2 comments

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

aknapp avatar Dec 05 '12 01:12 aknapp

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.

EvaSDK avatar Dec 13 '13 15:12 EvaSDK

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

EvaSDK avatar Jun 17 '15 08:06 EvaSDK