Changeset 9260

Show
Ignore:
Timestamp:
03/17/10 05:07:14 (3 years ago)
Author:
mbrevda
Message:

new debuging function; amporal/fpbx command to view debug file ('fpbx a dbug')

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • freepbx/trunk/amp_conf/bin/freepbx_engine

    r8677 r9260  
    3939AMPVMUMASK=077 
    4040ASTETCDIR=/etc/asterisk 
     41FPBXDBUGFILE=/tmp/freepbx_debug.log 
    4142 
    4243. /etc/amportal.conf 
     
    312313        echo `wget http://mirror.freepbx.org/whatismyip.php -O - -q|sed 's/<[^>]*>//g'` 
    313314      ;; 
     315      dbug) 
     316        if [ -f $FPBXDBUGFILE ]; then  
     317          tail -f $FPBXDBUGFILE  
     318        else  
     319          touch tail -f $FPBXDBUGFILE 
     320          chown $AMPASTERISKUSER:$AMPASTERISKGROUP $FPBXDBUGFILE 
     321          tail -f $FPBXDBUGFILE 
     322        fi 
     323      ;; 
    314324    *) 
    315325 
     
    331341               contexts as they appear in extensions* files 
    332342${b}modadmin$bx|${b}ma$bx:   Runs the module_admin script with additional argument as passed 
    333 ${b}externalip$bx|${b}extip$bx: Returns the external ip from the default gateway    " 
     343${b}externalip$bx|${b}extip$bx: Returns the external ip for the default gateway     
     344${b}dbug$bx: shows the freepbx debug log file and any updates      
     345\n\n\n" 
    334346    ;; 
    335347  esac 
  • freepbx/trunk/amp_conf/htdocs/admin/functions.inc.php

    r9234 r9260  
    730730  'FOPWEBROOT'     => array('dir' , '/var/www/html/panel'), 
    731731  'MOHDIR'         => array('dir' , '/mohmp3'), 
     732  'FPBXDBUGFILE'   => array('dir' , '/tmp/freepbx_debug.log'), 
    732733 
    733734  'USECATEGORIES'  => array('bool' , true), 
     
    36793680  fclose($fh); 
    36803681} 
    3681 //lazy, I mean efficient, alias for function freepbx_debug 
     3682 /*  
     3683  * FreePBX Debuging function 
     3684  * This function can be called as follows: 
     3685  * dbug() - will just print a time stapm to the debug log file ($amp_conf['FPBXDBUGFILE']) 
     3686  * dbug('string') - same as above + will print the string 
     3687  * dbug('string',$array) - same as above + will print_r the array after the message 
     3688  * dbug($array) - will print_r the array with no message (just a time stamp)   
     3689  * dbug('string',$array,1) - same as above + will var_dump the array 
     3690  * dbug($array,1) - will var_dump the array with no message  (just a time stamp) 
     3691  *     
     3692  */   
    36823693function dbug(){ 
    3683   $args=func_get_args(); 
    3684   call_user_func_array('freepbx_debug',$args); 
    3685 
    3686  
     3694  $opts=func_get_args(); 
     3695  //call_user_func_array('freepbx_debug',$opts); 
     3696  $dump=0; 
     3697  //sort arguments 
     3698  switch(count($opts)){ 
     3699    case 1: 
     3700      $msg=$opts[0]; 
     3701    break; 
     3702    case 2: 
     3703      if(is_array($opts[0])||is_object($opts[0])){ 
     3704        $msg=$opts[0]; 
     3705        $dump=$opts[1]; 
     3706      }else{ 
     3707        $disc=$opts[0]; 
     3708        $msg=$opts[1]; 
     3709      } 
     3710    break; 
     3711    case 3: 
     3712      $disc=$opts[0]; 
     3713      $msg=$opts[1]; 
     3714      $dump=$opts[2]; 
     3715    break;   
     3716  } 
     3717  if($disc){$disc=' \''.$disc.'\':';} 
     3718  $txt=date("Y-M-d H:i:s").$disc."\n"; //add timestamp 
     3719  dbug_write($txt,1); 
     3720  if($dump==1){//force output via var_dump 
     3721    ob_start(); 
     3722    var_dump($msg); 
     3723    $msg=ob_get_contents(); 
     3724    ob_end_clean(); 
     3725    dbug_write($msg."\n"); 
     3726  }elseif(is_array($msg)||is_object($msg)){ 
     3727    dbug_write(print_r($msg,true)."\n"); 
     3728  }else{ 
     3729    dbug_write($msg."\n"); 
     3730  } 
     3731
     3732 
     3733function dbug_write($txt,$check){ 
     3734  global $amp_conf; 
     3735  $append=FILE_APPEND; 
     3736  //optionaly ensure that dbug file is smaller than $max_size 
     3737  if($check){ 
     3738    $max_size=52428800;//hardcoded to 50MB. is that bad? not enough? 
     3739    $size=filesize($amp_conf['FPBXDBUGFILE']); 
     3740    $append=(($size > $max_size)?'':FILE_APPEND); 
     3741  } 
     3742  file_put_contents($amp_conf['FPBXDBUGFILE'],$txt, $append); 
     3743
    36873744/** Log an error to the (database-based) log 
    36883745 * @param  string   The section or script where the error occurred