I have used scrapy for several months.Several weeks ago,I started to use file to record log information.I wrote
from scrapy.utils.log import configure_logging
filename = '%s-log.txt' % file_name
logger = logging_file.logging_to_file('./logs/xxx-%s' % time.strftime('%y%m%d'))
I'm not sure if I understand what your question is but in general you don't have to create any functions or anything to configure your logger.
What you should do create a logger and assign it a
FileHandler and then just use your created logger to log your info.
import logging logger = logging.getLogger('mylogger') # skip name for global rules fh = logging.FileHandler(LOG_FILE_DIR, mode='a') logger.addHandler(fh)
You can put this anywhere that gets executed on program startup, like
__init__.py or something.
Now when you want to log something just:
logger = logging.getLogger('mylogger') logger.error("error happened, oh no!")
Official Python logging tutorial can be found here