PHPackages                             nklatt/debugout - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Logging &amp; Monitoring](/categories/logging)
4. /
5. nklatt/debugout

ActiveLibrary[Logging &amp; Monitoring](/categories/logging)

nklatt/debugout
===============

DebugOut for PHP, for tracing code execution the old-fashioned way: with printlines.

v0.0.1(10y ago)023MITPHPPHP ^5.3 || ^7.0

Since Jun 9Pushed 4y ago1 watchersCompare

[ Source](https://github.com/nklatt/debugout)[ Packagist](https://packagist.org/packages/nklatt/debugout)[ Docs](https://github.com/nklatt/debugout)[ RSS](/packages/nklatt-debugout/feed)WikiDiscussions master Synced 4w ago

READMEChangelog (1)Dependencies (1)Versions (2)Used By (0)

DebugOut
========

[](#debugout)

DebugOut for PHP, for tracing code execution the old-fashioned way: with printlines.

History
-------

[](#history)

I initially created this pair of classes, DebugOut and DynamicDebug, in the mid-nineties for C++. It was later ported to Ada 95 and now PHP; I did *not* port it to Java because the DebugOut class relies on its destructor being called immediately upon its instantiations go out of scope and that doesn't happen with Java's garbage collection. (The C++ and Ada versions were both thread-aware; as I've not had occasion to use threads in PHP, this version does not include that capability.)

Purpose
-------

[](#purpose)

What they do is allow you to instrument code so that you can trace the execution path to the level of detail you would like by configuring what paths you're interested in for any given run through. DebugOut handles the outputting and DynamicDebug controls which scopes are traced based on a configuration file which is read in at the beginning of every, e.g., page load.

Installation
------------

[](#installation)

Use \[Composer\] to install the package:

```
composer require nklatt/debugout
```

Usage
-----

[](#usage)

There are two steps to using this package.

First, you need to instrument your code with DebugOut instantiations in the functions/methods you wish to trace/debug. At the top of such functions, add `$debugOut = new DebugOut(__FUNCTION__, '');` then, in the body, add calls to `$debugOut->putLine` passing it a string to be output.

Second, you need to enable logging for the flags you wish to see for any given run. This is done by calling `DynamicDebug::setEnabledFlags(array());`.

See tests/DebugOutTest.php for sample code.

Sample Output
-------------

[](#sample-output)

### Default

[](#default)

```
--> outputPage
    --> outputHeader
        --> outputNav(header)
            Adding to nav: Home
            Adding to nav: About
            Excluding from nav: History
            Excluding from nav: Executives
            Excluding from nav: Careers
            Adding to nav: Contact
            Adding to nav: Help
         outputSidebar
            --> outputNav(sidebar)
                Excluding from nav: Home
                Adding to nav: About
                Adding to nav: History
                Adding to nav: Executives
                Adding to nav: Careers
                Excluding from nav: Contact
                Adding to nav: Help
             outputNav(sidebar)
 |   |   |   |  Excluding from nav: Home
 |   |   |   |  Adding to nav: About
 |   |   |   |  Adding to nav: History
 |   |   |   |  Adding to nav: Executives
 |   |   |   |  Adding to nav: Careers
 |   |   |   |  Excluding from nav: Contact
 |   |   |   |  Adding to nav: Help
 |   |   |  outputNav(sidebar)
        Excluding from nav: Home
        Adding to nav: About
        Adding to nav: History
        Adding to nav: Executives
        Adding to nav: Careers
        Excluding from nav: Contact
        Adding to nav: Help
