Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to log error message in drupal

How to log our own error messages(for ex: error due to invalid user date entry) which is generated in php program to drupal error log.

like image 215
ArK Avatar asked Nov 10 '09 05:11

ArK


People also ask

How do I enable error reporting in Drupal?

You can show all errors by adding a few lines to your local testing site's settings. php: error_reporting(E_ALL); ini_set('display_errors', TRUE); ini_set('display_startup_errors', TRUE); In addition, navigate to Administration→ Configuration→ Development → logging and errors and select "All messages".

How do I display errors in Drupal 8?

To turn on the “Error Messages to Display”, go to the Administration menu, then go into Configuration > Development > Logging and errors (/admin/config/development/logging). You will find the following configuration. There are 4 options available, and the default setting is “None”.

How do I check Drupal logs?

To view entries in Drupal's own internal log system (the watchdog database table), go to http://example.com/admin/reports/dblog. These can include Drupal-specific errors as well as general PHP or MySQL errors that have been thrown. Use the watchdog() function to add an entry to this log from your own custom module.

What is Watchdog Drupal?

Developers familiar with Drupal 7 will also be familiar with watchdog(), an API function that allows you to create a log message that appears on the Reports page in the Drupal administrative UI. Implementing D7's hook_watchdog allows module developers to customize the destination of these log messages.


2 Answers

You can use the watchdog function :

watchdog($type, $message, $variables = array(), $severity = WATCHDOG_NOTICE, $link = NULL) 

Quoting the manual, the parameters are :

  • $type The category to which this message belongs.
  • $message The message to store in the log.
  • $variables Array of variables to replace in the message on display or NULL if message is already translated or not possible to translate.
  • $severity The severity of the message, as per RFC 3164
  • $link A link to associate with the message.

And the error levels can be found on the page of watchdog_severity_levels. For an error, you'll most probably use WATCHDOG_ERROR, or maybe even something more "critical", depending on the kind of error.

like image 113
Pascal MARTIN Avatar answered Oct 13 '22 01:10

Pascal MARTIN


Drupal 8

// Logs a notice \Drupal::logger('my_module')->notice($message); // Logs an error \Drupal::logger('my_module')->error($message); 

See more examples at How to Log Messages in Drupal 8.

like image 29
milkovsky Avatar answered Oct 13 '22 01:10

milkovsky