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 LOG_FILE_APPEND to settings #5279

Merged
merged 3 commits into from
Oct 18, 2021

Conversation

erikkemperman
Copy link
Contributor

@erikkemperman erikkemperman commented Oct 15, 2021

Hi,

First of all, thanks for a great tool!

I wanted to truncate my logfile at every new run, but noticed that the logfile is opened with mode='a' and there's no way to override that. So I made a PR which allows us to pass a LOG_FILE_TRUNCATE setting, defaulting to False. If it's set to True, the logfile will be opened with mode='w'. The setting has no effect unless LOG_FILE is set, obviously.

Hopefully I've added sufficient info to the docs to explain this item.

I've also added a test, although it seems slightly out of place in test_crawler.py -- I put it there because it's the only file in the tests directory where I found an occurrence of LOG_FILE.

Copy link
Member

@Gallaecio Gallaecio left a comment

Choose a reason for hiding this comment

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

Nice work!

docs/topics/logging.rst Outdated Show resolved Hide resolved
@erikkemperman erikkemperman force-pushed the option-logfile-truncate branch from d916450 to b78fad1 Compare October 15, 2021 14:28
@erikkemperman
Copy link
Contributor Author

Changed to APPEND. I'm baffled why it says here I started a review, certainly that wasn't my intention :-)

@erikkemperman erikkemperman force-pushed the option-logfile-truncate branch from b78fad1 to 7cd907f Compare October 15, 2021 14:35
@erikkemperman erikkemperman force-pushed the option-logfile-truncate branch from 7cd907f to ca320fe Compare October 15, 2021 14:36
@erikkemperman
Copy link
Contributor Author

(Sorry, I forgot to change the commit message)

@erikkemperman erikkemperman changed the title Add LOG_FILE_TRUNCATE to settings Add LOG_FILE_APPEND to settings Oct 15, 2021
@Gallaecio
Copy link
Member

Don’t worry about keeping the commit history clean, we will probably squash your changes into a single commit upon merging anyway.

@codecov
Copy link

codecov bot commented Oct 15, 2021

Codecov Report

Merging #5279 (b85207e) into master (5b13bfd) will decrease coverage by 0.02%.
The diff coverage is 100.00%.

❗ Current head b85207e differs from pull request most recent head d774d6a. Consider uploading reports for the commit d774d6a to get more accurate results

@@            Coverage Diff             @@
##           master    #5279      +/-   ##
==========================================
- Coverage   88.52%   88.49%   -0.03%     
==========================================
  Files         163      163              
  Lines       10608    10608              
  Branches     1557     1527      -30     
==========================================
- Hits         9391     9388       -3     
- Misses        942      945       +3     
  Partials      275      275              
Impacted Files Coverage Δ
scrapy/settings/default_settings.py 98.75% <100.00%> (+<0.01%) ⬆️
scrapy/utils/log.py 89.36% <100.00%> (+0.11%) ⬆️
scrapy/downloadermiddlewares/cookies.py 94.80% <0.00%> (-2.60%) ⬇️
scrapy/shell.py 67.96% <0.00%> (-0.79%) ⬇️
scrapy/http/response/__init__.py 97.43% <0.00%> (-0.04%) ⬇️
scrapy/http/request/__init__.py 97.77% <0.00%> (-0.03%) ⬇️
scrapy/utils/python.py 87.64% <0.00%> (ø)
scrapy/commands/check.py 71.01% <0.00%> (ø)

@erikkemperman
Copy link
Contributor Author

Ah, sloppy/paste in the test function: thanks for removing the unused variable!

@wRAR wRAR merged commit afa5881 into scrapy:master Oct 18, 2021
@erikkemperman
Copy link
Contributor Author

Thanks for review and merge!

By the way, I looked into the problem with recent flake8 versions -- i.e., the reason why you had to add 98ee3dd.

I've submitted a PR which would, I think, resolve the issue here:
tholo/pytest-flake8#82

If that were to be accepted, merged and released, then scrapy could drop this version pin and use latest flake8 releases.

@Gallaecio
Copy link
Member

That’s awesome. However, freezing these static checks, and upgrading them manually regularly (e.g. after a release) is something we are actually moving towards. Even if bug free, new versions of checkers may introduce new checks that our code does not pass in master, and having pull requests fail in CI because of static check tool upgrades can be confusing for contributors.

@erikkemperman
Copy link
Contributor Author

Fair enough -- but at least you'll have the option of pinning it to the current major release, if you wanted to. (Well, if that PR is accepted, anyway).

@erikkemperman erikkemperman deleted the option-logfile-truncate branch October 21, 2021 21:23
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.

3 participants