You're currently:
ERROR
level."is_system_error": true/false
.This works, but becomes a pain when filtering large logs.
The PSR-3 logging standard (widely followed in the PHP and Laravel world) defines log levels and intended usage, but it does not dictate exactly what to log at which level in terms of domain logic. However, it does provide strong guidelines:
Level | Description |
---|---|
emergency |
System is unusable |
alert |
Immediate action required |
critical |
Critical conditions (e.g., app component unavailable) |
error |
Runtime errors that do not require immediate action but should be logged |
warning |
Exceptional occurrences that are not errors |
notice |
Normal but significant condition |
info |
Interesting events (e.g., user logins, SQL logs) |
debug |
Detailed debug info |
error
and above (critical
, alert
) for things like DB failure, exceptions, service unavailability.warning
or notice
for invalid input, failed validations, wrong OTP, etc.✅ Pros:
⚠️ Cons:
warning
vs error
.// User enters wrong OTP
Log::warning('OTP verification failed', ['user_id' => 123]);
// DB connection failed
Log::error('Database connection error', ['exception' => $e]);
error
, Add Context (is_system_error
)What you're doing now is also totally valid — especially if you have centralized log processing (e.g., ELK/Logstash or Loki with Grafana), where you can filter by structured fields.
✅ Pros:
error
logs.⚠️ Cons:
You can combine both approaches for maximum clarity and compatibility with community norms:
error
and above for system-related failures (crashes, exceptions, DB issues).warning
for user-triggered issues (invalid OTP, validation fails, payment declined).error_type: "user"
or is_system_error: true
for extra filtering power.This hybrid gives you:
If you're using Laravel with Monolog under the hood, consider using custom channels or processors to enrich logs further or even split logs by type (user.log
, system.log
, etc.).
a-h-abid liked this reply
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community