Page tree
Skip to end of metadata
Go to start of metadata

There are two methods you can use to debug variables in FreePBX

dbug

The dbug() function is the official debug function for FreePBX. The dbug() function is your friend and in invaluable resource when trying to figure out why that query isn’t returning the results you excepted or why the post seems to be returned blank. Think of dbug() as php’s builtin print_r()/var_dump(), time stamping, and logging all rolled in to one simple function.

By default, dbug() stores all its output to /var/log/asterisk/freepbx_dbug - but you don’t have to remember this path. You can use this handy shortcut from the linux cli to bring up the debug output:

fwconsole dbug

This tails the log file for you, continuously reading from it. It will also attempt to read from the httpd error log, assuming it is in the default location.

OUT > ==> /var/log/asterisk/freepbx_dbug <==
 'load_view failed to load view for inclusion:':
/usr/src/freepbx/ucp/htdocs/modules/oembranding/views/ucp_footer_content.php


2018-Oct-30 13:41:08	/usr/src/freepbx/ucp/htdocs/index.php:271


hi

dbug() only works when you are actively running: fwconsole dbug. If you want output from dbug to always be writing into freepbx_debug.log then go to Advanced Settings and set “Disable FreePBX dbug Logging” to false

So we have dbug() logging enabled and we have the log up. Now we need to insert a dbug() call. Using dbug() is relay quite simple, you can pass it 1-3 arguments:

dbug('string');

Will output your string. The logfile will also include the filename and even the line name where the dbug() function is located. You can use this to “step through” your code.

dbug('my var', $var);

In this case, you will probably want to set the string to something informative (although you don’t have to), and include the variable to be output. This will allow you to see what going on “inside” your variable. This is especially useful with arrays.

dbug('my var', $var, 1);

This last example is most extreme and while its basically a repeat of the last example, it outputs and array using var_dump() (instead of print_r()) which give a more accurate expression of whats in side that array.

When developing, this function is one of the most handy to have laying around.

There are several 'modes' to using dbug

  • dbug() - will just print a time stamp to the debug log file ($amp_conf['FPBXDBUGFILE'])
  • dbug('string') - same as above + will print the string
  • dbug('string',$array) - same as above + will print_r the array after the message
  • dbug($array) - will print_r the array with no message (just a time stamp)
  • dbug('string',$array,1) - same as above + will var_dump the array
  • dbug($array,1) - will var_dump the array with no message (just a time stamp)

PHPConsole

Additionally you can also enable PHP Console from Advanced Settings and then utilize chrome and this extension (https://chrome.google.com/webstore/detail/php-console/nfhmhhlpfleoednkpnnnkolmclajemef)

Then utilizing the Chrome Developer Console you will be able to see errors from PHP, including anything you've sent from the dbug() statements

  • No labels