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

Crawler logs are cut by day #3628

Open
Lingshuirong opened this issue Feb 15, 2019 · 18 comments · May be fixed by #4465, #4844, #6155 or #5815
Open

Crawler logs are cut by day #3628

Lingshuirong opened this issue Feb 15, 2019 · 18 comments · May be fixed by #4465, #4844, #6155 or #5815

Comments

@Lingshuirong
Copy link

I hope scrapy's log can provide more convenience, such as crawlers running for a long time, log can be cut by day, so that the log file is not too large.

@MeiK2333
Copy link

Scrapy seems to use logging inside.

You can have a look: https://docs.python.org/3/library/logging.handlers.html#timedrotatingfilehandler

@VMRuiz
Copy link
Contributor

VMRuiz commented Mar 14, 2019

Also, you could use an external unix tool to directly rotate the logs files without having to make changes on how Scrapy works with logs: https://www.tutorialspoint.com/unix_commands/logrotate.htm

@kmike
Copy link
Member

kmike commented Jul 10, 2019

If that's possible to do using stdlib logging module, it would be nice to document how. Pull requests are welcome!

@phoenikx
Copy link

I am working on this, will raise a pull request

@Roman519
Copy link

Is it worked on? If not, I'm going to work on it.

@Gallaecio
Copy link
Member

@Roman519 Go for it! 😃

@Roman519
Copy link

Roman519 commented Sep 6, 2019

I've shoe horned a TimedRotatingFileHandler into root logger by way of log.configure_logging function. Do I need to add unit tests for something as simple as this. I'm asking because the default root filehandler doesn't have a unit test that I can see.

@Gallaecio
Copy link
Member

We are trying for new patches to provide complete coverage of their changes, so that we eventually reach that sweet 100% test coverage. So unless the tests are really difficult to write, it would be great to have them.

@jessekoconnor
Copy link

jessekoconnor commented Oct 28, 2019

Is this being worked on? Looks interesting, would like to contribute if theres not a pr I missed :D

@Gallaecio
Copy link
Member

There is no pull request at the moment, I believe.

@Urahara
Copy link

Urahara commented Nov 19, 2019

@Gallaecio in my scrapy projects i configure log handlers in settings.py like this:

from logging.handlers import TimedRotatingFileHandler
from scrapy.utils.log import configure_logging

logHandler = TimedRotatingFileHandler('crawl.log', when='midnight', interval=1)
configure_logging(install_root_handler=False)
logging.basicConfig(
    format='%(asctime)s [%(name)s] %(levelname)s: %(message)s',
    level=logging.INFO,
    handlers=[logHandler])

Is this right approach?

@Gallaecio
Copy link
Member

It does look like the recommended approach in the documentation.

@vaibhavdesai16
Copy link

@Gallaecio is there pull request for this enhancement? I am interested to contribute.

@Gallaecio
Copy link
Member

No pull request at the moment.

rindhane added a commit to rindhane/scrapy that referenced this issue Mar 31, 2020
	- Modified _get_handler method to return TimedRotatingFileHandler
	  if LOG_ROTATION variable is set to True in settings.
	- This enhancement is regards to issue : Crawler logs are cut by day scrapy#3628

 Changes to be committed:
	modified:   scrapy/utils/log.py
@rindhane
Copy link

@kmike @Gallaecio, could you check the modification proposed in #4465? I think this will provide the requested enhancement.
If it looks suitable, I will go-ahead and prepare the documentation and tests accordingly.

@MrAnderson-1999
Copy link

Hi!
is it still relevant?

@Gallaecio
Copy link
Member

Still relevant, with 3 stale, open pull requests.

@DinkyC
Copy link

DinkyC commented Nov 20, 2023

Could I go ahead and take a stab at this and complete the stale pull requests? I'm a new contributor and would love to help out.

DinkyC added a commit to DinkyC/scrapy that referenced this issue Nov 25, 2023
DinkyC added a commit to DinkyC/scrapy that referenced this issue Nov 25, 2023
DinkyC added a commit to DinkyC/scrapy that referenced this issue Nov 25, 2023
@DinkyC DinkyC linked a pull request Nov 25, 2023 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment