aagjalpankaj / logstan
PHPStan extension for Laravel applications to enforce consistent logging practices.
Requires
- php: ^8.2
- illuminate/support: ^11.0|^12.0
- laravel/prompts: ^0.3
- phpstan/phpstan: ^2.0
- symfony/console: ^7.0
Requires (Dev)
- laravel/pint: ^1.21
- pestphp/pest: ^3.8
- rector/rector: ^2.0
This package is auto-updated.
Last update: 2025-08-09 05:57:34 UTC
README
About
LogStan is a PHPStan extension that helps you to enforce structured and consistent logging in Laravel.
Example Output
./vendor/bin/logstan analyse ------ -------------------------------------------------------------------------------------------- Line Actions/CreateOrderAction.php ------ -------------------------------------------------------------------------------------------- 21 Log message "order created" should start with an uppercase letter. 67 Log context key "orderId" should be in snake_case format. 94 Log context has too many keys (11). Maximum allowed are 10. ------ -------------------------------------------------------------------------------------------- ------ -------------------------------------------------------------------------------------------- Line Services/ShopifyService.php ------ -------------------------------------------------------------------------------------------- 57 Log context value of key "order" must be scalar, null or array of scalar. "App\Models\Order" provided. ------ -------------------------------------------------------------------------------------------- [ERROR] Found 4 errors
Installation | Usage | Logging standards enforced
Installation
composer require --dev aagjalpankaj/logstan
Usage
Analyzing Logs
./vendor/bin/logstan analyse
This command will scan your application and report any inconsistencies or potential problems with the logs in your application.
Getting Insights
./vendor/bin/logstan insights
This command provides insights about logs in your application.
Help
For more information about available commands and options:
./vendor/bin/logstan --help
Logging standards enforced
Logstan ensures your Laravel application follows best practices for logging by enforcing the following standards:
Log Messages
Standard | Description |
---|---|
✅ Non-empty requirement | All log messages must contain meaningful content |
✅ Character limit | Messages are validated against maximum length constraints |
✅ Proper capitalization | Messages must begin with uppercase letters for consistency |
Log Context
Standard | Description |
---|---|
✅ Array structure | Context data must be provided as a properly formatted array |
✅ Key limit | Maximum of 10 context keys to maintain readability |
✅ Naming convention | Keys must use snake_case format and be non-empty strings |
✅ Data types | Values restricted to scalar types or null (arrays/objects prohibited) |
✅ Value length | Context values limited to 100 characters maximum |
✅ Security compliance | Automatic detection and prevention of sensitive information in keys |
Contributing
Found a bug or have a feature request? We'd love to hear from you!
- 🐛 Report Issues: Create an issue
- 💡 Feature Requests: Start a discussion
- 🤝 Pull Requests: Contributions are welcome!
License
This package is open-sourced software licensed under the MIT license.