mirror of
https://github.com/PaddlePaddle/FastDeploy.git
synced 2026-04-23 00:17:25 +08:00
@@ -30,7 +30,7 @@ class LoggerTests(unittest.TestCase):
|
||||
self.env_patchers = [
|
||||
patch("fastdeploy.envs.FD_LOG_DIR", self.tmp_dir),
|
||||
patch("fastdeploy.envs.FD_DEBUG", 0),
|
||||
patch("fastdeploy.envs.FD_LOG_BACKUP_COUNT", "1"),
|
||||
patch("fastdeploy.envs.FD_LOG_BACKUP_COUNT", 1),
|
||||
]
|
||||
for p in self.env_patchers:
|
||||
p.start()
|
||||
@@ -77,5 +77,54 @@ class LoggerTests(unittest.TestCase):
|
||||
self.assertTrue(legacy_logger.propagate)
|
||||
|
||||
|
||||
class LoggerExtraTests(unittest.TestCase):
|
||||
def setUp(self):
|
||||
self.logger = FastDeployLogger()
|
||||
|
||||
def tearDown(self):
|
||||
if hasattr(FastDeployLogger, "_instance"):
|
||||
FastDeployLogger._instance = None
|
||||
if hasattr(FastDeployLogger, "_initialized"):
|
||||
FastDeployLogger._initialized = False
|
||||
|
||||
def test_singleton_behavior(self):
|
||||
"""Ensure multiple instances are same"""
|
||||
a = FastDeployLogger()
|
||||
b = FastDeployLogger()
|
||||
self.assertIs(a, b)
|
||||
|
||||
def test_initialize_only_once(self):
|
||||
"""Ensure _initialize won't re-run if already initialized"""
|
||||
self.logger._initialized = True
|
||||
with patch("fastdeploy.logger.logger.setup_logging") as mock_setup:
|
||||
self.logger._initialize()
|
||||
mock_setup.assert_not_called()
|
||||
|
||||
def test_get_logger_unified_path(self):
|
||||
"""Directly test get_logger unified path"""
|
||||
with patch("fastdeploy.logger.logger.setup_logging") as mock_setup:
|
||||
log = self.logger.get_logger("utils")
|
||||
self.assertTrue(log.name.startswith("fastdeploy."))
|
||||
mock_setup.assert_called_once()
|
||||
|
||||
def test_get_logger_legacy_path(self):
|
||||
"""Test legacy get_logger path"""
|
||||
with patch("fastdeploy.logger.logger.FastDeployLogger._get_legacy_logger") as mock_legacy:
|
||||
self.logger.get_logger("x", "y.log", False, False)
|
||||
mock_legacy.assert_called_once()
|
||||
|
||||
def test_get_legacy_logger_debug_mode(self):
|
||||
"""Ensure debug level is set when FD_DEBUG=1"""
|
||||
with patch("fastdeploy.envs.FD_DEBUG", 1):
|
||||
logger = self.logger._get_legacy_logger("debug_case", "d.log")
|
||||
self.assertEqual(logger.level, logging.DEBUG)
|
||||
|
||||
def test_get_legacy_logger_without_formatter(self):
|
||||
"""Test legacy logger without formatter"""
|
||||
logger = self.logger._get_legacy_logger("nofmt", "n.log", without_formater=True)
|
||||
for h in logger.handlers:
|
||||
self.assertIsNone(h.formatter)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main(verbosity=2)
|
||||
|
||||
Reference in New Issue
Block a user