madzak / python-json-logger

Json Formatter for the standard python logger
BSD 2-Clause "Simplified" License
1.7k stars 231 forks source link

Feature request: Add ECS compatibility #147

Closed Henkhogan closed 1 year ago

Henkhogan commented 1 year ago

Add a constant dictionary that can be used in order to map the python logger fields to ecs (https://www.elastic.co/guide/en/ecs/current/ecs-reference.html) compatible field names

JSONLOGGER_RENAME_FIELDS_ECS = {
    'levelname':'log.level',
    'funcName': 'log.origin.function',
    'module': 'log.origin.file.name',
    'name': 'log.logger',
    'process': 'process.pid',
    'processName': 'process.name',
    'thread': 'process.thread.id',
    'threadName': 'process.thread.name'
    }

that can then be used like

json_formatter = jsonlogger.JsonFormatter(rename_fields = JSONLOGGER_RENAME_FIELDS_ECS)

louis-jaris commented 1 year ago

Hey @Henkhogan

Why this map should be packaged in python-json-logger? It looks like you found the solution to make things work locally.

Having a such map in this package would mean that it has to be maintained. In addition to this, this is Cloud provider-specific, so this is specific to your use case and not to the use case of users of this library. I don't think such addition makes sense for the community IMHO.

Henkhogan commented 1 year ago

Hey @louis-jaris,

I think ECS is not cloud provider specific but supposed to be an open standard for logging.

Furthermore the map is expected to be static. It only maps the field names that the python logger has built in.

However if you have a problem maintaining the map, I will remove it from the PR and just keep the other change in. Just let me know.

Cheers

madzak commented 1 year ago

Changes merged. please open a new issue if something isn't working