Scrapy provides a logging facility which can be used through the scrapy.log module. The current underlying implementation uses Twisted logging but this may change in the future.
The logging service must be explicitly started through the scrapy.log.start() function.
Scrapy provides 5 logging levels:
You can set the log level using the –loglevel/-L command line option, or using the LOG_LEVEL setting.
Here’s a quick example of how to log a message using the WARNING level:
from scrapy import log
log.msg("This is a warning", level=log.WARNING)
The recommended way to log from spiders is by using the Spider log() method, which already populates the spider argument of the scrapy.log.msg() function. The other arguments are passed directly to the msg() function.
A boolean which is True if logging has been started or False otherwise.
Start the logging facility. This must be called before actually logging any messages. Otherwise, messages logged before this call will get lost.
Parameters: |
|
---|
Log a message
Parameters: |
|
---|
Log level for critical errors
Log level for errors
Log level for warnings
Log level for informational messages (recommended level for production deployments)
Log level for debugging messages (recommended level for development)
These settings can be used to configure the logging: