User login

Calling watchdog function (logging info) in Drupal 6

In Drupal 6, the way watchdog() is used has changed a bit.

It's all defined in the API, of course, but some things could use a little more clarification.

Here's the function definition as a starting point:
http://api.drupal.org/api/function/watchdog/6

<?php
function watchdog($type, $message, $variables = array(), $severity = WATCHDOG_NOTICE, $link = NULL)
?>

And Agaric's explanation of watchdog's parameters, in we hope something closer to layman's terms:

  • $type is typically the module name (the module from which you are calling watchdog).
  • $message is your error message. You can use percent-style (and I suppose other) placeholders (%placeholder) but do not wrap your text in the t() function— this function will be called by the various implementations of hook_watchdog.
  • $variables is an array holding your placeholders in '%placeholder' => $placeholder syntax.
  • $severity is what you might have been thinking for "type." watchdog_severity_levels defines a slew of them, but you will probably most often be using the default WATCHDOG_NOTICE or replacing it with WATCHDOG_ERROR.

See a simple example of watchdog being called in action (er, honestly, no pun intended) in actions_save().

Resolution

Searched words: 
logging reports D6 save error or notice information to watchdog table log notices, errors, alerts the Drupal way

Comments

+1

+1

Post new comment

The content of this field is kept private and will not be shown publicly.
  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.
  • You can use Markdown syntax to format and style the text. Also see Markdown Extra for tables, footnotes, and more.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <img> <blockquote> <small> <h2> <h3> <h4> <h5> <h6> <sub> <sup> <p> <br> <strike> <table> <tr> <td> <thead> <th> <tbody> <tt> <output>
  • Lines and paragraphs break automatically.

More information about formatting options

By submitting this form, you accept the Mollom privacy policy.