Is there a way to change the log message format in scrapy?

I would like to modify the scrapy log messages to contain the user id at the beginning of it. for example instead

2015-03-03 17:09:34+0530 [scrapy] INFO: Enabled spider middlewares: HttpErrorMiddleware, OffsiteMiddleware, RefererMiddleware, UrlLengthMiddleware, DepthMiddleware

Is it possible that he looked like

**user_id**:2015-03-03 17:09:34+0530 [scrapy] INFO: Enabled spider middlewares: HttpErrorMiddleware, OffsiteMiddleware, RefererMiddleware, UrlLengthMiddleware, DepthMiddleware

Additionally, there is a way to register only user messages; ie: register only those messages that I want to register, which I put from the code?

Any help would be greatly appreciated. Thanks in advance!

+4
source share
2 answers

Scrapy , . , , .

. , scrapy,

LOG_ENABLED = False

settings.py. ( )

logging.basicConfig(level=logging.DEBUG, format='%(asctime)s %(levelname)8s\t%(message)s', )

logging.log, logging.info, logging.debug ..

.

+2

settings.py

LOG_FORMAT = user_id +' %(asctime)s %(levelname)8s\t%(message)s'

https://doc.scrapy.org/en/latest/topics/logging.html#logging-settings

+1

All Articles