PHPackages                             lf4php/lf4php - 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. lf4php/lf4php

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

lf4php/lf4php
=============

This is a facade for logging frameworks.

5.0.0(8y ago)1176.5k↓25.9%28MITPHPPHP &gt;=7.1

Since Dec 17Pushed 8y ago2 watchersCompare

[ Source](https://github.com/szjani/lf4php)[ Packagist](https://packagist.org/packages/lf4php/lf4php)[ RSS](/packages/lf4php-lf4php/feed)WikiDiscussions 4.2 Synced 1mo ago

READMEChangelogDependencies (2)Versions (26)Used By (8)

lf4php
======

[](#lf4php)

master: [![Build Status](https://camo.githubusercontent.com/35d646f1c8a1a3801b8875e051fe22636c8af3c736701202d798c057b386e45f/68747470733a2f2f7472617669732d63692e6f72672f737a6a616e692f6c66347068702e706e673f6272616e63683d6d6173746572)](https://travis-ci.org/szjani/lf4php)3.0: [![Build Status](https://camo.githubusercontent.com/4afb53da7fb44ba1a2006d5de6c9a68b2a64e56fe5fbfd4d79979f0ef6abe6cc/68747470733a2f2f7472617669732d63692e6f72672f737a6a616e692f6c66347068702e706e673f6272616e63683d332e30)](https://travis-ci.org/szjani/lf4php)4.0: [![Build Status](https://camo.githubusercontent.com/7208310a97f0f9212b39feb337bdb6934f7266c423ab2836b54e8c376913c5e8/68747470733a2f2f7472617669732d63692e6f72672f737a6a616e692f6c66347068702e706e673f6272616e63683d342e30)](https://travis-ci.org/szjani/lf4php)

The Logging Facade for PHP (lf4php) serves as a simple facade or abstraction for various logging frameworks. Its design comes from [slf4j](http://www.slf4j.org).

Hello World
-----------

[](#hello-world)

```
$logger = LoggerFactory::getLogger(HelloWorld::class);
// or $logger = LoggerFactory::getLogger("The\Namespace\Of\HelloWorld");
$logger->info("Hello World");
```

This code snippet does not do anything. To resolve the problem, you have to use a logging framework and the appropriate lf4php binding. Assuming you use Monolog and Composer, you need to pull the following dependencies:

- lf4php/lf4php
- lf4php/lf4php-monolog

Typical usage pattern
---------------------

[](#typical-usage-pattern)

```
class Wombat
{
    private $t;
    private $oldT;

    public function setTemperature($temperature)
    {
        $logger = LoggerFactory::getLogger(Wombat::class);
        $this->oldT = $this->t;
        $this->t = $temperature;

        $logger->debug("Temperature set to {}. Old temperature was {}.", [$this->t, $this->oldT]);

        if ($temperature > 50) {
            $logger->info("Temperature has risen above 50 degrees.");
        }
    }
}
```

If a class extends `precore\lang\Object`, you can obtain the proper logger object via `self::getLogger()` method call.

Bindings
--------

[](#bindings)

- [lf4php/lf4php-log4php](https://github.com/szjani/lf4php-log4php)
- [lf4php/lf4php-monolog](https://github.com/szjani/lf4php-monolog)
- [lf4php/lf4php-psr3](https://github.com/szjani/lf4php-psr3)

lf4php-psr3 is a generic binding for any PSR-3 logging framework. However using specific bindings is recommended, because some features are missing from PSR-3 API.

Mapped Diagnostic Context (MDC) support
---------------------------------------

[](#mapped-diagnostic-context-mdc-support)

"Mapped Diagnostic Context" is essentially a map maintained by the logging framework where the application code provides key-value pairs which can then be inserted by the logging framework in log messages. MDC data can also be highly helpful in filtering messages or triggering certain actions.

lf4php supports MDC, or mapped diagnostic context. If the underlying logging framework offers MDC functionality, then lf4php will delegate to the underlying framework's MDC. Note that at this time, only log4php offers MDC functionality (and Monolog binding use a processor for it). If the underlying framework does not offer MDC, for example PSR-3, then lf4php will still store MDC data but the information therein will need to be retrieved by custom user code.

For example you can store user specific information in MDC. After that, log messages may contain these values depending on the configuration:

```
// before the controller
MDC::put("userName", Session::getCurrentUser()->name());

// later, in the controller
$logger = LoggerFactory::getLogger(BasketController::class);
$logger->debug("Product added to basket: {}", [$basket]);
```

The log entry created in the controller may contains the user name too as additional information.

Static access to logger object
------------------------------

[](#static-access-to-logger-object)

PSR-3 is a simple API, which does not support static access, you have to inject the logger objects. lf4php supports both static and injection ways. The logger objects implement `lf4php\Logger` interface, they are actually instances of the adapter for the logging framework you use.

Logging hierarchy
-----------------

[](#logging-hierarchy)

lf4php supports logging hierarchy even if the logging framework does not provide this feature. It means that when you are accessing to a logger object by a name, lf4php assumes that the given string is a class or namespace and splits it at backslashes. After that it removes the last part of it until it finds a logger object with the remaining, truncated name.

It is useful when you want to use a different logging configuration for a specific namespace or class. Assuming you use Monolog:

```
// configuring Monolog loggers
$fooLogger = new \Monolog\Logger('foo');
$barLogger = new \Monolog\Logger('foo\bar');

$loggerFactory = StaticLoggerBinder::$SINGLETON->getLoggerFactory();
$loggerFactory->setRootMonologLogger($fooLogger);
$loggerFactory->registerMonologLogger($barLogger);
```

```
namespace foo\bar;

class BarClass
{
    public function sayHello()
    {
        LoggerFactory::getLogger(BarClass::class)->info("hello");
    }
}
```

The above info log call will use the `$barLogger` object.

Location information
--------------------

[](#location-information)

It is really hard to identify the source of a log entry if it does not contain any information about it. Some frameworks like log4php supports this feature, and can add the class or the file name to the messages, but Monolog and PSR-3 does not offer it. lf4php automatically prefixes the messages with the location information all the time.

The output of the previous example would something like this:

```
[2015-01-04 13:18:43] foo\bar.INFO: f\b\BarClass - hello [] []

```

History
-------

[](#history)

### 4.2

[](#42)

- Mapped (MDC) Diagnostic Contexts support. More information:
- There is a BC break around configuration. `LoggerFactory::setILoggerFactory()` has been removed, only one `lf4php\impl\StaticLoggerBinder` should be available provided by the binder.

### 4.1

[](#41)

- Performance increased.
- After an `lf4php\Logger` has been obtained for the first time, you cannot register more loggers.

### 4.0

[](#40)

LazyMap (thanks Ocramius) has been introduced to store logger instances in `CachedClassLoggerFactory`. Its interface has been changed:

- the root logger has to be passed to its constructor, the abstract `getDefaultLogger()` method has been removed
- the `map` property became private
- after calling the `getLogger()` method for the first time, no more logger can be registered, otherwise an `RuntimeException` is being thrown

### 3.0

[](#30)

Mustache based MessageFormatter has been modified to use slf4j style. For more information see the description above. Thus Mustache is not a dependency anymore. Now message formatting is more than 4 times faster and log lines are shorter.

###  Health Score

39

—

LowBetter than 86% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity36

Limited adoption so far

Community17

Small or concentrated contributor base

Maturity68

Established project with proven stability

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

Recently: every ~310 days

Total

24

Last Release

2983d ago

Major Versions

1.0.x-dev → 2.0.02012-12-25

2.0.x-dev → 3.0.02013-01-10

3.0.x-dev → 4.0.02014-02-19

4.2.x-dev → 5.0.02018-03-18

PHP version history (2 changes)1.0.0PHP &gt;=5.3.0

5.0.0PHP &gt;=7.1

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/545872?v=4)[Janos Szurovecz](/maintainers/szjani)[@szjani](https://github.com/szjani)

---

Top Contributors

[![janez89](https://avatars.githubusercontent.com/u/87160?v=4)](https://github.com/janez89 "janez89 (1 commits)")

---

Tags

logwrapperfacade

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[monolog/monolog

Sends your logs to files, sockets, inboxes, databases and various web services

21.4k964.9M7.0k](/packages/monolog-monolog)[psr/log

Common interface for logging libraries

10.4k1.2B9.2k](/packages/psr-log)[symfony/monolog-bundle

Symfony MonologBundle

2.9k249.1M1.6k](/packages/symfony-monolog-bundle)[spatie/laravel-activitylog

A very simple activity logger to monitor the users of your website or application

5.8k45.4M309](/packages/spatie-laravel-activitylog)[sentry/sentry

PHP SDK for Sentry (http://sentry.io)

1.9k227.1M273](/packages/sentry-sentry)[sentry/sentry-laravel

Laravel SDK for Sentry (https://sentry.io)

1.3k114.3M154](/packages/sentry-sentry-laravel)

PHPackages © 2026

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