PHPackages                             lfbn/logger-trait - 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. lfbn/logger-trait

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

lfbn/logger-trait
=================

A trait that allows you to add logging capabilities to any class.

0.0.1(6y ago)017MITPHPCI failing

Since Jan 9Pushed 6y ago1 watchersCompare

[ Source](https://github.com/lfbn/logger-trait)[ Packagist](https://packagist.org/packages/lfbn/logger-trait)[ RSS](/packages/lfbn-logger-trait/feed)WikiDiscussions master Synced 3w ago

READMEChangelog (1)Dependencies (4)Versions (2)Used By (0)

Logger Trait
============

[](#logger-trait)

This is a Trait that allows to have logging capabilities in any class.

By default, it uses Monolog and streams to standard output, but you can override this behaviour.

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

[](#installation)

```
composer require lfbn/logger-trait
```

Usage
-----

[](#usage)

### Using the default behaviour

[](#using-the-default-behaviour)

```
// In the class you want, add the use of the Trait.
use LoggerTrait;

(...)

// After that, you can use it.
$this->logError('Some message...', ['some context']);
```

### Changing name, stream or minimum level

[](#changing-name-stream-or-minimum-level)

```
// Implement the following protected properties.
/* @var string */
protected static $loggerName = 'my-logger-name';

/* @var string */
protected static $loggerStream = 'php://stdout';

/* @var string */
protected static $loggerMinimumLevel = LogLevel::DEBUG;
```

### Overriding the default behaviour

[](#overriding-the-default-behaviour)

```
class MyClass {
   protected function initLogger(): bool
   {
       $this->logger = new \Monolog\Logger('Overriding default logger: '.$this->getLoggerName());

       try {
           $handler = new StreamHandler(
               $this->getLoggerStream(),
               $this->getLoggerMinimumLevel()
           );
           $this->logger->pushHandler($handler);
       } catch (Exception $e) {
           $this->logger = new NullLogger();

           return false;
       }

       return true;
   }
}
```

### Inject your own logger

[](#inject-your-own-logger)

```
class Test {
    use \Lfbn\LoggerTrait\LoggerTrait;
    public function test(): void
    {
        $this->logDebug('Hello TEST!');
    }
}

$logger = new \Monolog\Logger('test4-my-own-logger');

try {
    $handler = new StreamHandler(
        'php://stdout',
        'debug'
    );
    $logger->pushHandler($handler);
} catch (Exception $e) {
    $logger = new NullLogger();
}

$myClass = (new Test());
$myClass->setLogger($logger);
$myClass->test();
```

### Interpolate messages

[](#interpolate-messages)

```
$this->logWarning(
            self::interpolateMessage(
                'Hello my {private} TEST5!',
                ['private' => 'message']
            ),
        );
```

###  Health Score

22

—

LowBetter than 21% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity47

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

Unknown

Total

1

Last Release

2366d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/6152567?v=4)[Luís Nóbrega](/maintainers/lfbn)[@lfbn](https://github.com/lfbn)

---

Top Contributors

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

---

Tags

loggerloggingtraitlogginglogger

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/lfbn-logger-trait/health.svg)

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

###  Alternatives

[matomo/matomo

Matomo is the leading Free/Libre open analytics platform

21.7k38.9k](/packages/matomo-matomo)[laravel/framework

The Laravel Framework.

34.8k543.8M19.9k](/packages/laravel-framework)[tempest/framework

The PHP framework that gets out of your way.

2.2k34.4k15](/packages/tempest-framework)[sentry/sentry

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

1.9k247.1M331](/packages/sentry-sentry)[illuminate/log

The Illuminate Log package.

6225.3M621](/packages/illuminate-log)[flow-php/flow

PHP ETL - Extract Transform Load - Data processing framework

85036.3k](/packages/flow-php-flow)

PHPackages © 2026

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