PHPackages                             smartdesk/debug-logger - 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. smartdesk/debug-logger

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

smartdesk/debug-logger
======================

Human-friendly WordPress debug logger with hook status block and optional rotating file sink.

v1.0.2(9mo ago)0311GPL-3.0-or-laterHTMLPHP &gt;=8.1CI passing

Since Aug 20Pushed 8mo agoCompare

[ Source](https://github.com/martin-kronsteiner/SmartDesk-DebugLogger)[ Packagist](https://packagist.org/packages/smartdesk/debug-logger)[ RSS](/packages/smartdesk-debug-logger/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (1)Dependencies (3)Versions (4)Used By (1)

SmartDesk DebugLogger
=====================

[](#smartdesk-debuglogger)

[![License: GPL v3](https://camo.githubusercontent.com/48bf9b56d44f38db53ce21294cf0b9487d0a3734ab3ba1fe4c69858ae20db2c1/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c6963656e73652d47504c76332d626c75652e737667)](LICENSE) [![PHP Version](https://camo.githubusercontent.com/7535257ca228724c93658bd52583d4e47a9bab02c356abf6e54c1d575f2151e6/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048502d382e312532422d626c75652e737667)](https://www.php.net/supported-versions.php) [![Packagist Version](https://camo.githubusercontent.com/747755df9e79f8edfb03c3d6ad7b47a23750241c581d7374a30723ff526b86aa/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f736d6172746465736b2f64656275672d6c6f676765722e737667)](https://packagist.org/packages/smartdesk/debug-logger) [![Packagist Downloads](https://camo.githubusercontent.com/5303cdaed0e579a2c748d040caf4cd40e1de1f62ebcdd1e54875de772f97aef9/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f736d6172746465736b2f64656275672d6c6f676765722e737667)](https://packagist.org/packages/smartdesk/debug-logger) [![CI](https://github.com/martin-kronsteiner/SmartDesk-DebugLogger/actions/workflows/ci.yml/badge.svg)](https://github.com/martin-kronsteiner/SmartDesk-DebugLogger/actions/workflows/ci.yml) [![Release](https://github.com/martin-kronsteiner/SmartDesk-DebugLogger/actions/workflows/release.yml/badge.svg)](https://github.com/martin-kronsteiner/SmartDesk-DebugLogger/actions/workflows/release.yml) [![WordPress](https://camo.githubusercontent.com/2d7ecbd0de75900a848ee02bb4d682496d2f22bb7df770c74483d79a9271a07b/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f576f726450726573732d506c7567696e2d3231373539423f6c6f676f3d776f72647072657373)](https://camo.githubusercontent.com/2d7ecbd0de75900a848ee02bb4d682496d2f22bb7df770c74483d79a9271a07b/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f576f726450726573732d506c7567696e2d3231373539423f6c6f676f3d776f72647072657373)

\[EN\] Human-readable debug logger for WordPress development (PHP 8.1+).
Generates structured multi-line entries with SmartDesk caller info, an optional hook status block (♻️/⏳), and a level prefix (emoji + label).
Output goes to a sink: error\_log() by default, optionally a rotating file via setWriter().
The output of a debug entry in debug.log or in your personal storage location looks something like this:

\[DE\] Menschenlesbarer Debug‑Logger für WordPress‑Entwicklung (PHP 8.1+).
Erzeugt strukturierte, mehrzeilige Einträge mit SmartDesk‑Caller‑Info, optionalem Hook‑Status‑Block (♻️/⏳) und Level‑Präfix (Emoji + Label).
Ausgabe geht an eine Senke (sink): standardmäßig error\_log(), optional rotierende Datei via setWriter().
Die Ausgabe eines Debug-Eintrages in debug.log oder an deinem persönlichen Speicherort, sieht dann etwa so aus:

```
[20-Aug-2025 04:58:25 UTC] SmartDesk\Admin\WooMembershipPlanPricing\Main::{closure:SmartDesk\Admin\WooMembershipPlanPricing\Main::__construct():74}() - 04:58:25,56937
'Timestamp: 1755665904.8372 / Request: 394713'
C:\Users\SmartDesk\...\public\wp-includes\class-wp-hook.php:324

    hooks:
        ♻️ plugins_loaded (1 times fired)
        ♻️ init (1 times fired)
        ⏳ rest_api_init
        ⏳ admin_menu
        ⏳ admin_init
        ⏳ wp_enqueue_scripts
        ⏳ admin_enqueue_scripts
        ♻️ wp_loaded (1 times fired)
    AT states count (via getter, after wp_loaded): 9
    person => {
            id => 1
            wp_capabilities => {
                    administrator => true
                    }
            role => administrator
            nickname => admin
            locale => [empty-string]
            show_welcome_panel => false
            ...
            }
---------|---------|---------|---------|---------|---------|---------|---------|---------|---------|-SmartDesk

```

Table of Contents
-----------------

[](#table-of-contents)

- [Features](#features)
- [Requirements](#requirements)
- [Installation](#installation)
- [Quick Start](#quick-start)
- [Configuration](#configuration)
- [API Reference](#api-reference)
- [Usage Examples](#usage-examples)
- [Plugin Integration](#plugin-integration)
- [Testing](#testing)
- [Notes](#notes)
- [License](#license)

Features
--------

[](#features)

- 🎯 **WordPress-optimized**: Designed specifically for WordPress development
- 📊 **Hook status tracking**: Visual indicators for fired (♻️) and pending (⏳) hooks
- 🎨 **Human-readable output**: Structured, multi-line debug entries
- 📁 **Flexible output**: Error log or rotating file support
- ⏱️ **Built-in timers**: Performance monitoring capabilities
- 🎭 **Log levels**: 8 different levels with emoji indicators
- 🔧 **Easy integration**: Simple setup for plugins and themes

Requirements
------------

[](#requirements)

- PHP 8.1 or higher
- WordPress (any recent version)
- WP\_DEBUG enabled for active operation

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

[](#installation)

```
composer require smartdesk/debug-logger

```

Quick Start
-----------

[](#quick-start)

```
use SmartDesk\Utils\DebugLogger;

// Simple logging
DebugLogger::debug(['user_id' => 123], 'init', 'User Login');

// With hook status
DebugLogger::log($data, ['plugins_loaded', 'init'], 'Startup Data');
```

Configuration
-------------

[](#configuration)

### Basic Setup

[](#basic-setup)

```
use SmartDesk\Utils\DebugLogger;

// Enable only in development
if (defined('WP_DEBUG') && WP_DEBUG === true) {
    DebugLogger::setMinLevel(LogLevel::DEBUG);
}
```

### Advanced Configuration

[](#advanced-configuration)

```
// Custom log directory
$logDir = WP_CONTENT_DIR . '/uploads/smartdesk-logs';
DebugLogger::setWriter(
    DebugLogger::makeRotatingWriter($logDir, 'debug.log', 5_000_000, 5)
);

// Set minimum log level
DebugLogger::setMinLevel(LogLevel::WARNING);
```

### Output Configuration

[](#output-configuration)

#### Error Log Output (Default)

[](#error-log-output-default)

```
// Uses PHP's error_log() function - no additional setup needed
DebugLogger::debug(['data' => 'value'], 'init', 'Debug Info');
```

#### Rotating File Output

[](#rotating-file-output)

```
// Set up rotating file writer
$logDir = WP_CONTENT_DIR . '/uploads/smartdesk-logs';
DebugLogger::setWriter(
    DebugLogger::makeRotatingWriter(
        $logDir,        // Directory path
        'debug.log',    // Base filename
        5_000_000,      // Max file size in bytes (5MB)
        5               // Number of backup files to keep
    )
);
```

#### Custom Writer

[](#custom-writer)

```
use SmartDesk\Utils\Handlers\CallbackHandler;

// Custom callback handler
DebugLogger::setWriter(new CallbackHandler(function($message) {
    // Send to external service, database, etc.
    file_put_contents('/custom/path/app.log', $message, FILE_APPEND);
}));
```

#### Log Level Configuration

[](#log-level-configuration)

```
use SmartDesk\Utils\Support\LogLevel;

// Set minimum log level (only logs at this level or higher will be output)
DebugLogger::setMinLevel(LogLevel::WARNING);  // Only WARNING, ERROR, CRITICAL, ALERT, EMERGENCY

// Available levels (from lowest to highest):
// LogLevel::DEBUG     🐞
// LogLevel::INFO      ℹ️
// LogLevel::NOTICE    📋
// LogLevel::WARNING   ⚠️
// LogLevel::ERROR     ❌
// LogLevel::CRITICAL  ☠️
// LogLevel::ALERT     🚨
// LogLevel::EMERGENCY ⛔
```

#### Request Tracking

[](#request-tracking)

```
// Define request marker for log correlation
if (!defined('SMARTDESK_REQ')) {
    define(
        'SMARTDESK_REQ',
        'Timestamp: ' . ($_SERVER['REQUEST_TIME_FLOAT'] ?? microtime(true))
        . ' / Request: ' . substr(md5($_SERVER['REQUEST_URI'] ?? ''), 0, 6)
        . ' / User: ' . (get_current_user_id() ?: 'guest')
    );
}
```

API Reference
-------------

[](#api-reference)

### Static Methods

[](#static-methods)

#### `setWriter(WriterInterface $writer): void`

[](#setwriterwriterinterface-writer-void)

Sets the output destination for log messages.

```
// Rotating file writer
DebugLogger::setWriter(
    DebugLogger::makeRotatingWriter('/path/to/logs', 'app.log', 5_000_000, 5)
);

// Custom callback writer
DebugLogger::setWriter(new CallbackHandler(function($message) {
    error_log($message);
}));
```

#### `setMinLevel(string $level): void`

[](#setminlevelstring-level-void)

Sets the minimum log level. Only messages at this level or higher will be output.

```
use SmartDesk\Utils\Support\LogLevel;

// Available levels (from lowest to highest):
// LogLevel::DEBUG     🐞
// LogLevel::INFO      ℹ️
// LogLevel::NOTICE    📋
// LogLevel::WARNING   ⚠️
// LogLevel::ERROR     ❌
// LogLevel::CRITICAL  ☠️
// LogLevel::ALERT     🚨
// LogLevel::EMERGENCY ⛔
DebugLogger::setMinLevel(LogLevel::WARNING);
```

#### `makeRotatingWriter(string $dir, string $filename, int $maxSize, int $maxFiles): FileHandler`

[](#makerotatingwriterstring-dir-string-filename-int-maxsize-int-maxfiles-filehandler)

Creates a rotating file handler.

##### Parameters:

[](#parameters)

- `$dir` - Directory path for log files
- `$filename` - Base filename (e.g., 'app.log')
- `$maxSize` - Maximum file size in bytes before rotation
- `$maxFiles` - Number of backup files to keep

```
$writer = DebugLogger::makeRotatingWriter(
    WP_CONTENT_DIR . '/uploads/logs',
    'debug.log',
    2_000_000,  // 2MB
    4           // Keep 4 backup files
);
```

### Logging Methods

[](#logging-methods)

#### `log(mixed $data, string|array $hooks = '', string $title = '', string $level = LogLevel::DEBUG): void`

[](#logmixed-data-stringarray-hooks---string-title---string-level--logleveldebug-void)

Main logging method.

#### Shortcut Methods

[](#shortcut-methods)

```
DebugLogger::debug($data, $hooks, $title);     // 🐞 DEBUG
DebugLogger::info($data, $hooks, $title);      // ℹ️ INFO
DebugLogger::notice($data, $hooks, $title);    // 📋 NOTICE
DebugLogger::warning($data, $hooks, $title);   // ⚠️ WARNING
DebugLogger::error($data, $hooks, $title);     // ❌ ERROR
DebugLogger::critical($data, $hooks, $title);  // ☠️ CRITICAL
DebugLogger::alert($data, $hooks, $title);     // 🚨 ALERT
DebugLogger::emergency($data, $hooks, $title); // ⛔ EMERGENCY
```

### Timer Methods

[](#timer-methods)

#### `timerStart(string $name): void`

[](#timerstartstring-name-void)

Starts a named timer.

#### `timerLap(string $name, string $title = ''): void`

[](#timerlapstring-name-string-title---void)

Records a lap time without stopping the timer.

#### `timerStop(string $name, string $title = '', string $level = LogLevel::DEBUG): void`

[](#timerstopstring-name-string-title---string-level--logleveldebug-void)

Stops the timer and logs the total time.

### Hook Methods

[](#hook-methods)

#### `hook(string|array $hooks, string $title = ''): void`

[](#hookstringarray-hooks-string-title---void)

Logs only hook status information without additional data.

Usage Examples
--------------

[](#usage-examples)

### Setup Rotating file sink with Request marker

[](#setup-rotating-file-sink-with-request-marker)

```
use SmartDesk\Utils\DebugLogger;

add_action('plugins_loaded', function () {
    if (!defined('WP_DEBUG') || WP_DEBUG !== true) return;

    $dir = WP_CONTENT_DIR . '/uploads/smartdesk-logs';
    DebugLogger::setWriter(DebugLogger::makeRotatingWriter($dir, 'dev.log', 2_000_000, 4));

    if (!defined('SMARTDESK_REQ')) {
        define(
            'SMARTDESK_REQ',
            'Timestamp: ' . ($_SERVER['REQUEST_TIME_FLOAT'] ?? microtime(true))
            . ' / Request: ' . substr(md5($_SERVER['REQUEST_URI'] ?? ''), 0, 6)
        );
    }
});
```

### Log

[](#log)

```
use SmartDesk\Utils\DebugLogger;

// 🐞 Debug Flag
$debug = 1 === 1;

$debug && DebugLogger::log(
    [
        '🧪 foo' => 'bar',
        '🧪 list' => ['a', 'b', 'c'],
    ],
    'register',   // preset(s) or single hooks
    'My Block'    // optional title
);
```

#### Log just Hook-State

[](#log-just-hook-state)

```
use SmartDesk\Utils\DebugLogger;

DebugLogger::hook(['admin', 'enqueue'], 'Hooks');
```

##### Available Hook Presets

[](#available-hook-presets)

The logger includes predefined hook sets for common WordPress scenarios:

```
// Usage examples with presets
DebugLogger::log($data, 'load', 'Plugin Loading');      // WordPress loading hooks
DebugLogger::log($data, 'register', 'Registration');    // Plugin/theme registration
DebugLogger::log($data, 'admin', 'Admin Area');         // Admin-specific hooks
DebugLogger::log($data, 'frontend', 'Frontend');        // Frontend-specific hooks
DebugLogger::log($data, 'enqueue', 'Script Loading');   // Script/style enqueuing
DebugLogger::log($data, 'woo', 'WooCommerce');          // WooCommerce hooks
DebugLogger::log($data, 'rest', 'REST API');            // REST API hooks
DebugLogger::log($data, 'request', 'Request Handling'); // Request processing
```

##### Preset Details:

[](#preset-details)

- `'load'` - WordPress core loading sequence (muplugins\_loaded, plugins\_loaded, init, etc.)
- `'register'` - Plugin/theme registration hooks (plugins\_loaded, init, admin\_init, etc.)
- `'admin'` - Admin area hooks (admin\_init, admin\_menu, current\_screen, etc.)
- `'frontend'` - Frontend hooks (wp, template\_redirect, wp\_enqueue\_scripts, etc.)
- `'enqueue'` - Script/style enqueuing hooks
- `'woo'` - WooCommerce-specific hooks
- `'rest'` - REST API related hooks
- `'request'` - Request processing hooks (parse\_request, wp, template\_redirect, etc.)

### Timer

[](#timer)

```
use SmartDesk\Utils\DebugLogger;
use SmartDesk\Utils\Support\LogLevel;

DebugLogger::timerStart('import');
// ... prepare whatever
DebugLogger::timerLap('import', 'after preparing whatever');
// ... work ...
DebugLogger::timerStop('import', 'Import job', LogLevel::NOTICE);
```

##### Output:

[](#output)

```
📋 NOTICE SmartDesk\Importer\Runner::run - 12:34:56,12345
'Timestamp: 1755609635.4039 / Request: abc123'
C:\path\to\Importer\Runner.php:88

    Timer finished
    Timer 'import' finished in 2.3456s
---------|---------|...

```

Plugin Integration
------------------

[](#plugin-integration)

> **WordPress**
>
> See the dedicated guide: [WP-IMPLEMENTATION.md](./WP-IMPLEMENTATION.md) — step-by-step
>
> - Composer &amp; manual install
> - Robust plugin bootstrap (autoloader fallback)
> - Theme &amp; multisite setup
> - Hook/action tracking
> - DB query logging
> - Performance timers
> - WP-CLI integration
> - Security, and troubleshooting

```
/**
 * Plugin Name: SmartDesk Core
 */

use SmartDesk\Utils\DebugLogger;
use SmartDesk\Utils\Support\LogLevel;

// Composer Autoload
require_once __DIR__ . '/vendor/autoload.php';

// Logger setup for plugin
add_action('plugins_loaded', function () {
    if (!defined('WP_DEBUG') || WP_DEBUG !== true) return;

    $logsDir = WP_CONTENT_DIR . '/uploads/smartdesk-logs';

    DebugLogger::setWriter(
        DebugLogger::makeRotatingWriter($logsDir, 'core.log', 2_000_000, 4)
    );

    DebugLogger::info([
        'wp' => get_bloginfo('version'),
        'php' => PHP_VERSION,
    ], 'plugins_loaded', 'Core Plugin Loaded');
});
```

Testing
-------

[](#testing)

```
composer install
composer test
composer coverage  # Generate coverage report
composer qa        # Run all quality checks

```

Notes
-----

[](#notes)

Active only if WP\_DEBUG === true.
Timestamps in UTC.
Single sink: default error\_log(), or rotating file via setWriter().

License
-------

[](#license)

GPL-3.0-or-later. See [LICENSE](./LICENSE).

### Plugin-Header (if loaded as plugin)

[](#plugin-header-if-loaded-as-plugin)

```
/*
Plugin Name: SmartDesk DebugLogger
License: GPLv3 or later
License URI: https://www.gnu.org/licenses/gpl-3.0.html
*/
```

###  Health Score

32

—

LowBetter than 72% of packages

Maintenance59

Moderate activity, may be stable

Popularity7

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity46

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~0 days

Total

3

Last Release

271d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/9d344a87e816c8c037b41e2450d956326fd3b770543122863308487233834d80?d=identicon)[martin-kronsteiner](/maintainers/martin-kronsteiner)

---

Top Contributors

[![martin-kronsteiner](https://avatars.githubusercontent.com/u/144478618?v=4)](https://github.com/martin-kronsteiner "martin-kronsteiner (19 commits)")

---

Tags

wordpressdebugloggerhookstimers

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP\_CodeSniffer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/smartdesk-debug-logger/health.svg)

```
[![Health](https://phpackages.com/badges/smartdesk-debug-logger/health.svg)](https://phpackages.com/packages/smartdesk-debug-logger)
```

###  Alternatives

[inpsyde/wonolog

Monolog-based logging package for WordPress.

183617.9k7](/packages/inpsyde-wonolog)[analog/analog

Fast, flexible, easy PSR-3-compatible PHP logging package with dozens of handlers.

3451.5M24](/packages/analog-analog)[bdk/debug

Browser/javascript like console class for PHP

819.0k1](/packages/bdk-debug)[snapshotpl/zf-snap-php-debug-bar

PHP Debug Bar module for Zend Framework 2

3026.1k](/packages/snapshotpl-zf-snap-php-debug-bar)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
