1. Go to this page and download the library: Download smartdesk/debug-logger library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
smartdesk / debug-logger example snippets
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');
use SmartDesk\Utils\DebugLogger;
// Enable only in development
if (defined('WP_DEBUG') && WP_DEBUG === true) {
DebugLogger::setMinLevel(LogLevel::DEBUG);
}
// Uses PHP's error_log() function - no additional setup needed
DebugLogger::debug(['data' => 'value'], 'init', 'Debug Info');
// 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
)
);
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);
}));
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 โ