-
Notifications
You must be signed in to change notification settings - Fork 324
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
Scutils log callbacks #92
Conversation
First off, this idea is great and I would like to incorporate this in. There are a handful of minor things we need to address before we can merge this in. Comments as follows:
Going to look into point 3 a bit more, as I can replicate it on only 1 of my local machines, but not the other. EDIT: Later commits to this branch have addressed all issues raised here. |
In continuing to investigate, point 2 I think is irrelevant, as I instantiate |
Cleaned up main.log and main.lock in new test class. Removed __init__.py from `tests/` to ensure nose can properly run the unit tests.
1 similar comment
Latest commit fixes points 3 and 4, just need to add documentation and test how this works within Scrapy. |
For point 5, the behavior is as follows: We will not have access to class instance variables, but the callback is available across the multithreaded/twisted process. What this means is that you can register your callback in one location, and it allows the scrapy item pipeline, scheduler, spider, etc to use/trigger the callback. In this case, you must decorate your method with The callback functionality works as expected using the
I will try to see if I can refactor some of the tests to remove that log_object dependency in the callback method, but on track to be merged in. |
1 similar comment
1 similar comment
Latest commit address Point 1. Looks good on all fronts. |
This PR provides a starting point for registering callbacks using the
LogFactory
. This PR addresses Issue #91Usage
Given a logging object
logger
, you can register a callback viaSome examples:
Explanation: The callback function
report
will fire when the.error()
logging method is calledExplanation: The callback function
add_1
will fire when.debug()
or.info()
are called AND the{'key': 'val1'} is a subdict of the
extras` passed to the logging functionsExplanation: The callback function
negate
will fire when.warning()
,.error()
, or.critical()
are called AND{'key': 'val2'}
is a subdict ofextras
passed to the logging functions.Explanation: The callback function
always_fire
will fire for all log levels with no concern of theextras
dict passed to the logging functions.Testing
Notes
The callbacks respect the log level. If the log level for a logger is CRITICAL then a
.debug()
invocation will not trigger the callbacks registered for CRITICAL.