Skip to content

[feature] global extra's (key-value) #1374

@ddofborg

Description

@ddofborg

I would like to be able to set some global extra's to all log output. This is useful when logs are written to files or terminal from multiple processed running at the same time. This way each line can be connected by PID or some other useful key-value pair. Especially when other modules are also logging and you want to know what is was related to.

Code:

log.set('pid', os.getpid())
log.info("loading account")
account_id = load_account()
log.set('account', account_id)
log.info("computing")
compute(account_id)
log.info("unloading account")
unload(account_id)
log.set('account', None)
log.info("done")

Output:

2025-08-09 07:53:37 [INFO    ] [pid=123] loading account
2025-08-09 07:53:37 [INFO    ] [pid=123, account=456] computing
2025-08-09 07:53:37 [INFO    ] [pid=123, account=456] unloading account
2025-08-09 07:53:37 [INFO    ] [pid=123] done

What do you think?

Metadata

Metadata

Assignees

No one assigned

    Labels

    featureRequest for adding a new feature

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions