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

How do I control logging levels of other handles? #115

Open
clsteam opened this issue Mar 22, 2023 · 0 comments
Open

How do I control logging levels of other handles? #115

clsteam opened this issue Mar 22, 2023 · 0 comments

Comments

@clsteam
Copy link

clsteam commented Mar 22, 2023

As stated in my title question, how should I change logging levels of other handles, like logging.FileHandler below.

    logging_format = '%(asctime)s %(hostname)s %(username)s %(programname)s %(name)s[%(process)d] %(levelname)s %(message)s'
    logging_level = "DEBUG"
    logging_file = "test.log"

    verboselogs.install()
    coloredlogs.install(level=logging_level, stream=sys.stdout, fmt=logging_format, milliseconds=True)
    # main logger
    logger = logging.getLogger("main")
    # add file handler
    logging_file_handler = logging.FileHandler(logging_file)
    logging_file_handler.setFormatter(coloredlogs.ColoredFormatter('%(asctime)s %(name)s[%(process)d] %(levelname)s %(message)s'))
    logging_file_handler.setLevel("SPAM")
    logger.addHandler(logging_file_handler)
    logger.debug("show in console")
    logger.spam("show in logging file only?")

In the above code, logging_file_handler.setLevel("SPAM") doesn't seem to work, the logging is same between console and file.

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