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

Log output does not match what is expected #989

Open
wangjinbei opened this issue Jun 18, 2024 · 0 comments
Open

Log output does not match what is expected #989

wangjinbei opened this issue Jun 18, 2024 · 0 comments

Comments

@wangjinbei
Copy link

wangjinbei commented Jun 18, 2024

Hi, when I use https://kdeldycke.github.io/click-extra/logging.html#custom-logger

My terminal outputs two logs, is there a problem where I am processing?
My intention: to format all log content in json format so that I can analyze and notify using the log collector .

Also what can I do to define the "Load configuration matching foo.ini" in json format as well?

demo.py:

import logging

from click import pass_context
from click_extra import extra_command, extra_basic_config, verbosity_option

extra_basic_config(
    logger_name="app_logger",
    format='{{"time": "{asctime}", "name": "{name}", "level": "{levelname}", "msg": "{message}"}}',
    force=True,
    level=logging.INFO,
)


@extra_command
@pass_context
@verbosity_option(default_logger="app_logger",)
def cli(config):
    logging.getLogger("app_logger").info("This is an info message from the root logger.")

output:

Load configuration matching foo.ini
{"time": "2024-06-18 10:35:50,018", "name": "app_logger", "level": "info", "msg": "This is an info message from the root logger."}
info: This is an info message from the root logger.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant