PHPackages                             wp-spaghetti/wp-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. wp-spaghetti/wp-logger

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

wp-spaghetti/wp-logger
======================

A comprehensive WordPress logging service with Wonolog integration, secure file logging, multi-server protection, and environment-based configuration

v2.2.4(7mo ago)0530[1 PRs](https://github.com/wp-spaghetti/wp-logger/pulls)1GPL-3.0-or-laterPHPPHP &gt;=8.0CI passing

Since Sep 1Pushed 1mo agoCompare

[ Source](https://github.com/wp-spaghetti/wp-logger)[ Packagist](https://packagist.org/packages/wp-spaghetti/wp-logger)[ Docs](https://github.com/wp-spaghetti/wp-logger)[ Fund](https://buymeacoff.ee/frugan)[ RSS](/packages/wp-spaghetti-wp-logger/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (10)Dependencies (12)Versions (15)Used By (1)

[![PHP Version](https://camo.githubusercontent.com/b57298983de6b1f97922e35aa610645fbfb348c272e10d238cdd54256336103b/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f77702d7370616768657474692f77702d6c6f67676572)](https://camo.githubusercontent.com/b57298983de6b1f97922e35aa610645fbfb348c272e10d238cdd54256336103b/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f77702d7370616768657474692f77702d6c6f67676572)[![Packagist Downloads](https://camo.githubusercontent.com/f85755c0ee92982e34a0c4b347190793ec7e19b9260a805c967c0bad57494675/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f77702d7370616768657474692f77702d6c6f67676572)](https://camo.githubusercontent.com/f85755c0ee92982e34a0c4b347190793ec7e19b9260a805c967c0bad57494675/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f77702d7370616768657474692f77702d6c6f67676572)[![Packagist Stars](https://camo.githubusercontent.com/357854d6db852f7a18807a49340f306463a14219dd00bb161fcda6ab32acfa88/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f73746172732f77702d7370616768657474692f77702d6c6f67676572)](https://camo.githubusercontent.com/357854d6db852f7a18807a49340f306463a14219dd00bb161fcda6ab32acfa88/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f73746172732f77702d7370616768657474692f77702d6c6f67676572)[![GitHub Actions Workflow Status](https://github.com/wp-spaghetti/wp-logger/actions/workflows/main.yml/badge.svg)](https://github.com/wp-spaghetti/wp-logger/actions/workflows/main.yml/badge.svg)[![Coverage Status](https://camo.githubusercontent.com/270b2eab8d6987908a9b94224f242536fbf630a762dfb9e878a1f14db4b442b0/68747470733a2f2f696d672e736869656c64732e696f2f636f6465636f762f632f6769746875622f77702d7370616768657474692f77702d6c6f67676572)](https://camo.githubusercontent.com/270b2eab8d6987908a9b94224f242536fbf630a762dfb9e878a1f14db4b442b0/68747470733a2f2f696d672e736869656c64732e696f2f636f6465636f762f632f6769746875622f77702d7370616768657474692f77702d6c6f67676572)[![Known Vulnerabilities](https://camo.githubusercontent.com/128c762bb026be76278556932ad75dd37ab39f680d549a42d30082dfcd7cc034/68747470733a2f2f736e796b2e696f2f746573742f6769746875622f77702d7370616768657474692f77702d6c6f676765722f62616467652e737667)](https://camo.githubusercontent.com/128c762bb026be76278556932ad75dd37ab39f680d549a42d30082dfcd7cc034/68747470733a2f2f736e796b2e696f2f746573742f6769746875622f77702d7370616768657474692f77702d6c6f676765722f62616467652e737667)[![GitHub Issues](https://camo.githubusercontent.com/ef9a3192707f1583c024e4bbb6b9f5ad8eb716b8ff7a65fc3d71c471f2f660b2/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6973737565732f77702d7370616768657474692f77702d6c6f67676572)](https://camo.githubusercontent.com/ef9a3192707f1583c024e4bbb6b9f5ad8eb716b8ff7a65fc3d71c471f2f660b2/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6973737565732f77702d7370616768657474692f77702d6c6f67676572)[![GitHub Release](https://camo.githubusercontent.com/2f145f1221980781dd548e1a41869ddb6c62511a396acf1ad0afcf348a3f743f/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f762f72656c656173652f77702d7370616768657474692f77702d6c6f67676572)](https://camo.githubusercontent.com/2f145f1221980781dd548e1a41869ddb6c62511a396acf1ad0afcf348a3f743f/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f762f72656c656173652f77702d7370616768657474692f77702d6c6f67676572)[![License](https://camo.githubusercontent.com/03adb0928eecfc77eef7647a1b9aa9342842a8c2978de52009815fb7bfdf1866/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f77702d7370616768657474692f77702d6c6f67676572)](https://camo.githubusercontent.com/03adb0928eecfc77eef7647a1b9aa9342842a8c2978de52009815fb7bfdf1866/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f77702d7370616768657474692f77702d6c6f67676572)

WP Logger
=========

[](#wp-logger)

A comprehensive WordPress logging service with Wonolog integration, secure file logging, multi-server protection, and environment-based configuration.

Features
--------

[](#features)

- **PSR-3 Compatibility**: Full implementation of PSR-3 LoggerInterface for standardized logging
- **Environment-Based Configuration**: Powered by [WP Env](https://github.com/wp-spaghetti/wp-env) for flexible configuration management
- **Wonolog Integration**: Automatic detection and seamless integration with [Wonolog](https://github.com/inpsyde/Wonolog)
- **Secure File Logging**: WordPress.org compliant fallback logging with multi-server protection
- **Multi-Server Protection**: Built-in protection files for Apache, Nginx, IIS, LiteSpeed, and more
- **Configurable Log Levels**: Minimum log level filtering with environment variable support
- **Intelligent Log Retention**: Environment-specific retention policies with automatic cleanup
- **Hook System**: Extensible architecture with WordPress hooks for customization
- **Debug Mode Support**: Intelligent handling of development vs production environments
- **Zero Dependencies**: Works with or without external logging libraries, with automatic fallback to native file-based logging
- **Plugin Isolation**: Each plugin/theme gets independent log directories and settings

Design Philosophy: Mixed Types for Maximum Flexibility
------------------------------------------------------

[](#design-philosophy-mixed-types-for-maximum-flexibility)

WP Logger intentionally uses `mixed` type hints throughout its API, diverging from strict PSR Log ^2.0+ signatures. This design choice aligns with our primary integration target and WordPress ecosystem philosophy:

### Why Mixed Types?

[](#why-mixed-types)

**Wonolog Compatibility**: Our primary target, [Wonolog](https://github.com/inpsyde/Wonolog), accepts truly mixed types natively (Throwable, Arrays, Objects, WP\_Error):

```
// Wonolog native usage
do_action('wonolog.log', $exception);        // ✅ Throwable
do_action('wonolog.log', ['data' => 'log']); // ✅ Array
do_action('wonolog.log', $wpError);          // ✅ WP_Error
```

**PSR Log Version Differences**:

- **PSR Log ^1.0**: Uses `mixed` type hint but primarily expects strings
- **PSR Log ^2.0+**: Strictly enforces `string|\Stringable` only

**WordPress Ecosystem**: WordPress prioritizes pragmatism and developer experience over strict typing. Our design reflects this philosophy.

### Developer Benefits

[](#developer-benefits)

```
// ✅ Natural and intuitive - all supported
$logger->error($exception);              // Throwable objects
$logger->warning($wpError);              // WP_Error objects
$logger->info(['user' => 123]);          // Structured data
$logger->debug($customObject);           // Any object

// vs. ❌ Verbose PSR ^2.0+ requirement
$logger->error($exception->getMessage(), ['exception' => $exception]);
```

### How It Works

[](#how-it-works)

- **With Wonolog**: Mixed types passed through natively without conversion
- **Fallback Mode**: Mixed types converted to strings via `formatMessage()`
- **Best of Both**: WordPress flexibility + PSR compatibility + Wonolog power

This approach ensures zero breaking changes while maximizing compatibility across the WordPress ecosystem.

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

[](#installation)

Install via Composer:

```
composer require wp-spaghetti/wp-logger
```

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

[](#quick-start)

### 1. Basic Usage

[](#1-basic-usage)

```
