Skip to content

logging handler yields 'record' as string instead of map #34

Closed
@mr-salty

Description

@mr-salty

When using the logging handler, the emitted record has type string (fixedstr) rather than map.

According to the fluent plugin docs at http://docs.fluentd.org/articles/plugin-development 'record' is required to be a Hash object, so I believe the implication is this module should only emit 'map'.

Example code (based on the examples from the docs), followed by some extra logging I added to fluentd's in_forward plugin:

Example using 'handler':

import logging
from fluent import handler

logging.basicConfig(level=logging.INFO)
l = logging.getLogger('fluent.test')
l.addHandler(handler.FluentHandler('app.follow'))
l.info({
  'message': 'test from info',
})

2015-04-10 22:15:07 +0000 [info]: on_read_msgpack:
00000000  93 aa 61 70 70 2e 66 6f 6c 6c 6f 77 ce 55 28 4b  |..app.follow.U(K|
00000010  6b bd 7b 27 6d 65 73 73 61 67 65 27 3a 20 27 74  |k.{'message': 't|
00000020  65 73 74 20 66 72 6f 6d 20 69 6e 66 6f 27 7d     |est from info'}|
2015-04-10 22:15:07 +0000 [info]: on_message:  msg=["app.follow", 1428704107, "{'message': 'test from info'}"] chunk_size=47 source="host: 127.0.0.1, addr: 127.0.0.1, port: 49307"
2015-04-10 22:15:07 +0000 [info]: record_class=String

Example using 'event' directly, which works correctly:

from fluent import sender
from fluent import event
sender.setup('app')
event.Event('follow', {
  'message': 'this is a test',
})

2015-04-10 22:15:07 +0000 [info]: on_read_msgpack:
00000000  93 aa 61 70 70 2e 66 6f 6c 6c 6f 77 ce 55 28 4b  |..app.follow.U(K|
00000010  6b 81 a7 6d 65 73 73 61 67 65 ae 74 68 69 73 20  |k..message.this |
00000020  69 73 20 61 20 74 65 73 74                       |is a test|
2015-04-10 22:15:07 +0000 [info]: on_message:  msg=["app.follow", 1428704107, {"message"=>"this is a test"}] chunk_size=41 source="host: 127.0.0.1, addr: 127.0.0.1, port: 49306"
2015-04-10 22:15:07 +0000 [info]: record_class=Hash

Some output plugins do not care about the type of 'record' so this may appear to work, but there are other plugins that discard the record or have other issues if it is not a hash.

Metadata

Metadata

Assignees

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