Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add setting key allowing to customize logging #31

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions scrapyrt/conf/default_settings.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
# -*- coding: utf-8 -*-
"""Default scrapyrt settings."""
import logging

# Project settings module - found at server initialization

PROJECT_SETTINGS = None

# Path to server log file
Expand All @@ -12,6 +14,8 @@

LOG_ENCODING = 'utf-8'

LOG_LEVEL = logging.DEBUG

# Root server resource, should inherit from scrapyrt.resources.RealtimeAPI
SERVICE_ROOT = 'scrapyrt.resources.RealtimeApi'

Expand Down
4 changes: 3 additions & 1 deletion scrapyrt/core.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# -*- coding: utf-8 -*-
import logging
from collections import OrderedDict
from copy import deepcopy
import datetime
Expand Down Expand Up @@ -272,10 +273,11 @@ def create_spider_request(self, kwargs):
# It is needed because in POST handler we can pass
# all possible requests kwargs, so it is easy to make mistakes.
message = "Error while creating Request, {}".format(e.message)
log.msg(message, level=logging.WARNING)
raise Error('400', message=message)

req.dont_filter = True
msg = u"Created request for spider {} with url {} and kwargs {}"
msg = msg.format(self.spider_name, url, repr(kwargs))
log.msg(msg)
log.msg(msg, level=logging.DEBUG)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd prefer to keep log.msg and log.err for backwards compatibility and switch to logging. Keep in mind that ScrapyRT was developed before Scrapy 1.0 release with logging support, so logging handling in ScrapyRT is a bit outdated and can be improved.

return req
5 changes: 4 additions & 1 deletion scrapyrt/log.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@


def msg(message=None, **kwargs):
kwargs['logLevel'] = kwargs.pop('level', INFO)
loglevel = kwargs.get('level', INFO)
configured_log_level = scrapyrt_settings.LOG_LEVEL
if loglevel < configured_log_level:
return
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ugh, why it isn't implemented as logging filter?

kwargs.setdefault('system', 'scrapyrt')
if message is None:
log.msg(**kwargs)
Expand Down