forked from scrapy/scrapy
-
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.
adding support for log rotation per issue scrapy#3628
- Loading branch information
Showing
4 changed files
with
101 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
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
Empty file.
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,54 @@ | ||
import datetime | ||
import logging | ||
import unittest | ||
|
||
from scrapy.utils.log import configure_logging | ||
|
||
|
||
class test_log_rotate(unittest.TestCase): | ||
def setUp(self): | ||
self.test_settings = { | ||
"LOG_MAX_BYTES": 500, | ||
"LOG_FILE": "sample.log", | ||
"LOG_FILE_ROTATE": True, | ||
"LOG_FILE_ROTATE_WHEN": "midnight", | ||
"LOG_FILE_ROTATE_INTERVAL": 2, | ||
"LOG_FILE_ROTATE_BACKUP_COUNT": 3, | ||
"LOG_FILE_ROTATE_DELAY": True, | ||
"LOG_FILE_ROTATE_UTC": True, | ||
"LOG_FILE_ROTATE_AT_TIME": datetime.time(), | ||
} | ||
configure_logging(settings=self.test_settings) | ||
self.handler = next( | ||
( | ||
handler | ||
for handler in logging.root.handlers | ||
if isinstance(handler, logging.handlers.TimedRotatingFileHandler) | ||
), | ||
None, | ||
) | ||
|
||
def test_rotating_handler(self): | ||
self.assertIsInstance(self.handler, logging.handlers.TimedRotatingFileHandler) | ||
|
||
def test_attribute_when(self): | ||
self.assertEqual(self.handler.when, "midnight".upper()) | ||
|
||
def test_attribute_interval(self): | ||
self.assertEqual(self.handler.interval, 2 * 24 * 60 * 60) | ||
|
||
def test_attribute_backupCount(self): | ||
self.assertEqual(self.handler.backupCount, 3) | ||
|
||
def test_attribute_delay(self): | ||
self.assertEqual(self.handler.delay, True) | ||
|
||
def test_attribute_utc(self): | ||
self.assertEqual(self.handler.utc, True) | ||
|
||
def test_attribute_atTime(self): | ||
self.assertEqual(self.handler.atTime, datetime.time()) | ||
|
||
|
||
if __name__ == "__main__": | ||
unittest.main() |