| 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 | */ |
|---|
| 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 | |
|---|
| | 3733 | function 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 | } |
|---|