나는 scrapy 1.1.0을 사용하고 있으며 "거미"폴더에 5 개의 거미가 있습니다.python3 로깅 모듈 문제를 이용한 치료
모든 스파이더에서 나는 python3 로깅 모듈을 사용하려고합니다. 그리고이 같은 코드 구조 :
import other modules
import logging
class ExampleSpider(scrapy.Spider):
name = 'special'
def __init__(self):
# other initializations
# set log
self.log = logging.getLogger('special')
self.log.setLevel(logging.DEBUG)
logFormatter = logging.Formatter('%(asctime)s %(levelname)s: %(message)s')
# file handler
fileHandler = logging.FileHandler(LOG_PATH) # LOG_PATH has defined
fileHandler.setLevel(logging.DEBUG)
fileHandler.setFormatter(logFormater)
self.log.addHandler(fileHandler)
# other functions
모든 거미가 나는이 거미를 실행 같은 structure.When을 가지고, 나는 그들이 존재 않은 로그 파일을 확인하지만, 그 크기는 항상 0 바이트입니다.
다른 질문은 하나의 스파이더를 실행할 때 항상 두 개 이상의 로그 파일을 생성한다는 것입니다. 나는 a
스파이더를 실행하는 것처럼 a.log
과 b.log
을 생성합니다.
모든 답변을 주시면 감사하겠습니다.
당신은 아무것도를 기록하는'self.log'를 사용하십니까? 즉'self.log.warning ('something')'? scrapy는 자신의 로거와 다른 모든 구성 요소를 가지고 있습니다. 여기에서하는 일은 로거에 대해서만 파일 처리기 등을 설정하는 것입니다. – Granitosaurus
@Granitosaurus 내가 원하는 것은 scrapy 출력을 로그 파일로 저장하는 것이며, 이제는 scrapy (버전 1.1.0)가 Python 표준 로깅에 대한 명시 적 호출을 위해 함수와 함께 더 이상 사용되지 않음을 알고 있습니다. –