This repository has been archived by the owner on Jan 26, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from aidh-ms/issue/1-add-logging
Issue/1 add logging
- Loading branch information
Showing
4 changed files
with
78 additions
and
1 deletion.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
# locals | ||
.vscode | ||
|
||
# Byte-compiled / optimized / DLL files | ||
__pycache__/ | ||
*.py[cod] | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import logging | ||
import colorlog | ||
|
||
|
||
class ICUPLogger: | ||
def __init__(self): | ||
self._logger: logging.Logger = logging.getLogger() # Get the root logger | ||
self._logger.setLevel(logging.INFO) # Set your desired log level | ||
|
||
formatter = colorlog.ColoredFormatter( | ||
'%(log_color)s%(levelname)s:%(name)s:%(message)s%(reset)s', | ||
log_colors={ | ||
'DEBUG': 'cyan', | ||
'INFO': 'green', | ||
'WARNING': 'yellow', | ||
'ERROR': 'red', | ||
'CRITICAL': 'red,bg_white', | ||
} | ||
) | ||
|
||
console_handler = logging.StreamHandler() | ||
console_handler.setFormatter(formatter) | ||
|
||
self._logger.addHandler(console_handler) | ||
|
||
def get_logger(self): | ||
return self._logger |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
psycopg[binary] | ||
SQLAlchemy | ||
pandas | ||
pandas | ||
colorlog |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import unittest | ||
from io import StringIO | ||
import logging | ||
from icu_pipeline.logger import ICUPLogger | ||
|
||
|
||
class LoggerTestCase(unittest.TestCase): | ||
def setUp(self): | ||
self.logger = ICUPLogger().get_logger() | ||
|
||
# Create a StringIO object to capture the logging output | ||
self.log_output = StringIO() | ||
self.log_handler = logging.StreamHandler(self.log_output) | ||
self.logger.addHandler(self.log_handler) | ||
|
||
def tearDown(self): | ||
self.logger.removeHandler(self.log_handler) | ||
self.log_output.close() | ||
|
||
def test_info_logging(self): | ||
message = "This is an info message" | ||
self.logger.info(message) | ||
log_output = self.log_output.getvalue().strip() | ||
|
||
self.assertIn(message, log_output) | ||
self.assertIn("info", log_output) | ||
|
||
def test_warning_logging(self): | ||
message = "This is a warning message" | ||
self.logger.warning(message) | ||
log_output = self.log_output.getvalue().strip() | ||
|
||
self.assertIn(message, log_output) | ||
self.assertIn("warning", log_output) | ||
|
||
def test_error_logging(self): | ||
message = "This is an error message" | ||
self.logger.error(message) | ||
log_output = self.log_output.getvalue().strip() | ||
|
||
self.assertIn(message, log_output) | ||
self.assertIn("error", log_output) | ||
|
||
|
||
if __name__ == "__main__": | ||
unittest.main() |