In this snippet we're using log_message() to log messages of different severity levels (error, debug, info). Depending on the condition, we log different messages. Ensure that logging is enabled and properly configured in your CodeIgniter 4 application.
Configuration
In CodeIgniter 4, the Logger class provides several threshold levels to filter log messages based on their severity. These threshold levels are used to determine which log messages should be recorded. Here are the threshold levels available in CodeIgniter 4:- emergency: System is unusable.
- alert: Action must be taken immediately.
- critical: Critical conditions.
- error: Error conditions.
- warning: Warning conditions.
- notice: Normal but significant condition.
- info: Informational messages.
- debug: Debug-level messages.
You can adjust the threshold level according to your application's requirements. Any log message with a severity level equal to or lower than the specified threshold will be recorded in the log file.Source code viewer
// This will log messages of severity "error" and lower. public $threshold = 3;Programming Language: PHP
Log function
Source code viewer
log_message('info', 'Log an info message.');Programming Language: PHP