PHPackages                             dan-d-martin/logger-aware - 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. dan-d-martin/logger-aware

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

dan-d-martin/logger-aware
=========================

Simply and transparently add logger support to a class

1.1.0(4y ago)011.2kMITPHPPHP &gt;=7.0

Since Dec 2Pushed 4y ago1 watchersCompare

[ Source](https://github.com/dan-d-martin/logger-aware)[ Packagist](https://packagist.org/packages/dan-d-martin/logger-aware)[ RSS](/packages/dan-d-martin-logger-aware/feed)WikiDiscussions master Synced 1mo ago

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

LoggerAware - easily and transparently add logger support to a class
====================================================================

[](#loggeraware---easily-and-transparently-add-logger-support-to-a-class)

Introduction
------------

[](#introduction)

The LoggerAware library provides two things: a LoggerAware trait which adds logger support to a class, and a NullLogger class which allows logger support to be optional.

The problem which this library aims to solve is that of adding logging support to a class in as lightweight and transparent a manner as possible. Best practice dictates that a Logger service should be injected into any class which requires it, but to do this means adding code to the class which does not contribute to the behaviour of the class (logging should be an optional behaviour; it is not a required function of most classes) furthermore, if injection of the logger is optional then the class doing the logging must check each time it wants to log that a logger is actually present. This adds further overhead.

This library abstracts this code away into a trait which can be added to any class requiring the logger. The trait provides a setLogger() method allowing a logger to be injected and a getLogger() method by which the class can obtain the logger. If no logger is injected a NullLogger is provided, which provides all the logging methods but performs no actions. This allows classes to be certain they can call logging methods.

Usage
-----

[](#usage)

Adding logger support to a class is as simple as adding the trait:

```
use DanDMartin\LoggerAware\Traits\LoggerAware;

class MyClass
{
	use LoggerAware;

	public function doSomething()
	{
		$this->getLogger()->info('Doing something');
		// do something...
	}
}
```

Now, if a logger is available, MyClass will use it to write log messages. By default, the NullLogger will be used and nothing will happen, but it's a simple matter to inject a different logger:

```
$myClass = new MyClass();
$logger = new \Monolog\Logger('logger');

$myClass->setLogger($logger);
$myClass->doSomething();
```

Now all logging will be performed by the injected logger.

###  Health Score

30

—

LowBetter than 65% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity19

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity61

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

Total

3

Last Release

1494d ago

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

1.1.0PHP &gt;=7.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/b5ae2b62e0c30dc10d10c024f9ccf668ae9b79b69e38ab74f7b983e236f7e11f?d=identicon)[dan-d-martin](/maintainers/dan-d-martin)

---

Top Contributors

[![dan-d-martin](https://avatars.githubusercontent.com/u/1822432?v=4)](https://github.com/dan-d-martin "dan-d-martin (6 commits)")

### Embed Badge

![Health badge](/badges/dan-d-martin-logger-aware/health.svg)

```
[![Health](https://phpackages.com/badges/dan-d-martin-logger-aware/health.svg)](https://phpackages.com/packages/dan-d-martin-logger-aware)
```

###  Alternatives

[sentry/sentry

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

1.9k227.1M271](/packages/sentry-sentry)[rollbar/rollbar

Monitors errors and exceptions and reports them to Rollbar

33723.7M81](/packages/rollbar-rollbar)[illuminate/log

The Illuminate Log package.

6224.3M517](/packages/illuminate-log)[open-telemetry/sdk

SDK for OpenTelemetry PHP.

2222.9M248](/packages/open-telemetry-sdk)[open-telemetry/api

API for OpenTelemetry PHP.

1833.0M214](/packages/open-telemetry-api)[pagemachine/typo3-formlog

Form log for TYPO3

23225.3k6](/packages/pagemachine-typo3-formlog)

PHPackages © 2026

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