A log level is the severity attached to each log message, from debug for detail only a developer wants, up to emergency for a system that is unusable. One setting can then decide which messages are kept, where they are sent and which of them should wake someone up.
How it works
The eight levels PHP code uses come from the syslog standard, RFC 5424, which numbers them from 0 to 7. A lower number means a higher severity. With the names PSR-3 gives them and the RFC's descriptions:
0 emergency system is unusable
1 alert action must be taken immediately
2 critical critical conditions
3 error error conditions
4 warning warning conditions
5 notice normal but significant condition
6 info informational messages
7 debug debug-level messages
PSR-3, the shared PHP logger interface, has one method for each level, so $logger->warning() writes at warning. Laravel's Log facade offers the same eight through Monolog.
A log channel has a minimum level, and messages below it are not written. In Laravel this is the channel's level option. Laravel's documentation shows a Slack channel set to critical, which receives critical, alert and emergency messages and nothing else, next to a system log channel that takes everything from debug up.
Not every system counts the same way. OpenTelemetry's log data model uses severity numbers in six ranges, from TRACE to FATAL, where a larger number means more severe: the opposite direction to syslog.
Why it matters
Levels make a log usable at volume. Production can keep warnings and above while development keeps everything, and an alert can fire on error without firing on every info line. That only works if the code picks its levels consistently.
What can go wrong
- Everything is logged at error, so a filter on level filters nothing and alerts fire all day, which leads to alert fatigue.
- A real failure is logged at info or debug, and a production channel set to warning drops it.
- Production keeps logging at debug, because the channel reads
LOG_LEVELand falls back to debug when it is not set, and the volume hides the lines that matter. - Levels are mapped between two systems with opposite scales, and the most severe messages are read as the least severe.
Check it
With Laravel Pail installed, php artisan pail --level=error tails a Laravel application's logs at one level. Ranetrace's log monitoring filters records by level, and its Laravel SDK sends notice and above by default, a minimum you change with RANETRACE_LOGGING_LEVEL.
Read more
Start monitoring today
Websites go down and code throws errors. Ranetrace tells you when it happens to yours, why it matters and what to do next.