Giter Site home page Giter Site logo

php-debug's Introduction

php-debug

This is the PHP debugger. It's not as good as the other ones out there, but it suited my needs.

What it does

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

Debugging Levels

Int Short Name long name
0 Reserved
1 ERRR Error
2 WARN Warning
3 INFO Informational
4 VERB Verbose

Notes

If using a log file output, you should add the logrotate config file to your system

Usage

Include

include '/path/to/debugger/php-debug.php'
$debugSettings = array();
$debug = new debug($debugSettings);

Settings

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)

Example

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);

Functions

changeLogLevel

Description

change the level of messages sent to log destinations

Arguments

argument type required description
level INT or STR yes integer 1-4 or string of level short name

Examples

debug->changeLogLevel('ERRR');

changeDebugLevel

Description

change the level of messages sent to debug destinations

Arguments

argument type required description
level INT or STR yes integer 1-4 or string of level short name
debug->changeDebugLevel('ERRR');

dump

Description

A pretty version of var_dump (slightly altered based on output destination). using the settings, can be set to obey enabled, storeMessages, redact.

Arguments

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

Examples

debug->dump($data, 'This is the data here');

storeMessages

Description

Enable/disable message storage and suppress debug output

Arguments

argument type required description
enabled boolean yes true to enable message storage, false to disable

Examples

debug->storeMessages(true);

getBuffer

Description

Get all stored messages out of the buffer

Arguments

argument type required description

Examples

debug->getBuffer();

msg

Description

Send a message (with optional data)

Arguments

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

Examples

debug->msg(INFO, "here", $extraData, true);

php-debug's People

Contributors

tame-lx-tech avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.