Created
April 14, 2023 07:38
-
-
Save thoroc/f4978059839abb64eeadbcd772705fd2 to your computer and use it in GitHub Desktop.
How to set the cli app to show debug logs with loguru
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import click | |
from loguru import logger | |
@click.command() | |
@click.option( | |
"-d", | |
"--debug", | |
is_flag=True, | |
help="Enable debug mode. Prints debug messages to the console.", | |
) | |
def main(debug: bool): | |
if not debug: | |
# default loguru level is DEBUG | |
logger.remove() | |
logger.add(sys.stderr, level="INFO") | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment