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

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

phoole/logger
=============

Slim, simple and full compatible PSR-3 Logger library for PHP

1.1.0(6y ago)416Apache-2.0PHPPHP &gt;=7.2.0

Since Oct 28Pushed 6y ago1 watchersCompare

[ Source](https://github.com/phoole/logger)[ Packagist](https://packagist.org/packages/phoole/logger)[ RSS](/packages/phoole-logger/feed)WikiDiscussions master Synced today

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

logger
======

[](#logger)

[![Build Status](https://camo.githubusercontent.com/d93cb84e151497f7ce6eef2ff5a6a246024a0d42d41e94a38fa992d1df1accd2/68747470733a2f2f7472617669732d63692e636f6d2f70686f6f6c652f6c6f676765722e7376673f6272616e63683d6d6173746572)](https://travis-ci.com/phoole/logger)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/4f1e08e0ec63c9c50f4a5c4a50142d92fe4e418c0fa8c26ee71a74436e0e75bf/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f70686f6f6c652f6c6f676765722f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/phoole/logger/?branch=master)[![Code Climate](https://camo.githubusercontent.com/c8f8cb577bc43b91821c4154b1e41f5111c99dca19e7ded364d795b802b20191/68747470733a2f2f636f6465636c696d6174652e636f6d2f6769746875622f70686f6f6c652f6c6f676765722f6261646765732f6770612e737667)](https://codeclimate.com/github/phoole/logger)[![PHP 7](https://camo.githubusercontent.com/a0316bbcb255cd91cfb1aaf91025a32a30394bb47e6fe72153cadf9a68beb145/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f70686f6f6c652f6c6f67676572)](https://packagist.org/packages/phoole/logger)[![Latest Stable Version](https://camo.githubusercontent.com/f41f6acbb956e565785f06c7796006ec06bbc594858dc371c1146af70e85d951/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f762f72656c656173652f70686f6f6c652f6c6f67676572)](https://packagist.org/packages/phoole/logger)![License](https://camo.githubusercontent.com/840c71e131357b236d3434d5b9211e95706e433b8966e9e7ca6c46e715a91c71/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f70686f6f6c652f6c6f67676572)

Slim, simple and full compatible [PSR-3](http://www.php-fig.org/psr/psr-3/ "PSR-3: Logger Interface") Logger library for PHP.

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

[](#installation)

Install via the `composer` utility.

```
composer require "phoole/logger"

```

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

```
{
    "require": {
       "phoole/logger": "1.*"
    }
}
```

Usage
-----

[](#usage)

Create the logger instance with a channel id,

```
use Psr\Log\LogLevel;
use Phoole\Logger\Logger;
use Phoole\Logger\Entry\MemoryInfo;
use Phoole\Logger\Handler\SyslogHandler;
use Phoole\Logger\Handler\TerminalHandler;

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

// log every warning to syslog
$logger->addHandler(
    LogLevel::WARNING,
    new SyslogHandler()
);

// log to terminal for MemoryInfo entry
$logger->addHandler(
    LogLevel::INFO,
    new TerminalHandler(),
    MemoryInfo::class // handle this log object only
);

// log a text message
$logger->warning('a warning message');

// log memory usage
$logger->info(new MemoryInfo());
```

Concepts
--------

[](#concepts)

- **Log entry**

    *A log entry* is a message in the form of an object. It solves the problem of **'WHAT TO BE SENT OUT'**. It has a message template, and some processors to process its context.

    For example, `Entry\MemoryInfo` is a predefined log entry with a message template of `{memory_used}M memory used , peak usage is {memory_peak}M`and one `Processor\MemoryProcessor` processor.

    ```
    // with predefined template and processor
    $logger->warning(new MemoryInfo());

    // use new template
    $logger->warning(new MemoryInfo('Peak memory usage is {memory_peak}M'));
    ```

    `Entry\LogEntry` is the log entry prototype used whenever text message is to be logged

    ```
    // using LogEntry
    $logger->info('test only');
    ```

    To define your own log entry,

    ```
    use Phoole\Logger\Entry\LogEntry;

    class MyMessage extends LogEntry
    {
        // message template
        protected $message = 'your {template}';
    }

    // add handler
    $logger->addHandler(
        'warning', // level
        function(LogEntry $entry) { // a handler
            echo (string) $entry;
        },
        MyMessage::class // handle this type of message only
    );

    // output: 'your wow'
    $logger->error(new MyMessage(), ['template' => 'wow']);
    ```
- **Processor**

    *Processors* are associated with log entry classes. They solve the problem of **'WHAT EXTRA INFO TO SENT OUT'**. They will inject information into entries' context. Processors are `callable(LogEntryInterface $entry)`,

    ```
    use Phoole\Logger\Processor\ProcessorAbstract;

    // closure
    $processor1 = function(LogEntry $entry) {
    };

    // invokable object
    $processor2 = new class() {
        public function __invoke(LogEntry $entry)
        {
        }
    }

    // extends
    class Processor3 extends ProcessorAbstract
    {
        protected function updateContext(array $context): array
        {
            $context['bingo'] = 'wow';
            return $context;
        }
    }
    ```

    Processors are attached to log entries either in the entry class definition as follows,

    ```
    class MyMessage extends LogEntry
    {
        // message template
        protected $message = 'your {template}';

        // define processors for this class
        protected static function classProcessors(): array
        {
            return [
                function(LogEntry $entry) {
                    $context = $entry->getContext();
                    $context['template'] = 'wow';
                    $entry->setContext($context);
                },
                new myProcessor(),
            ];
        }
    }
    ```

    or during the handler attachment

    ```
    use Phoole\Logger\Handler\SyslogHandler;

    // will also add 'Processor1' and 'Processor2' to 'MyMessage' class
    $logger->addHandler(
        'info',
        new SyslogHandler(),
        MyMessage::addProcessor(
            new Processor1(),
            new Processor2(),
            ...
        )
    );
    ```
- **Handler**

    *Handlers* solve the problem of **'WHERE TO SEND MESSAGE'**. They take a log entry object and send it to somewhere.

    Handlers takes the form of `callable(LogEntryInterface $entry)` as follows,

    ```
    use Phoole\Logger\Handler\HandlerAbstract;

    $handler1 = function(LogEntry $entry) {
        echo (string) $entry;
    }

    $handler2 = new class() {
        public function __invoke(LogEntry $entry)
        {
        }
    }

    class Handler3 extends HandlerAbstract
    {
        protected function write(LogEntryInterface $entry)
        {
            echo $this->>getFormatter()->format($entry);
        }
    }
    ```

    Handlers are added to the `$logger` with specific log level and type of log message they are going to handle (default is `LogEntryInterface`).

    ```
    $logger->addHandler(
        LogLevel::WARNING,
        new TerminalHandler(),
        LogEntryInterface::class // this is the default anyway
    );
    ```
- **Formatter**

    *Formatters* solve the problem of **'HOW MESSAGE WILL BE PRESENTED''**. Each handler of the type `Handler\HandlerAbstract` may have formatter specified during its initiation.

    ```
    use Phoole\Logger\Handler\TerminalHandler;
    use Phoole\Logger\Formatter\AnsiFormatter;

    // use ANSI Color formatter
    $handler = new TerminalHandler(new AnsiFormatter());

    // add handler handles 'ConsoleMessage' ONLY
    $logger->addHandler('debug', $handler, ConsoleMessage::class);

    // log to console
    $logger->info(new ConsoleMessage('exited with error.'));

    // this will goes handlers handling 'LogEntry'
    $logger->info('exited with error');
    ```

APIs
----

[](#apis)

- `LoggerInterface` related

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

    - `__construct(string $channel)`

        Create the logger with a channel id.
    - `addHandler(string $level, callable $handler, string $entryClass, int $priority = 50): $this`

        Add one handler to specified channel with the priority.
- `Phoole\Logger\Entry\LogEntry` related

    - `static function addProcessor(callable ...$callables): string`

        This method will returns called class name.

Testing
-------

[](#testing)

```
$ composer test
```

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

[](#dependencies)

- PHP &gt;= 7.2.0
- phoole/base 1.\*

License
-------

[](#license)

- [Apache 2.0](https://www.apache.org/licenses/LICENSE-2.0)

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity10

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity56

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

Total

5

Last Release

2370d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/3bae7d5f135e90fd05271574bfd04d4844169bd4c554eaa9e103e4af69267ffc?d=identicon)[phoole](/maintainers/phoole)

---

Top Contributors

[![phossa](https://avatars.githubusercontent.com/u/8499165?v=4)](https://github.com/phossa "phossa (11 commits)")[![phoole](https://avatars.githubusercontent.com/u/55728163?v=4)](https://github.com/phoole "phoole (1 commits)")

---

Tags

loggerphoolephppsr-3swoolepsr-3phplibraryswooleloggerphoole

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

PHPackages © 2026

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