Skip to content

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

Open
@clsteam

Description

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions