Feature Request: Add php artisan logs:clear to prevent log accumulation in long-lived systems #56282
Replies: 1 comment 5 replies
-
If you are in a position to depend on file logging like you describe and you don't have a devops team to solve this for you using file beat for example or not using files at all but stdout etc., then the fastest solution would be for you to add that command in your projects. Also you should not delete the files in production but move them in archive and then delete them from the archive after some months or years and by doing this, it would make the laravel built-in delete command overhead for production usage and just usable for local development. |
Beta Was this translation helpful? Give feedback.
5 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Context
I maintain and oversee more than 20 Laravel-based systems running in production environments, active continuously since 2021. Each system handles over 1,000 users daily. Over time, without proper log rotation in place, the default
storage/logs/laravel.log
files have accumulated over 5TB of raw log data across projects.Even though I have access to a 100TB server infrastructure, this behavior leads to real problems:
The Problem
Laravel's current default uses the
single
channel unless configured otherwise. While thedaily
driver exists and is a better practice, many production systems are shipped without log rotation awareness — especially in long-lived deployments across multiple teams, such as in government, education, or telecom infrastructures.Today, if you want to delete old logs, you must manually write custom commands or scripts to clean the
storage/logs/
directory.Proposed Solution
Add a built-in Artisan command:
Behavior:
Delete all .log and .log.* files under storage/logs
Optional flags:
--dry-run → list what would be deleted
--keep-days=30 → retain logs from the last 30 days only
--path=custom/path → support logs in different locations
This would match other convenience commands in Laravel like cache:clear, queue:flush, etc., and could be easily extended by developers.
Why This Matters
Laravel is used in long-term infrastructures where developers may rotate, and deployment scripts may stay unchanged for years.
logs:clear improves DX (Developer Experience) and server hygiene with zero risk.
Prevents catastrophic server outages caused by forgotten laravel.log growth (especially in debug mode).
Reduces reliance on external solutions when Laravel could handle this natively.
Final Notes
I’m happy to contribute a PR if the team is open to including this in core. Otherwise, I'd suggest at least documenting best practices for log rotation more explicitly in the logging documentation.
Let me know your thoughts!
Beta Was this translation helpful? Give feedback.
All reactions