Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Machine readable addons logs #1308

Open
nirs opened this issue Mar 31, 2024 · 0 comments
Open

Machine readable addons logs #1308

nirs opened this issue Mar 31, 2024 · 0 comments
Labels
enhancement New feature or request test Testing related issue

Comments

@nirs
Copy link
Member

nirs commented Mar 31, 2024

Currently addons use print() and fstrings (e.g. f"{value}")) for logging. The motivation was to make writing addons really easy for new contributors.

This make it hard to handle logs in a useful way in drenv, for example:

  • Log warnings emitted by the addon (e.g. timeout was too short - operation finished in time but could fail in next run)
  • Parse errors by drenv, for reporting error in machine readable format to the tool running drenv

We can keep logging easy by using a drenv log module, initialized when parsing addon arguments:

from drenv import addon

args = addon.parse_args()

addon.debug("message with value %s", 42)
addon.info("message")

The output will use jsonlines:

{"time": "2024-03-31 11:24:09,869", "level": "DEBUG", "message": "message with value 42"}
{"time": "2024-03-31 11:24:09,869", "level": "INFO", "message": "message"}

The addon module can install a sys.excepthook that will log errors using the same formatter.

@nirs nirs added enhancement New feature or request test Testing related issue labels Mar 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request test Testing related issue
Projects
None yet
Development

No branches or pull requests

1 participant