This is the PHP debugger. It's not as good as the other ones out there, but it suited my needs.
This module can do logging and debugging stuff.
- Log outputs can go to syslog and/or file
- debug outputs can go to cli or JS console ( with auto detect environment)
Also, the dump
function provides a prettier version of var_dump
, with options for redaction and enable/disable
Int | Short Name | long name |
---|---|---|
0 | Reserved | |
1 | ERRR | Error |
2 | WARN | Warning |
3 | INFO | Informational |
4 | VERB | Verbose |
If using a log file output, you should add the logrotate config file to your system
include '/path/to/debugger/php-debug.php'
$debugSettings = array();
$debug = new debug($debugSettings);
You can pass an array to set a lot of things
The default values are intended for balance between useful loggin, and security towards web clients
Key | Type | Default | Description | |
---|---|---|---|---|
enabled |
boolean | true | ||
redact |
array | keys that will be searched for in data array and values redacted |
||
logLevel |
integer | 1 | messages of this level or lower will be sent to the log destinations (file and syslog) | |
logToFile |
boolean | false | send messages to file? | |
logFile |
string | /var/log/myapp.log | path to log output file | |
logToSyslog |
boolean | false | send log messages to syslog? | |
syslogName |
string | GNU STP | app name registered with syslog | |
syslogFacility |
integer | LOG_LOCAL0 | the source registered for syslog | |
debugLevel |
integer | 0 | this level and lower will be sent to debug destinations (JS console or CLI) | |
storeMessages |
boolean | false | suppress debug output and store messages into a buffer. If not explicitly set, the auto-detect for ajax requests will set this to true |
|
dumpObeysEnabled |
boolean | true | if false, dumps will always be outputted. otherwise, it will obey the enabled option |
|
dumpObeysStoreMessages |
boolean | true | set whether dumps will be stored in the message buffer according to ['debug']['storeMessages'] |
|
dumpObeysRedact |
boolean | true | if false, nothing will be redacted. Otherwise, redactions will be enabled | |
handlePhpErrors |
boolean | true | should PHP errors be handled using this | |
phpLevel |
int | 4 | Level of php errors to intercept (currently nothin is classed below warning) | |
phpToLog |
boolean | true | php errors to log destinations? | |
phpToDebug |
boolean | false | php errors to debug destinations? | |
hidePhpData |
boolean | true | Will hide file, line and context when output to JS console (because security) |
include '/path/to/debugger/php-debug.php'
$debugSettings = array(
'enabled'=>true,
'log'=>array(
'logToFile'=>false,
'logToSyslog'=>true,
'logLevel'=>2,
),
);
$debug = new debug($debugSettings);
$data = array(
'foo'=>'bar',
'something'=>7,
'somethingElse'=>true,
'hereIsAnArray'=>array('biz', 'baz', 'box')
)
debug->msg('WARN', 'This is a warning message', $data);
change the level of messages sent to log destinations
argument | type | required | description |
---|---|---|---|
level | INT or STR | yes | integer 1-4 or string of level short name |
debug->changeLogLevel('ERRR');
change the level of messages sent to debug destinations
argument | type | required | description |
---|---|---|---|
level | INT or STR | yes | integer 1-4 or string of level short name |
debug->changeDebugLevel('ERRR');
A pretty version of var_dump (slightly altered based on output destination). using the settings, can be set to obey enabled
, storeMessages
, redact
.
argument | type | required | description |
---|---|---|---|
data | any | yes | the data to be shown |
message | string | no | a message or title to be shown above the dump |
debug->dump($data, 'This is the data here');
Enable/disable message storage and suppress debug output
argument | type | required | description |
---|---|---|---|
enabled | boolean | yes | true to enable message storage, false to disable |
debug->storeMessages(true);
Get all stored messages out of the buffer
argument | type | required | description |
---|
debug->getBuffer();
Send a message (with optional data)
argument | type | required | description |
---|---|---|---|
level | string | yes | the level of this message |
message | string | yes | string of the message to be sent |
data | any | no | extra data that might be useful |
highlight | bool | no | should this message be highlighted in the debug outputs? |
additional | array | no | currently unused |
debug->msg(INFO, "here", $extraData, true);