-
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.
feat(LOGGING): add logging to slack bot and client
- Loading branch information
1 parent
edbd7a4
commit 8eb43e9
Showing
11 changed files
with
149 additions
and
15 deletions.
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
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
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
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
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
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
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
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
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
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,20 @@ | ||
"""Standard logging mixin class.""" | ||
|
||
from logging import Logger, getLogger | ||
|
||
from pi_portal.modules.configuration import logger | ||
|
||
|
||
class WriteLogFile: | ||
"""Adds logging features to an existing class.""" | ||
|
||
logger_name: str | ||
log_file_path: str | ||
log: Logger | ||
|
||
def configure_logger(self) -> None: | ||
"""Configure a standardized logger for this class.""" | ||
|
||
self.log = getLogger(self.logger_name) | ||
logging_configuration = logger.LoggingConfiguration() | ||
logging_configuration.configure(self.log, self.log_file_path) |
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,39 @@ | ||
"""Test the WriteLogFile mixin classes.""" | ||
|
||
from unittest import TestCase, mock | ||
|
||
from .. import log_file | ||
|
||
LOG_FILE_MODULE = log_file.__name__ | ||
|
||
|
||
class ClassWithLogging(log_file.WriteLogFile): | ||
"""A test class using the WriteLogFile mixin.""" | ||
|
||
logger_name = "test_logger" | ||
log_file_path = "/var/run/some.log" | ||
|
||
|
||
@mock.patch(LOG_FILE_MODULE + '.getLogger') | ||
@mock.patch(LOG_FILE_MODULE + '.logger.LoggingConfiguration') | ||
class WriteLogFileTest(TestCase): | ||
"""Test the WriteLogFile mixin class.""" | ||
|
||
def setUp(self) -> None: | ||
self.instance = ClassWithLogging() | ||
|
||
def test_configure_logger( | ||
self, | ||
m_config: mock.Mock, | ||
m_get: mock.Mock, | ||
) -> None: | ||
|
||
self.instance.configure_logger() | ||
|
||
m_get.assert_called_once_with(self.instance.logger_name) | ||
m_config.assert_called_once_with() | ||
m_config.return_value.configure.assert_called_once_with( | ||
m_get.return_value, self.instance.log_file_path | ||
) | ||
|
||
self.assertEqual(self.instance.log, m_get.return_value) |