log_message()

log_message($level, $message)

Parameters:
  • $level (string) – Log level: ‘error’, ‘debug’ or ‘info’
  • $message (string) – Message to log
Return type:

void

This function lets you write messages to your log files. You must supply one of three “levels” in the first parameter, indicating what type of message it is (debug, error, info), with the message itself in the second parameter.

Example:

if ($some_var == '')
{
        log_message('error', 'Some variable did not contain a value.');
}
else
{
        log_message('debug', 'Some variable was correctly set');
}

log_message('info', 'The purpose of some variable is to provide some value.');

There are three message types:

  1. Error Messages. These are actual errors, such as PHP errors or user errors.
  2. Debug Messages. These are messages that assist in debugging. For example, if a class has been initialized, you could log this as debugging info.
  3. Informational Messages. These are the lowest priority messages, simply giving information regarding some process.

Note

In order for the log file to actually be written, the logs/ directory must be writable. In addition, you must set the “threshold” for logging in application/config/config.php. You might, for example, only want error messages to be logged, and not the other two types. If you set it to zero logging will be disabled.

doc_CodeIgniter
2016-10-15 16:32:29
Comments
Leave a Comment

Please login to continue.