For debug purposes I need to see both output of log messages and print statements when working with Scrapy. Hovewer, when I start Scrapy logger, I no longer see output of print statements! How should I modify the following sample code to see both print statements?
from scrapy import log
print 'PRINT OUTPUT BEFORE'
log.start(loglevel='DEBUG',logstdout=True)
print 'PRINT OUTPUT AFTER'
Output:
PRINT OUTPUT BEFORE
I beleive redirecting stderr or stdout may solve the problem. Any help would be greatly appreciated!
Python - Print Logs in a File. If you want to print python logs in a file rather than on the console then we can do so using the basicConfig() method by providing filename and filemode as parameter. The format of the message can be specified by using format parameter in basicConfig() method.
You should use the console. log() method to print to console JavaScript. The JavaScript console log function is mainly used for code debugging as it makes the JavaScript print the output to the console.
You can start by running the Scrapy tool with no arguments and it will print some usage help and the available commands: Scrapy X.Y - no active project Usage: scrapy <command> [options] [args] Available commands: crawl Run a spider fetch Fetch a URL using the Scrapy downloader [...]
logstdout
must be set to False to disable stdout from being redirected.
from scrapy import log
print 'PRINT OUTPUT BEFORE'
log.start(loglevel='DEBUG', logstdout=False)
print 'PRINT OUTPUT AFTER'
With output:
PRINT OUTPUT BEFORE
PRINT OUTPUT AFTER
I think above works for old version. They seems to have deprecated scrapy.log . Refer: https://docs.scrapy.org/en/latest/topics/logging.html
Eg:
import logging
logging.warning("This is a warning")
logging.info("This is an info")
logging.error("This is an error")
As my config was set to warn. I got only below
WARNING:root:This is a warning
ERROR:root:This is an error
Note that this is helpful if you are using scrapyd. As scrapy crawl will print all but scrapyd doesn't do same way.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With