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

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

phossa2/logger
==============

A PSR-3 compliant logging libraray for PHP

2.0.1(9y ago)2291MITPHPPHP &gt;=5.4.0

Since Jul 22Pushed 6y ago1 watchersCompare

[ Source](https://github.com/phossa2/logger)[ Packagist](https://packagist.org/packages/phossa2/logger)[ Docs](https://github.com/phossa2/logger)[ RSS](/packages/phossa2-logger/feed)WikiDiscussions master Synced 2mo ago

READMEChangelog (2)Dependencies (3)Versions (3)Used By (1)

phossa2/logger \[ABANDONED\]
============================

[](#phossa2logger-abandoned)

**PLEASE USE [phoole/logger](https://github.com/phoole/logger) library instead**

[![Build Status](https://camo.githubusercontent.com/d112ae8600a0a9b7c478b1c2e2c582e483d24e9b5126307ee94c20db60a97b90/68747470733a2f2f7472617669732d63692e6f72672f70686f737361322f6c6f676765722e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/phossa2/logger)[![Code Quality](https://camo.githubusercontent.com/39dfbfbbe63b02ed2092f4ef6aa318f1523f606ad50b9fd8b5be166a2e25e835/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f70686f737361322f6c6f676765722f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/phossa2/logger/)[![Code Climate](https://camo.githubusercontent.com/2a556ccb5920c3da6c7cb7f56be57767d3f1a174cb9c208bf28473d36fa24045/68747470733a2f2f636f6465636c696d6174652e636f6d2f6769746875622f70686f737361322f6c6f676765722f6261646765732f6770612e737667)](https://codeclimate.com/github/phossa2/logger)[![PHP 7 ready](https://camo.githubusercontent.com/fb05d180635ba0c5d5c9cc411f004f329adb3724a979e141060a442520e77862/687474703a2f2f7068703772656164792e74696d6573706c696e7465722e63682f70686f737361322f6c6f676765722f6d61737465722f62616467652e737667)](https://travis-ci.org/phossa2/logger)[![HHVM](https://camo.githubusercontent.com/f11d0cee65999f1f691115e835e4709b89a08c32d53cf3dedc02209bdd9a37ad/68747470733a2f2f696d672e736869656c64732e696f2f6868766d2f70686f737361322f6c6f676765722e7376673f7374796c653d666c6174)](http://hhvm.h4cc.de/package/phossa2/logger)[![Latest Stable Version](https://camo.githubusercontent.com/1b790601a42c4f899f802ab274a90668db91f49591c9bd93deaf35865f03b7ea/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f767072652f70686f737361322f6c6f676765722e7376673f7374796c653d666c6174)](https://packagist.org/packages/phossa2/logger)[![License](https://camo.githubusercontent.com/4fc6538ded72843e26a272d300ce4c95da083ce92576e10e4fdd505d579a8125/68747470733a2f2f696d672e736869656c64732e696f2f3a6c6963656e73652d6d69742d626c75652e737667)](http://mit-license.org/)

**phossa2/logger** is a [PSR-3](http://www.php-fig.org/psr/psr-3/ "PSR-3: Logger Interface") compliant logging library. It is a rewrite of Monolog with couple of changes.

It requires PHP 5.4, supports PHP 7.0+ and HHVM. It is compliant with [PSR-1](http://www.php-fig.org/psr/psr-1/ "PSR-1: Basic Coding Standard"), [PSR-2](http://www.php-fig.org/psr/psr-2/ "PSR-2: Coding Style Guide"), [PSR-3](http://www.php-fig.org/psr/psr-3/ "PSR-3: Logger Interface"), [PSR-4](http://www.php-fig.org/psr/psr-4/ "PSR-4: Autoloader"), and the proposed [PSR-5](https://github.com/phpDocumentor/fig-standards/blob/master/proposed/phpdoc.md "PSR-5: PHPDoc").

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

[](#installation)

Install via the `composer` utility.

```
composer require "phossa2/logger=2.*"

```

or add the following lines to your `composer.json`

```
{
    "require": {
       "phossa2/logger": "2.*"
    }
}
```

Usage
-----

[](#usage)

Create the logger instance with default channel,

```
use Phossa2\Logger\Logger;
use Phossa2\Logger\Handler\SyslogHandler;
use Phossa2\Logger\Handler\LogfileHandler;
use Phossa2\Logger\Processor\MemoryProcessor;
use Phossa2\Logger\Processor\InterpolateProcessor;

// with default channel
$logger = new Logger('MyApp');

// attach memory processor
$logger->addProcessor(new MemoryProcessor());

// attach interpolate processor to all channels' ('*') end (-100)
$logger->addProcessor(new InterpolateProcessor(), '*', -100);

// attach syslog handler to user related channels
$logger->addHandler('debug', new SyslogHandler(), 'user.*');

// attach file handler to all channels
$logger->addHandler('warning', new LogfileHandler('/tmp/app.log'));

// log to system.usage channel
$logger
    ->with('system.usage')
    ->debug('memory used {memory.used} and peak is {memory.peak}');

// log to user.login channel
$logger
    ->with('user.login')
    ->info('user logged in as {user.username}', ['user' => $user]);

// log to default channel
$logger->debug('a test message');
```

Features
--------

[](#features)

- **Channels**

    Creative usage of channels. `Handler` and `Processor` now can be bound to different channels, also with channel name globbing.

    - *Channel globbing*

        By default, handlers and processors are bound to `'*'` channel which globs to all. But they also can be bound to channels like `'user.*'` or more specific one `'user.login'`.

        ```
        // bind to 'user.*' channels
        $logger->addHandler('warning', new LogfileHandler('/log/user.log'), 'user.*');

        // bind to 'system.*' channels
        $logger->addHandler('error', new LogfileHandler('/log/system.log'), 'system.*');

        // add user info only in 'user.*' channel
        $logger->addProcessor(new UserProcessor(), 'user.*');
        ```

        log messages can be sent to specific channels by using of `with()` in front of any logging related methods, such as `log()`, `warning()` etc.

        ```
        $logger->with('user.login')->info('user {user.username} logged info');
        ```

        The `info()` method in the previous code will trigger user info being inserted into context array by the `UserProcessor` and being logged to file `/log/user.log`.

        **Note**: Channel names are *case insensitive*.

        **Note**: Same handler or processor can be bound to different channels. But will be executed only *ONCE* in one log call.
    - *Single logger*

        With the support for logging to different channels, there is no need to create multiple loggers in one application. By carefully designing your channel hierachy, you may use one logger through out your site.
- **Priority**

    Handlers and processors are now can injected into the logger with different priorities (range from `-100` to `100`, default is `0`).

    - Higher priority means executed first

        ```
        // add user info at first
        $logger->addProcessor(new UserProcessor(), 'user.*', 100);

        // interpolate should be done last (just before executing handlers)
        $logger->addProcessor(new InterpolateProcessor(), '*', -100);
        ```
    - First in first out(executed) for same priority

        Default priority value is `0`. The following handlers executed in the order of their addition.

        ```
        // log to file first
        $logger->addHandler('debug', new LogfileHandler('/log/log.txt'));

        // then log to mail
        $logger->addHandler('debug', new MailHandler('admin@my.com'));
        ```
- **Simple callable interface**

    Handlers, formatters, processors are now all using the single interface

    ```
    public function __invoke(LogEntryInterface $logEntry);
    ```

    Which means, user may use predefined functions or other callables to servce as handler, formatter or processor, as long as these callables take the `LogEntryInterface` as the parameter.

    A quick handler as follows,

    ```
    function myHandler(LogEntryInterface $logEntry) {
        // get formatted message
        $formatted = $logEntry->getFormatted();

        // write to my device ...
    }
    ```

    Or even,

    ```
    $logger->addHandler('error', function($log) {
        // write the log to my device
    }, 'user.*');
    ```
- **LogEntry**

    In stead of using array as data type for the log message. The `LogEntryInterface` is defined to serve as default data type for logs.

    You may even extend the `LogEntry` class, and use it in your logger

    ```
    class MyLogEntry extends LogEntry
    {
        // ...
    }
    ```

    Use it in your logger as the prototype for all log messages,

    ```
    $entryPrototype = new MyLogEntry('channel','debug', 'message');

    $logger = new Logger('MyApp', $entryPrototype);
    ```

APIs
----

[](#apis)

- `LoggerInterface` related

    See [PSR-3](http://www.php-fig.org/psr/psr-3/ "PSR-3: Logger Interface") for standard related APIs.
- `Phossa2\Logger\Logger` related

    - `__construct(string $defaultChannel = 'LOGGER', LogEntryInterface $logPrototype = null)`

        Create the logger.
    - `with(string $channel): $this`

        Specify the channel for the comming logging method.
    - `addHandler(string $level, callable $handler, string $channel = '*', int $priority = 0): $this`

        Add one handler to specified channel with the priority.
    - `addProcessor(callable $processor, string $channel = '*', int $priority = 0): $this`

        Add one processor to specified channel with the priority.
    - `removeHandler(callable|string $handlerOrClassname, $channel = '')`

        Remove the handler (or specify handler's classname) from the specified channel. If `$channel` is empty, then remove from all channels.
    - `removeProcessor(callable|string $processorOrClassname, $channel = '')`

        Remove the processor (or specify processor's classname) from the specified channel. If `$channel` is empty, then remove from all channels.

Change log
----------

[](#change-log)

Please see [CHANGELOG](CHANGELOG.md) from more information.

Testing
-------

[](#testing)

```
$ composer test
```

Contributing
------------

[](#contributing)

Please see [CONTRIBUTE](CONTRIBUTE.md) for more information.

Dependencies
------------

[](#dependencies)

- PHP &gt;= 5.4.0
- phossa2/shared &gt;= 2.0.21

License
-------

[](#license)

[MIT License](http://mit-license.org/)

###  Health Score

27

—

LowBetter than 49% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity10

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity59

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 91.7% 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 ~0 days

Total

2

Last Release

3584d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/6e0ecf2ab11402101d86a36b457973b81149757a53a67dd048bbfb9025890abf?d=identicon)[phossa2](/maintainers/phossa2)

---

Top Contributors

[![phossa](https://avatars.githubusercontent.com/u/8499165?v=4)](https://github.com/phossa "phossa (22 commits)")[![phossa2](https://avatars.githubusercontent.com/u/19922046?v=4)](https://github.com/phossa2 "phossa2 (2 commits)")

---

Tags

psrpsr-3loggingloggerphossa

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[analog/analog

Fast, flexible, easy PSR-3-compatible PHP logging package with dozens of handlers.

3451.5M24](/packages/analog-analog)[apix/log

Minimalist, thin and fast PSR-3 compliant (multi-bucket) logger.

511.0M18](/packages/apix-log)[inpsyde/wonolog

Monolog-based logging package for WordPress.

183617.9k7](/packages/inpsyde-wonolog)[markrogoyski/simplelog-php

Powerful PSR-3 logging. So easy, it's simple.

2818.1k4](/packages/markrogoyski-simplelog-php)

PHPackages © 2026

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