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

Use a custom DropItem subclass #126

Merged
merged 7 commits into from
Dec 30, 2024
Merged

Use a custom DropItem subclass #126

merged 7 commits into from
Dec 30, 2024

Conversation

Gallaecio
Copy link
Contributor

@Gallaecio Gallaecio commented Dec 30, 2024

To enable custom logging to cleanly lower the message severity.

@Gallaecio Gallaecio changed the title Use a custom DropItem subclass to enable custom logging to cleanly lo… Use a custom DropItem subclass Dec 30, 2024
@Gallaecio Gallaecio marked this pull request as ready for review December 30, 2024 11:06
@Gallaecio Gallaecio requested review from kmike and wRAR December 30, 2024 11:06
Copy link

codecov bot commented Dec 30, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Please upload report for BASE (main@f87d98b). Learn more about missing BASE report.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #126   +/-   ##
=======================================
  Coverage        ?   97.58%           
=======================================
  Files           ?       63           
  Lines           ?     2364           
  Branches        ?        0           
=======================================
  Hits            ?     2307           
  Misses          ?       57           
  Partials        ?        0           
Files with missing lines Coverage Δ
zyte_common_items/pipelines.py 97.77% <100.00%> (ø)

@@ -56,6 +61,11 @@ def process_item(self, item, spider):
return ae.downgrade(item)


class InfoDropItem(DropItem):
"""DropItem subclass for items that should be dropped with an INFO message
(instead of the default WARNING message)."""
Copy link
Contributor

Choose a reason for hiding this comment

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

If this class is defined here, we should define the log formatter here as well (not in zyte-spider-templates-project).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Am I correct to assume that we should also enable the new formatter in the library add-on, and not in the project?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, it seems we should do it here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I meant the zyte-spider-templates library, given there is no add-on here. Or are you thinking we should add an add-on to zyte-common-items?

Copy link
Contributor

Choose a reason for hiding this comment

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

You're adding it in #124 already :)

Copy link
Contributor

Choose a reason for hiding this comment

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

As for the settings, it seems it'd be better to keep them in the project - as we discussed elsewhere, it might be simpler for addons not to configure other libraries. But I don't have a stong opinion on this.

@kmike kmike merged commit 4350d9b into zytedata:main Dec 30, 2024
9 checks passed
(instead of the default WARNING message)."""


class ZyteLogFormatter(LogFormatter):
Copy link
Contributor

Choose a reason for hiding this comment

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

Alternatively, we could allow to configure the severity level at Scrapy level via settings given that this is not the first time this has come up.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@kmike mentioned somewhere that maybe we should allow components to set their desired log level in the exception, e.g. raise DropItem(severity=INFO).

Maybe we could have a setting to implement the overall default log level, allow components to set a custom value through severity, and let components choose whether or not they respect the setting, force a given value, or provide their own setting to override their own request droppings.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants