Skip to content

Commit

Permalink
To rollover the crawler logs by day end through settings
Browse files Browse the repository at this point in the history
	- Modified _get_handler method to return TimedRotatingFileHandler
	  if LOG_ROTATION variable is set to True in settings.
	- This enhancement is regards to issue : Crawler logs are cut by day scrapy#3628

 Changes to be committed:
	modified:   scrapy/utils/log.py
  • Loading branch information
rindhane committed Mar 31, 2020
1 parent 8845773 commit fcb4fcb
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion scrapy/utils/log.py
Expand Up @@ -4,6 +4,7 @@
import sys
import warnings
from logging.config import dictConfig
from logging.handlers import TimedRotatingFileHandler

from twisted.python import log as twisted_log
from twisted.python.failure import Failure
Expand Down Expand Up @@ -122,9 +123,23 @@ def get_scrapy_root_handler():
def _get_handler(settings):
""" Return a log handler object according to settings """
filename = settings.get('LOG_FILE')
rotation = settings.getbool('LOG_ROTATION')
rotation_dict = settings.getdict('LOG_ROTATION_VALUES', {})
if filename:
encoding = settings.get('LOG_ENCODING')
handler = logging.FileHandler(filename, encoding=encoding)
if rotation :
handler = TimedRotatingFileHandler(
filename,
encoding=encoding,
when = rotation_dict.get("when","midnight"),
interval = rotation_dict.get("interval",1),
backupCount = rotation_dict.get("backupCount",0),
delay= rotation_dict.get("delay",False),
utc= rotation_dict.get("utc",False),
atTime=rotation_dict.get("atTime",None) ,
)
else:
handler = logging.FileHandler(filename, encoding=encoding)
elif settings.getbool('LOG_ENABLED'):
handler = logging.StreamHandler()
else:
Expand Down

0 comments on commit fcb4fcb

Please sign in to comment.