Skip to content

Commit

Permalink
fix logging
Browse files Browse the repository at this point in the history
  • Loading branch information
drjova committed May 18, 2022
1 parent 106cef0 commit a830eb0
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions hepcrawl/pipelines.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,7 @@ class InspireAPIPushPipeline(object):
def __init__(self):
self.count = 0
self.dois = []

def open_spider(self, spider):
self.logger = structlog.getLogger(name=spider.name)
self.logger = structlog.getLogger()

def process_item(self, item, spider):
"""Convert internal format to INSPIRE data model."""
Expand All @@ -103,12 +101,12 @@ def process_item(self, item, spider):
if 'dois' in item:
value = [doi['value'] for doi in item['dois']]
if len(value) > 0:
self.logger.info('Processing article.', doi=value[0])
self.logger.info('Processing article.', name=spider.name, doi=value[0])
self.dois.append(value)
else:
self.logger.error('Empty DOIs for this article.')
self.logger.error('Empty DOIs for this article.', name=spider.name)
else:
self.logger.error('Cannot find DOIs for the parsed articles.')
self.logger.error('Cannot find DOIs for the parsed articles.', name=spider.name)

if 'related_article_doi' in item:
item['dois'] += item.pop('related_article_doi', [])
Expand Down Expand Up @@ -239,9 +237,9 @@ def close_spider(self, spider):
requests.post(api_url, json={
"kwargs": self._prepare_payload(spider)
})
self.logger.info('Spider successfully send payload.', dois=self.dois, count=self.count)
self.logger.info('Spider successfully send payload.', name=spider.name, dois=self.dois, count=self.count)
else:
self.logger.error('Spider cannot send payload.', dois=self.dois, count=self.count)
self.logger.error('Spider cannot send payload.', name=spider.name, dois=self.dois, count=self.count)
self._cleanup(spider)


Expand Down

0 comments on commit a830eb0

Please sign in to comment.