PHPackages                             wikimedia/normalized-exception - 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. wikimedia/normalized-exception

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

wikimedia/normalized-exception
==============================

A helper for making exceptions play nice with PSR-3 logging

v2.1.1(1y ago)1388.3k↑26.5%3MITPHPPHP &gt;=7.4

Since Jun 30Pushed 2mo ago16 watchersCompare

[ Source](https://github.com/wikimedia/mediawiki-libs-NormalizedException)[ Packagist](https://packagist.org/packages/wikimedia/normalized-exception)[ Docs](https://www.mediawiki.org/wiki/NormalizedException)[ RSS](/packages/wikimedia-normalized-exception/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (7)Versions (6)Used By (3)

[![Latest Stable Version](https://camo.githubusercontent.com/a5f2a2ac1eee12d8d340f980518cc21408eda97e431767e71b754a73751cb40b/68747470733a2f2f706f7365722e707567782e6f72672f77696b696d656469612f6e6f726d616c697a65642d657863657074696f6e2f762f737461626c652e737667)](https://packagist.org/packages/wikimedia/normalized-exception) [![License](https://camo.githubusercontent.com/aa94111b3d2dd8dbce629c65757b9f984684d4321c7d2e68dae4e3cb21e4a239/68747470733a2f2f706f7365722e707567782e6f72672f77696b696d656469612f6e6f726d616c697a65642d657863657074696f6e2f6c6963656e73652e737667)](https://packagist.org/packages/wikimedia/normalized-exception)

NormalizedException
===================

[](#normalizedexception)

A minimal library to facilitate [PSR-3](https://www.php-fig.org/psr/psr-3/)-friendly exception handling.

Additional documentation about the library can be found on [MediaWiki.org](https://www.mediawiki.org/wiki/NormalizedException).

Usage
-----

[](#usage)

The NormalizedException library provides an INormalizedException interface that exception classes can use to support a standardized way of logging their error messages in a PSR-3 compatible manner.

If you don't care about the exception class, you can use the standard implementation:

```
use Wikimedia\NormalizedException\NormalizedException;

throw new NormalizedException( 'Invalid value: {value}', [ 'value' => $value ] );
```

```
use Wikimedia\NormalizedException\INormalizedException;

try {
	mightThrow();
} catch ( INormalizedException $e ) {
	$psr3Logger->error( $e->getNormalizedMessage(), $e->getMessageContext() );
	echo 'Error: ' . $e->getMessage();
}
```

To make a specific exception class normalized, if it's constructed from a message and optionally an error code and a previous exception (like most PHP core exceptions), you can use a trait and a default constructor provided by that trait:

```
use Exception
use Wikimedia\NormalizedException\INormalizedException;
use Wikimedia\NormalizedException\NormalizedExceptionTrait;

class MyException extends Exception implements INormalizedException {
	use NormalizedExceptionTrait {
		NormalizedExceptionTrait::normalizedConstructor as __construct;
	}
}
```

```
throw new MyException( 'Invalid value!' );
throw new MyException( 'Invalid value: {value}', [ 'value' => $value ] );
throw new MyException( 'Invalid value: {value}', [ 'value' => $value ], /* code */ -1, $previous );
```

Exceptions with different parameters need their own constructor:

```
use Wikimedia\NormalizedException\INormalizedException;
use Wikimedia\NormalizedException\NormalizedExceptionTrait;

class MyException extends SomeException implements INormalizedException {
	use NormalizedExceptionTrait;

	public function __construct(
		string $normalizedMessage,
		array $messageContext = [],
		$otherParam1,
		$otherParam2
	) {
		// these properties are defined by the trait and must be set
		$this->normalizedMessage = $normalizedMessage;
		$this->messageContext = $messageContext;

		// replaces the PSR-3 tokens
		$message = self::getMessageFromNormalizedMessage( $normalizedMessage, $messageContext );

		parent::__construct( $message, $otherParam1, $otherParam2 );
	}
}
```

Running tests
-------------

[](#running-tests)

```
composer install --dev
composer test

```

History
-------

[](#history)

This library was split out of [MediaWiki](https://www.mediawiki.org/wiki/MediaWiki) changeset [670465](https://gerrit.wikimedia.org/r/c/mediawiki/core/+/670465) during the MediaWiki 1.37 development cycle.

---

###  Health Score

48

—

FairBetter than 94% of packages

Maintenance67

Regular maintenance activity

Popularity36

Limited adoption so far

Community24

Small or concentrated contributor base

Maturity55

Maturing project, gaining track record

 Bus Factor2

2 contributors hold 50%+ of commits

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

Total

5

Last Release

478d ago

Major Versions

v1.0.1 → v2.0.02024-11-10

PHP version history (2 changes)v1.0.0PHP &gt;=7.2.9

v2.0.0PHP &gt;=7.4

### Community

Maintainers

![](https://www.gravatar.com/avatar/b94d9718c06ec7c3fd7a104bc44966fb7464b9ec7411582343ea35a7a6a85f08?d=identicon)[mediawiki](/maintainers/mediawiki)

![](https://www.gravatar.com/avatar/716c86d71cbf921e7912a505f89d799de398fc0a3af0bd4c8862834b2d642bd7?d=identicon)[wikimedia](/maintainers/wikimedia)

---

Top Contributors

[![tgr](https://avatars.githubusercontent.com/u/145412?v=4)](https://github.com/tgr "tgr (10 commits)")[![jdforrester](https://avatars.githubusercontent.com/u/881572?v=4)](https://github.com/jdforrester "jdforrester (7 commits)")[![reedy](https://avatars.githubusercontent.com/u/67615?v=4)](https://github.com/reedy "reedy (3 commits)")[![lucaswerkmeister](https://avatars.githubusercontent.com/u/2346599?v=4)](https://github.com/lucaswerkmeister "lucaswerkmeister (2 commits)")[![umherirrender](https://avatars.githubusercontent.com/u/1174884?v=4)](https://github.com/umherirrender "umherirrender (2 commits)")[![DannyS712](https://avatars.githubusercontent.com/u/46829944?v=4)](https://github.com/DannyS712 "DannyS712 (1 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/wikimedia-normalized-exception/health.svg)

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

###  Alternatives

[psr/log

Common interface for logging libraries

10.4k1.2B9.2k](/packages/psr-log)[itsgoingd/clockwork

php dev tools in your browser

5.9k27.6M94](/packages/itsgoingd-clockwork)[graylog2/gelf-php

A php implementation to send log-messages to a GELF compatible backend like Graylog2.

41838.2M138](/packages/graylog2-gelf-php)[bugsnag/bugsnag-psr-logger

Official Bugsnag PHP PSR Logger.

32132.5M2](/packages/bugsnag-bugsnag-psr-logger)[consolidation/log

Improved Psr-3 / Psr\\Log logger based on Symfony Console components.

15462.2M7](/packages/consolidation-log)[datadog/php-datadogstatsd

An extremely simple PHP datadogstatsd client

19124.6M15](/packages/datadog-php-datadogstatsd)

PHPackages © 2026

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