The currently available devel debug functions (dsm, dpm, dprint_r, etc...) allow you to print messages to the screen or using drupal_set_message, and styles them nicely. However, there are some situations where you need to print data to the dblog (using watchdog), for instance for scripts triggered by cron and run as the anonymous user. Currently the only way to do this is something like watchdog('debug', print_r($data, 1));
.
It would be great if there was a devel function to do this more easily, and to style the resulting output (instead of getting gross print_r output).
Comment | File | Size | Author |
---|---|---|---|
#17 | Screen Shot 2018-08-18 at 12.48.18 AM.png | 125.75 KB | rajiv.singh |
Issue fork devel-989858
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #1
moshe weitzman CreditAttribution: moshe weitzman commentedi'm not aware of anything less gross. also note that we have dd() for writing to a log file.
Comment #2
Dane Powell CreditAttribution: Dane Powell commentedHrm... I can't believe that no one else but me has this problem. How else do you get a pretty-printed array from a function that runs during cron, in a drush script, etc... ? Currently, I have to var_export to the dblog, then copy and paste the output into a PHP script that evals it and then reprints the array using Krumo. This is crazy, there should really be a more streamlined way of accomplishing this.
Comment #3
ergonlogic@Dane Powell: You're not alone. I'd love to see a solution for this.
Comment #4
moshe weitzman CreditAttribution: moshe weitzman commentedkrumo is too huge to put into a watchdog msg. i think you have to write a function that will write the krumo output to a .html file. not likely to be added by drush core.
Comment #5
xurizaemonMoshe is right that watchdog may get angry if you do this to it; even a relatively small form definition array will end up at around 100K when you've kprint_r()'d it.
I don't expect this to get into devel module, but I have been using this a little so I figured I'd sandbox it for others to try adding dpw() (Drupal Print Watchdog) to your toolkit. So here you go.
* http://drupal.org/sandbox/grobot/1124300
Comment #6
Dane Powell CreditAttribution: Dane Powell commentedThanks for the info grobot- I totally understand why this would be a bad idea. But I will only ever be using this on a development site that will just get deleted afterwards anyway, so this would be very useful. Thanks!
Comment #7
Les LimIt may be a bad idea to store large structures in {watchdog}, but I don't see any reason why we can't have a dedicated table for such things. I just committed a module with that in mind:
http://drupal.org/project/object_log
I've been using it to help debug a web service project for a couple weeks and it's been a great time-saver.
Comment #8
fureigh CreditAttribution: fureigh commentedThanks for posting about that module, Les Lim.
Comment #9
pyry_p CreditAttribution: pyry_p commentedAs a workaround I stored the data in variable_set() and print at nice place.
Comment #10
xurizaemonpyry_p variables table is a horrible place to be pooping random data, consider cache_set instead perhaps?
not that spamming the watchdog table is a good idea either, but variables table, no no no
Comment #11
pyry_p CreditAttribution: pyry_p commentedGrobot: That is really alot better idea. I was doing variable_set in qa- and temp enviroments which i overwrite often. But with cache based variable I think possible ajax debugging at trunk and production will be lot safer. I will keep the variable table still "in the toolbox" tho if i need to build features that clear caches.
Comment #12
nicholas.alipaz CreditAttribution: nicholas.alipaz commentedI really like the object_log module and wish it were part of devel, as it only makes sense to be here IMO. Thanks Les for writing the module.
A new dpl() function would be a wonderful way handle it. Devel Print Log
Comment #13
drupalfan79 CreditAttribution: drupalfan79 commentedshow variables in devel way with watchdog:
Comment #14
Marko B CreditAttribution: Marko B commentedVery cool drupalfan79, thanx
Comment #15
kmajzlik CreditAttribution: kmajzlik commented#13 fails on PHP 5.4 (can not add function call as parameter)
Improved code taken from http://cgit.drupalcode.org/sandbox-grobot-1124300/commit/?id=f6fe936 :
Comment #16
rajiv.singh CreditAttribution: rajiv.singh commentedHere is my handy solution to print array/object in watchdog item
in the style of devel debug functions (dsm, dpm, dprint_r, etc...)
How to use it ?
Now go to admin/reports/dblog and click the message of "devel debug" item
Comment #17
rajiv.singh CreditAttribution: rajiv.singh commentedComment #18
gopisathya CreditAttribution: gopisathya commented#15 is working.
Comment #19
gravisrs CreditAttribution: gravisrs commentedFor smaller values you can print values to watchdog using pretty print json within