PHPackages                             xsga/log4php - 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. xsga/log4php

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

xsga/log4php
============

A PHP logging library based on Apache Log4PHP, PSR-3 compliant, supporting multiple appenders, layouts and log levels.

v1.0.0(2mo ago)133Apache-2.0PHPPHP ^8.4CI passing

Since Apr 18Pushed 2mo agoCompare

[ Source](https://github.com/xsga/Log4PHP)[ Packagist](https://packagist.org/packages/xsga/log4php)[ Docs](https://github.com/xsga/Log4PHP)[ RSS](/packages/xsga-log4php/feed)WikiDiscussions master Synced 3w ago

READMEChangelog (3)Dependencies (5)Versions (5)Used By (0)

Xsga Log4PHP
============

[](#xsga-log4php)

[![PHP](https://camo.githubusercontent.com/8739500537d5f861f74f8d1bc0a35ac7a897e0687b5d13a256bd3ed35bf801f3/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048502d382e342532422d626c75653f6c6f676f3d706870)](https://www.php.net/)[![PSR-3](https://camo.githubusercontent.com/cf2558ee434bb51957faaabcdd1217f310b0c523d2223da29a8ca9738e8e4f3d/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5053522d2d332d636f6d706c69616e742d627269676874677265656e)](https://www.php-fig.org/psr/psr-3/)[![License: Apache 2.0](https://camo.githubusercontent.com/c166f20e409d9fa506a962fe7edc0c99856f52abcef5fb2027fd1e45984d7773/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c6963656e73652d4170616368655f322e302d79656c6c6f772e737667)](LICENSE)

> A modern, PSR-compliant successor to Apache Log4PHP (now unmaintained).

Xsga Log4PHP is a heavily refactored and redesigned logging library for PHP, originally inspired by Apache Log4PHP and rebuilt for the current PHP ecosystem. It targets PHP 8.4+, follows PSR-3, ships with PSR-4 autoloading, and provides a flexible logging pipeline with appenders, layouts, context interpolation, and XML or programmatic configuration.

---

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

[](#table-of-contents)

- [Why this project exists](#why-this-project-exists)
- [Key Features](#key-features)
- [What makes it different](#what-makes-it-different)
- [Quick Start](#quick-start)
- [Basic Configuration](#basic-configuration)
- [Documentation](#documentation)
- [Who should use this](#who-should-use-this)
- [License](#license)
- [Acknowledgements](#acknowledgements)

---

📌 Why this project exists
-------------------------

[](#-why-this-project-exists)

Apache Log4PHP is no longer actively maintained and does not align with current PHP versions, tooling, or interoperability expectations.

This project exists to:

- Provide a conceptual successor for teams familiar with Apache Log4PHP
- Preserve the strengths of the original model while removing outdated constraints
- Modernize the architecture, code style, and runtime requirements
- Align the library with current PHP standards, especially PSR-3 and PSR-4
- Offer a maintainable codebase suitable for static analysis, code style checks, and ongoing development

---

✨ Key Features
--------------

[](#-key-features)

- ✅ PSR-3 compatible logging interface and context placeholder interpolation
- ✅ PSR-4 autoloading support via Composer
- ✅ PHP 8.4+ compatibility
- ✅ XML-based and programmatic array-based configuration
- ✅ Multiple appenders, including File, DailyFile, RollingFile, Console, and Loki
- ✅ Multiple layouts, including Pattern, JSON, and Simple
- ✅ Full log level support from ALL through OFF, aligned with modern logging expectations
- ✅ Refactored architecture with cleaner separation of responsibilities
- ✅ Improved maintainability, extensibility, and static-analysis friendliness

---

🔍 What makes it different
-------------------------

[](#-what-makes-it-different)

Compared to the original Apache Log4PHP:

- The internals have been substantially refactored for modern PHP and stricter typing expectations
- The package is distributed as a Composer-first library with PSR-4 autoloading
- Logging follows the PSR-3 method set and context conventions
- Configuration remains familiar, but the implementation is cleaner and easier to maintain
- Appenders and layouts are designed for present-day use cases, including structured JSON output and Loki integration
- Development tooling now includes linting, PSR-12 style checks, and Psalm-based static analysis

For a detailed comparison, see:

👉 [doc/differences-from-apache-log4php.md](doc/differences-from-apache-log4php.md)

---

🚀 Quick Start
-------------

[](#-quick-start)

Install via Composer:

```
composer require xsga/log4php
```

Basic usage:

```
use Xsga\Log4Php\Logger;

// Load configuration from an XML file.
Logger::configure('path/to/log4php.xml');

// Obtain a named logger.
$logger = Logger::getLogger('MyApp');
$logger->info('Application started.');
$logger->warning('Disk space running low.', ['threshold' => '90%']);

// Or use the root logger.
$root = Logger::getRootLogger();
$root->debug('Root logger is ready.');
```

If you prefer to configure the library without XML, you can also pass a PHP array directly to `Logger::configure()`.

---

⚙️ Basic Configuration
----------------------

[](#️-basic-configuration)

Configuration can be defined using XML or arrays.

XML example:

```

```

Programmatic example:

```
use Xsga\Log4Php\Logger;

Logger::configure([
    'appenders' => [
        'default' => [
            'class' => 'LoggerAppenderFile',
            'params' => [
                'file' => 'logs/app.log',
            ],
            'layout' => [
                'class' => 'LoggerLayoutPattern',
            ],
        ],
    ],
    'rootLogger' => [
        'level' => 'debug',
        'appenders' => ['default'],
    ],
]);
```

---

📚 Documentation
---------------

[](#-documentation)

Project documentation is currently centered on the repository itself:

- Differences from Apache Log4PHP: [doc/differences-from-apache-log4php.md](doc/differences-from-apache-log4php.md)
- Project documentation: [doc/DOCUMENTATION.md](doc/DOCUMENTATION.md)

---

👥 Who should use this
---------------------

[](#-who-should-use-this)

This project is a good fit if you:

- Are currently using Apache Log4PHP and need a modern successor with a familiar mental model
- Need a PHP 8.4+ logging library with PSR-3 semantics
- Want XML-driven logging configuration without giving up programmatic configuration options
- Need appenders for local files, rolling files, console output, or Grafana Loki
- Prefer a lightweight logging library over larger framework-coupled solutions

---

📄 License
---------

[](#-license)

This project is based on Apache Log4PHP and remains licensed under the Apache 2.0 License. See [LICENSE](LICENSE) for details.

It includes substantial refactoring, modernization, and new implementation work tailored to the current PHP ecosystem.

---

🙌 Acknowledgements
------------------

[](#-acknowledgements)

- Apache Log4PHP
- Apache Software Foundation

###  Health Score

42

—

FairBetter than 88% of packages

Maintenance84

Actively maintained with recent releases

Popularity12

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity54

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 ~4 days

Total

3

Last Release

87d ago

Major Versions

v0.2.0 → v1.0.02026-04-28

### Community

Maintainers

![](https://www.gravatar.com/avatar/4910bbdae842a515f9bea527ed4a7550ad04c9696ced65038be2e52ad2841464?d=identicon)[ParkerXsga](/maintainers/ParkerXsga)

---

Top Contributors

[![xsga](https://avatars.githubusercontent.com/u/67624778?v=4)](https://github.com/xsga "xsga (34 commits)")

---

Tags

log4phplogginglogging-librarypsr-3logpsr-3loggingloggerlog4php

###  Code Quality

Static AnalysisPsalm

Code StylePHP\_CodeSniffer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/xsga-log4php/health.svg)

```
[![Health](https://phpackages.com/badges/xsga-log4php/health.svg)](https://phpackages.com/packages/xsga-log4php)
```

###  Alternatives

[analog/analog

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

3511.6M24](/packages/analog-analog)[inpsyde/wonolog

Monolog-based logging package for WordPress.

184637.3k7](/packages/inpsyde-wonolog)[apix/log

Minimalist, thin and fast PSR-3 compliant (multi-bucket) logger.

521.1M24](/packages/apix-log)[markrogoyski/simplelog-php

Powerful PSR-3 logging. So easy, it's simple.

2819.3k4](/packages/markrogoyski-simplelog-php)

PHPackages © 2026

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