The error_log Function

The error_log function allows writing error messages to the system log, a specified file, or sending them via email. The first parameter is the message, the second - the log type (0 for system log, 1 for email, 3 for file), the third - the destination address (file or email), and the fourth - additional headers for email.

Syntax

phperror_log(message, message_type, destination, extra_headers);

Example

Writing a message to the system log:

php<?php
  error_log('Database connection failed', 0);
?>

Example

Writing an error to the file /var/log/php_errors.log:

php<?php
  error_log('Invalid user input', 3, '/var/log/php_errors.log');
?>

Example

Sending an error message via email:

php<?php
  $to = 'admin@example.com';
  $subject = 'Critical error';
  $headers = 'From: webmaster@example.com';
  error_log($subject, 1, $to, $headers);
?>

See Also