Skip to content

[Bug] Log message formatted with %r raises BulkIndexError #62

Open
@popes01a

Description

@popes01a

I have recently switched to using CMRESHandler and I encoutered some issues when trying to use %r for string formatting.

The handler is set up as below:

handler = {
    'level': 'INFO',
    'class': 'cmreslogging.handlers.CMRESHandler',
    'hosts': [{'host': ELASTICSEARCH_HOST, 'port': ELASTICSEARCH_PORT}],
    'es_index_name': 'app-name',
    'raise_on_indexing_exceptions': True,
}

Assuming I have the following dictionary to log:

parameters = { 
    'month': datetime.datetime(2018, 12, 1, 0, 0, tzinfo=tzutc()), 
    'status': 'complete', 
}

If I do logger.info('Parameters: %r' % parameters) then nothing gets logged and I get the following error:

raise BulkIndexError('%i document(s) failed to index.' % len(errors), errors)

'error': {
	'type': 'mapper_parsing_exception',
	'reason': 'failed to parse field [args] of type [text]',
	'caused_by': {'type': 'illegal_state_exception', 'reason': "Can't get text on a START_OBJECT at 1:610"}
}

I switched to logger.info('Parameters: %s' % repr(parameters)) and that works fine, however it would be nice to be able to use %r and avoid wrapping parameters in repr().

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions