PHPackages                             harbor/monolog-manager - 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. harbor/monolog-manager

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

harbor/monolog-manager
======================

Manages multiple Monolog loggers

1.0.2(5y ago)112MITPHPPHP ^7.4 || ^8.0

Since Jan 17Pushed 5y agoCompare

[ Source](https://github.com/harborphp/monolog-manager)[ Packagist](https://packagist.org/packages/harbor/monolog-manager)[ RSS](/packages/harbor-monolog-manager/feed)WikiDiscussions main Synced today

READMEChangelog (3)Dependencies (6)Versions (4)Used By (0)

Monolog Manager
===============

[](#monolog-manager)

[Monolog](https://github.com/Seldaek/monolog) Manager allows you to easily create and use multiple logging channels. The manager utilizes [Monolog Factory](https://github.com/nikolaposa/monolog-factory) for easy, configuration-based, creation of the Loggers.

You can optionally use a [PSR-11](https://www.php-fig.org/psr/psr-11/) dependency injection container for Handler, Processor, and Formatter resolution within your logger configuration.

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

[](#installation)

The preferred method of installation is via [Composer](http://getcomposer.org/). Run the following command to install the latest version of a package and add it to your project's `composer.json`:

```
composer require harbor/monolog-manager
```

Usage
-----

[](#usage)

### Adding logging channels

[](#adding-logging-channels)

```
use Monolog\Formatter\HtmlFormatter;
use Monolog\Formatter\LineFormatter;
use Monolog\Handler\NativeMailerHandler;
use Monolog\Handler\StreamHandler;
use Monolog\Processor\PsrLogMessageProcessor;
use Psr\Log\LogLevel;

$manager = new Harbor\MonologManager\Manager();

// Setup the default logger
$manager->add('app', [
    'default' => true,
    'handlers' => [
        'name' => StreamHandler::class,
        'params' => [
            'stream' => 'path/to/your.log',
            'level' => LogLevel::WARNING,
        ],
        'formatter' => [
            'name' => LineFormatter::class,
            'params' => [
                'allowInlineLineBreaks' => false,
                'ignoreEmptyContextAndExtra' => true,
            ],
        ],
    ],
    'processors' => [
        [
            'name' => PsrLogMessageProcessor::class,
        ]
    ],
]);

// Add an additional logging channel
$manager->add('alert', [
    'handlers' => [
        [
            'name' => NativeMailerHandler::class,
            'params' => [
                'to' => 'alerts@example.com',
                'subject' => 'Application Alert',
                'from' => 'noreply@example.com',
                'level' => Logger::ALERT,
            ],
            'formatter' => [
                'name' => HtmlFormatter::class,
            ],
        ],
    ],
    'processors' => [
        [
            'name' => PsrLogMessageProcessor::class,
        ]
    ],
]);
```

### Logging to the default channel

[](#logging-to-the-default-channel)

The `Manager` implements the `Psr\Log\LoggerInterface`, and sends the log message to the default channel.

```
// These logs be sent to the `app` channel we configured above.
$manager->emergency('test emergency');
$manager->alert('test alert');
$manager->critical('test critical');
$manager->error('test error');
$manager->warning('test warning');
$manager->notice('test notice');
$manager->info('test info');
$manager->debug('test debug');
$manager->log(LogLevel::INFO, 'test log');
```

Additionally, you can call any method on the default channel's `Mongolog\Logger` instance:

```
$manager->getName(); // returns "app"
```

### Logging to a specific channel

[](#logging-to-a-specific-channel)

Using the `channel(?string $name = null)` method on `Manager`, you can get that channel's `Mongolog\Logger` instance:

```
/** @var \Mongolog\Logger */
$logger = $manager->channel('alert');
$logger->alert('Something important happened!');
```

Emergency Logger
----------------

[](#emergency-logger)

By default, the `Manager` will return a default "emergency logger" if an error occurs while creating the Logger instance".

This is to prevent logging configuration/usage issues from stopping script execution.

The default emergency logger added via:

```
$manager->add(Manager::EMERGENCY_CHANNEL, [
    'handlers' => [
        [
            'name' => \Monolog\Handler\StreamHandler::class,
            'params' => [
                'stream' => 'php://stderr',
                'level' => \Psr\Log\LogLevel::DEBUG,
            ],
        ],
    ],
]);
```

**Supplying your own emergency logger:**

Simply add a channel, using `Manager::EMERGENCY_CHANNEL` as the channel name.

### Disabling the emergency logger

[](#disabling-the-emergency-logger)

```
$manager->useEmergencyChannel(false);
```

Using a Dependency Injection Container
--------------------------------------

[](#using-a-dependency-injection-container)

To use a [PSR-11](https://www.php-fig.org/psr/psr-11/) container to resolve dependencies:

### Setup

[](#setup)

```
use Harbor\MonologManager\Factory;
use Harbor\MonologManager\Manager;
use Psr\Container\ContainerInterface;

/** @var ContainerInterface */
$container = getContainer();

// Create a new Factory, providing the container
$factory = new Factory($container);

// Provide your factory to the Manager
$manager = new Manager($factory);
```

### Using the container in your channel config

[](#using-the-container-in-your-channel-config)

The `handlers`, `processors`, and `formatter` are resolved using the following logic:

***Note:** The term `callable` refers to any value where `is_callable($value) === true` **OR** any class where `method_exists($value, '__invoke')`*

1. If value is an object of the correct type: `$value = $value`
2. If value is a string, and `$container->has($value)`: `$value = $container->get($value)`
3. If value is a string, and is callable: `$value = $value($container)`
4. If value is an array, and `isset($value['formatter'])`: `$value['formatter'] = $this->resolve($value['formatter'])`

If the value cannot be resolved, an `InvalidArgumentException` is thrown (which gets sent to the emergency logger by default, see above)

**Example of all possible values:**

```
$manager->add('useless-logger', [
    'handlers' => [
        HandlerFactory::class,
        NoopHandler::class,
        new NoopHandler(),
        static fn () => new NoopHandler(),
        [
            'name' => ErrorLogHandler::class,
            'formatter' => LineFormatter::class,
        ],
        [
            'name' => ErrorLogHandler::class,
            'formatter' => new LineFormatter(),
        ],
    ],
    'processors' => [
        PsrLogMessageProcessor::class,
        new MemoryUsageProcessor(),
    ],
]);
```

License
-------

[](#license)

Released under MIT License

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity7

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity60

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

Total

3

Last Release

1928d ago

### Community

Maintainers

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

---

Top Contributors

[![dhrrgn](https://avatars.githubusercontent.com/u/149921?v=4)](https://github.com/dhrrgn "dhrrgn (6 commits)")

---

Tags

monolog

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/harbor-monolog-manager/health.svg)

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

###  Alternatives

[inpsyde/wonolog

Monolog-based logging package for WordPress.

183617.9k6](/packages/inpsyde-wonolog)[nikolaposa/monolog-factory

Configuration-based Monolog factory

25226.9k2](/packages/nikolaposa-monolog-factory)[tylercd100/laravel-notify

12152.1k1](/packages/tylercd100-laravel-notify)

PHPackages © 2026

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