欢迎各位兄弟 发布技术文章

这里的技术是共享的

You are here

drupal drupal7 肯定行 看门狗日志 watchdog 自定义记录日志 写入日志 到 数据库 drupal 中 在 /admin/reports/dblog 查看How to log error message in drupal 有大用 有大大用

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.



4 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.

shareimprove this answeranswered Nov 10 '09 at 5:45Pascal MARTIN307k55555594

3 $type is generally the name of the module you are developing. – Anyul Rivas Feb 23 '15 at 22:21 

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)
shareimprove this answeredited May 30 '13 at 17:18Stephen Schrauger2631314answered Nov 10 '09 at 8:14AlexA2,02463976

   Just installed the Drupal for Firebug extension - pretty sweet. – DilbertDave Nov 10 '09 at 9:01

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.

shareimprove this answeranswered Mar 21 '16 at 17:02milkovsky5,50631826

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).

http://api.drupal.org/api/function/drupal_set_message/6

shareimprove this answeranswered Nov 10 '09 at 8:54DilbertDave1,68112434

来自  https://stackoverflow.com/questions/1705840/how-to-log-error-message-in-drupal

普通分类: