PHPackages                             dotkernel/dot-log - 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. dotkernel/dot-log

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

dotkernel/dot-log
=================

Dotkernel log component implementing PSR-3

5.3.0(7mo ago)553.2k↑1513.6%2[1 PRs](https://github.com/dotkernel/dot-log/pulls)1MITPHPPHP ~8.2.0 || ~8.3.0 || ~8.4.0 || ~8.5.0CI failing

Since Mar 9Pushed 7mo ago1 watchersCompare

[ Source](https://github.com/dotkernel/dot-log)[ Packagist](https://packagist.org/packages/dotkernel/dot-log)[ Docs](https://github.com/dotkernel/dot-log)[ RSS](/packages/dotkernel-dot-log/feed)WikiDiscussions 5.0 Synced 3w ago

READMEChangelog (10)Dependencies (7)Versions (49)Used By (1)

dot-log
=======

[](#dot-log)

Robust, composite PSR-3 compliant logger with filtering and formatting.

Version History
---------------

[](#version-history)

BranchService ManagerLog style implementationPHP Version5.0Service Manager 4PSR-Log[![PHP from Packagist (specify version)](https://camo.githubusercontent.com/24ea5ed05d83016c97b96abe5f75ba94abe3feecff548cfa2769fbec0e339781/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f646f746b65726e656c2f646f742d6c6f672f352e332e30)](https://camo.githubusercontent.com/24ea5ed05d83016c97b96abe5f75ba94abe3feecff548cfa2769fbec0e339781/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f646f746b65726e656c2f646f742d6c6f672f352e332e30)4.1Service Manager 4Laminas Log style[![PHP from Packagist (specify version)](https://camo.githubusercontent.com/0a5a5af9db248b1138d92c132591dd640a1c4ebdc8770c3e8561e1ee17996dd8/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f646f746b65726e656c2f646f742d6c6f672f342e312e33)](https://camo.githubusercontent.com/0a5a5af9db248b1138d92c132591dd640a1c4ebdc8770c3e8561e1ee17996dd8/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f646f746b65726e656c2f646f742d6c6f672f342e312e33)4.0Service Manager 3Laminas Log style[![PHP from Packagist (specify version)](https://camo.githubusercontent.com/18fc3f2e28d973d510e0ab53c9b4cd15b83bc075bea7518e40757569afbacd99/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f646f746b65726e656c2f646f742d6c6f672f342e302e35)](https://camo.githubusercontent.com/18fc3f2e28d973d510e0ab53c9b4cd15b83bc075bea7518e40757569afbacd99/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f646f746b65726e656c2f646f742d6c6f672f342e302e35)3.0Service Manager 3Laminas Log[![PHP from Packagist (specify version)](https://camo.githubusercontent.com/a5683c231c9a00b2e2a5a7a18ffe335120a8b9b6de75f51cd604472d0f41b8a8/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f646f746b65726e656c2f646f742d6c6f672f332e352e34)](https://camo.githubusercontent.com/a5683c231c9a00b2e2a5a7a18ffe335120a8b9b6de75f51cd604472d0f41b8a8/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f646f746b65726e656c2f646f742d6c6f672f332e352e34)Documentation
-------------

[](#documentation)

Documentation is available at: .

Badges
------

[](#badges)

[![OSS Lifecycle](https://camo.githubusercontent.com/43e0bbf3256d7f2637856789b9438c74e19c3ab52b5abf2e31175d32b520f8b9/68747470733a2f2f696d672e736869656c64732e696f2f6f73736c6966656379636c652f646f746b65726e656c2f646f742d6c6f67)](https://camo.githubusercontent.com/43e0bbf3256d7f2637856789b9438c74e19c3ab52b5abf2e31175d32b520f8b9/68747470733a2f2f696d672e736869656c64732e696f2f6f73736c6966656379636c652f646f746b65726e656c2f646f742d6c6f67)[![PHP from Packagist (specify version)](https://camo.githubusercontent.com/24ea5ed05d83016c97b96abe5f75ba94abe3feecff548cfa2769fbec0e339781/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f646f746b65726e656c2f646f742d6c6f672f352e332e30)](https://camo.githubusercontent.com/24ea5ed05d83016c97b96abe5f75ba94abe3feecff548cfa2769fbec0e339781/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f646f746b65726e656c2f646f742d6c6f672f352e332e30)

[![GitHub issues](https://camo.githubusercontent.com/0585c9986d962ea19734dc0df1c7bc92bba936481fe61f5891243ad80dc691ac/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6973737565732f646f746b65726e656c2f646f742d6c6f67)](https://github.com/dotkernel/dot-log/issues)[![GitHub forks](https://camo.githubusercontent.com/222fd3bd4d0f67e75b77a91dabdaf946b2bd16347f90f993711cea24c280c31e/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f666f726b732f646f746b65726e656c2f646f742d6c6f67)](https://github.com/dotkernel/dot-log/network)[![GitHub stars](https://camo.githubusercontent.com/cef5274a27747e2dacf99bb266330dcd598cdfadaa975b683f49fc4e3110c862/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f73746172732f646f746b65726e656c2f646f742d6c6f67)](https://github.com/dotkernel/dot-log/stargazers)[![GitHub license](https://camo.githubusercontent.com/8faef8b3bde0aecd5ecc08358da2499e2634d9345eb711338f8630a61160ae38/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f646f746b65726e656c2f646f742d6c6f67)](https://github.com/dotkernel/dot-log/blob/5.0/LICENSE.md)

[![Build Static](https://github.com/dotkernel/dot-log/actions/workflows/continuous-integration.yml/badge.svg?branch=5.0)](https://github.com/dotkernel/dot-log/actions/workflows/continuous-integration.yml)[![codecov](https://camo.githubusercontent.com/79d05d61a3596d9ac0ee4a658f72c005117dfd055a13d61c759ed91b4f0f095d/68747470733a2f2f636f6465636f762e696f2f67682f646f746b65726e656c2f646f742d6c6f672f67726170682f62616467652e7376673f746f6b656e3d4a5831394b544252435a)](https://codecov.io/gh/dotkernel/dot-log)[![PHPStan](https://github.com/dotkernel/dot-log/actions/workflows/static-analysis.yml/badge.svg?branch=5.0)](https://github.com/dotkernel/dot-log/actions/workflows/static-analysis.yml)

Adding The Config Provider
--------------------------

[](#adding-the-config-provider)

- Enter config/config.php
- If there is no entry for the config provider below, add it: `\Dot\Log\ConfigProvider::class`
- Make sure it is added before with the Application-Specific components, e.g.: `\Frontend\App\ConfigProvider.php`, `\Admin\App\ConfigProvider::class`, `MyProject\ConfigProvider::class` , etc.
- Open the `Dot\Log\ConfigProvider`
- In the dependencies section you will see an abstract factory (`LoggerAbstractServiceFactory::class`)
- This class responds to "selectors" instead of class names Instead of requesting the `Dot\Log\Logger::class` from the container, `dot-log.my_logger` should be requested

Configuring the writer(s)
-------------------------

[](#configuring-the-writers)

Loggers must have at least one writer.

A writer is an object that inherits from `Dot\Log\Writer\AbstractWriter`. A writer's responsibility is to record log data to a storage backend.

### Writing to a file (stream)

[](#writing-to-a-file-stream)

It is possible to separate logs into multiple files using writers and filters. For example, *warnings.log*, *errors.log*, *all\_messages.log*.

The following is the simplest example to write all log messages to `/log/dk.log`

```
return [
    'dot_log' => [
        'loggers' => [
            'my_logger' => [
                'writers' => [
                     'FileWriter' => [
                        'name' => 'FileWriter',
                        'level'   => \Dot\Log\Logger::ALERT, // this is equal to 1
                        'options' => [
                            'stream' => __DIR__ . '/../../log/dk.log',
                        ],
                    ],
                ],
            ]
        ],
    ],
];
```

- The `FileWriter` key is optional, otherwise the writers array would be enumerative instead of associative.
- The writer name key is a developer-provided name for that writer, the writer name key is **mandatory**.

The writer level key is not affecting the errors that are written; it is a way to organize writers.

The writer level key is optional.

To write into a file, the key stream must be present in the writer options array. This is required only if writing into streams/files.

Grouping log files by date
--------------------------

[](#grouping-log-files-by-date)

By default, logs will be written to the same file: `log/dk.log`. Optionally, you can use date format specifiers wrapped between curly braces in your FileWriter's `stream` option, automatically grouping your logs by day, week, month, year, etc. Examples:

- `log/dk-{Y}-{m}-{d}.log` will write every day to a different file (eg: `log/dk-2021-01-01.log`)
- `log/dk-{Y}-{W}.log` will write every week to a different file (eg: `log/dk-2021-10.log`)

The full list of format specifiers is available in the [official documentation](https://www.php.net/manual/en/datetime.format.php).

Filtering log messages
----------------------

[](#filtering-log-messages)

As per PSR-3 document.

The log levels are: emergency (0), alert (1), critical (2), error (3), warn (4), notice (5), info (6), debug (7) (in order of level/importance)

The following example has three file writers using filters:

- First Example: `FileWriter` - All messages are logged in `/log/dk.log`
- Second Example: `OnlyWarningsWriter` - Only warnings are logged in `/log/warnings.log`
- Third Example: `WarningOrHigherWriter` - All important messages (`warnings` or more critical) are logged in `/log/important_messages.log`

```
