4

For some reason I couldn't use devel to debug output object arrays. Is there a way to output the array data to watchdog error reporting? This would also solve the issue of having to install or enable another module.

9

You can use watchdog but the message part should be translatable, so any variables should use placeholders defined in the variables array. Check out format_string to see how these should work.

watchdog(
  'my_module_name',
  'Here is the printed variable: <pre>@placeholder_name</pre>',
  array('@placeholder_name' => print_r( $my_variable, TRUE)),
  WATCHDOG_INFO
);

Also, convention dictates that the first parameter, $type, should be the module name calling watchdog.

9

You can do the following to output array data to be viewed in watchdog:

// Directly use values.
watchdog("log_name", '<pre>' . print_r( $my_object, true) . '</pre>');

Then goto /admin/reports and look for "log_name".

  • 1
    Watchdog runs through the translation function, so you need to use variables. See my answer. – featherbelly Jul 25 '17 at 10:52
2

If you don't mind enabling another module, though, I wrote Object Log for just this kind of thing:

https://www.drupal.org/project/object_log

It's lightweight, easier to use in code, more user-friendly to view, and doesn't get pushed down the log as other log events are recorded.

  • rather not install another module. not exactly practical if I only needed to do it once to see the array output. thanks tho. – Patoshi パトシ Jan 26 '16 at 0:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.