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.
Hi,
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.
1) Indeed, watchdog is a standard way to record own PHP errors.
2) Alternatively, if you need to immediately see error messages while debugging your Drupal pages, you may want to see them logged/printed right at the related page - in FireBug console. Sometimes is this very convenient when you can see page-related just-in-time logs. This requires - Devel module, Firebug extension to FireFox and possibly Firephp.
You can use the dfb() function to write log messages directly to the general Firebug console.
dfb($input, $label = NULL)
If you want to keep your Drupal-related log messages out of the normal Firebug console, you can write messages to the Drupal for Firebug log with the firep() function:
firep($item, $optional_title)
Watchdog is the way to go for a production system no doubt but during debugging I find the drupal_set_message
function useful.
It outputs the message to the screen where the 'Operation Successful'-type messages are normally displayed (so make sure you remove them before making the site Live).