From e8b0797ebe18bed71a2461ea76bcdb4b7acf3242 Mon Sep 17 00:00:00 2001 From: retoor Date: Tue, 17 Dec 2024 13:08:00 +0100 Subject: [PATCH] Changed log level. --- app.log | 5 +++++ logtest.py | 29 +++++++++++++++++++++++++++++ src/ragnar/__init__.py | 5 +++-- 3 files changed, 37 insertions(+), 2 deletions(-) create mode 100644 app.log create mode 100644 logtest.py diff --git a/app.log b/app.log new file mode 100644 index 0000000..a185452 --- /dev/null +++ b/app.log @@ -0,0 +1,5 @@ +2024-12-17 13:06:42,285 - __main__ - DEBUG - This is a debug message +2024-12-17 13:06:42,286 - __main__ - INFO - This is an info message +2024-12-17 13:06:42,286 - __main__ - WARNING - This is a warning message +2024-12-17 13:06:42,286 - __main__ - ERROR - This is an error message +2024-12-17 13:06:42,286 - __main__ - CRITICAL - This is a critical message diff --git a/logtest.py b/logtest.py new file mode 100644 index 0000000..1abb612 --- /dev/null +++ b/logtest.py @@ -0,0 +1,29 @@ +import logging + +# Create or get the root logger +logger = logging.getLogger(__name__) +logger.setLevel(logging.DEBUG) # Set the logging level + +# Create a file handler +file_handler = logging.FileHandler('app.log') +file_handler.setLevel(logging.DEBUG) # Set the level for this handler + +# Create a console handler (optional, for logging to the console too) +console_handler = logging.StreamHandler() +console_handler.setLevel(logging.INFO) + +# Create a logging format +formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s') +file_handler.setFormatter(formatter) +console_handler.setFormatter(formatter) + +# Add the handlers to the logger +logger.addHandler(file_handler) +logger.addHandler(console_handler) + +# Log some messages +logger.debug("This is a debug message") +logger.info("This is an info message") +logger.warning("This is a warning message") +logger.error("This is an error message") +logger.critical("This is a critical message") diff --git a/src/ragnar/__init__.py b/src/ragnar/__init__.py index 6b4cc3d..94744f8 100644 --- a/src/ragnar/__init__.py +++ b/src/ragnar/__init__.py @@ -1,8 +1,9 @@ import logging import sys -file_handler = logging.FileHandler("ragnar.log") -file_handler.setLevel(logging.INFO) + +file_handler = logging.FileHandler('ragnar.log') +file_handler.setLevel(logging.DEBUG) logging.basicConfig( level=logging.DEBUG,