Repository navigation
Conversation
kevinher7
marked this pull request as draft
October 7, 2026 11:50
kevinher7
force-pushed
the
fix/rotate-crawler-log
branch
from
October 7, 2026 11:51
27a6c9c to
b88f862
Compare
AsyncWebCrawler builds a default AsyncLogger that appends every message to <base_directory>/.crawl4ai/crawler.log, even with verbose=False, and never rotates it. In a long-lived container the file reached 1.1 GB. AsyncLogger and AsyncFileLogger now write through logging's RotatingFileHandler, capped at 10 MB with 3 backups. All loggers in a process that target the same path share one handler, so several crawlers rotate the file once instead of renaming it out from under each other. Rotation across processes is not coordinated, same as the standard library. Callers who need a different file policy can pass their own logger via AsyncWebCrawler(logger=...). The line format in the file is unchanged. Co-Authored-By: Claude Fable 5.1 <[email protected]>
kevinher7
force-pushed
the
fix/rotate-crawler-log
branch
from
October 7, 2026 11:57
b88f862 to
9ed415d
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
AsyncWebCrawler.__init__builds a defaultAsyncLoggerpointed at<base_directory>/.crawl4ai/crawler.logwhenever the caller passes nologger=.AsyncLogger._write_to_fileappends every message to that file, even withverbose=False(which only silences the console), and nothing rotates or caps it. In one of our long-running containers the file reached 1.1 GB before anyone noticed.async_database.pydoes the same forcrawler_db.log.This PR makes
AsyncLoggerandAsyncFileLoggerwrite through the standard library'sRotatingFileHandler, capped at 10 MB with 3 backups. Every logger in a process that targets the same path shares one handler, so several crawlers rotatecrawler.logonce instead of renaming it out from under each other. Rotation across processes is not coordinated, same asRotatingFileHandleritself.The line format written to the file is unchanged.
AsyncWebCrawlerandAsyncDatabaseManagerneed no changes; they pick up rotation through the default logger.Behaviour change to be aware of: the default goes from unbounded growth to a 10 MB cap with 3 backups. Anyone who needs a complete
crawler.loghistory, or a different policy, can pass their ownAsyncLoggerBaseviaAsyncWebCrawler(logger=...), which already works today.Related context: #264 confirms file logging was meant to stay on regardless of
verbose. This PR keeps that and only bounds the size.List of files changed and why
crawl4ai/async_logger.py-_get_file_handlerreturns a process-wideRotatingFileHandlerper path;_write_linesends a pre-formatted line through it.AsyncLoggerandAsyncFileLoggeruse the handler instead ofopen(..., "a").tests/loggers/test_log_rotation.py- two loggers on one path share a handler; with the cap lowered to 2 KB they producecrawler.logplus three backups, every file under the cap.How Has This Been Tested?
pytest tests/loggers/test_log_rotation.py tests/test_async_logger_stderr.pypasses.AsyncWebCrawlerinstances (no browser launched) withCRAWL4_AI_BASE_DIRECTORYpointed at a temp dir, lowered the cap to 5 KB, and logged 1200url_statuslines through them. Result:crawler.logplus three backups, each under the cap, all three crawlers sharing one handler.blackreports no issues on the added lines. The rest ofasync_logger.pywas left untouched since it is not black-formatted today and reformatting it would bury the change.Checklist:
🤖 Generated with Claude Code