PHPackages                             samdark/yii2-psr-log-target - 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. samdark/yii2-psr-log-target

ActiveYii2-extension[Logging &amp; Monitoring](/categories/logging)

samdark/yii2-psr-log-target
===========================

Yii 2 log target which uses PSR-3 compatible logger

1.1.4(2y ago)841.8M↓11%15[2 issues](https://github.com/samdark/yii2-psr-log-target/issues)[3 PRs](https://github.com/samdark/yii2-psr-log-target/pulls)9BSD-3-ClausePHPCI passing

Since Mar 8Pushed 5mo ago7 watchersCompare

[ Source](https://github.com/samdark/yii2-psr-log-target)[ Packagist](https://packagist.org/packages/samdark/yii2-psr-log-target)[ Docs](https://github.com/samdark/yii2-psr-log-target)[ GitHub Sponsors](https://github.com/samdark)[ Patreon](https://www.patreon.com/samdark)[ RSS](/packages/samdark-yii2-psr-log-target/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (3)Versions (16)Used By (9)

Yii 2 PSR Log Target
====================

[](#yii-2-psr-log-target)

Allows you to process logs using any PSR-3 compatible logger such as [Monolog](https://github.com/Seldaek/monolog).

[![Latest Stable Version](https://camo.githubusercontent.com/36ff69d71ddd8f53b5b7d6d12753e79bcb96251d247f2ad668bb1a8c2b745b50/68747470733a2f2f706f7365722e707567782e6f72672f73616d6461726b2f796969322d7073722d6c6f672d7461726765742f762f737461626c652e706e67)](https://packagist.org/packages/samdark/yii2-psr-log-target)[![Total Downloads](https://camo.githubusercontent.com/ccbf254c50b44f22f549dc1bfe50c880fa710590e211f8e79aa8a6e93f3efef5/68747470733a2f2f706f7365722e707567782e6f72672f73616d6461726b2f796969322d7073722d6c6f672d7461726765742f646f776e6c6f6164732e706e67)](https://packagist.org/packages/samdark/yii2-psr-log-target)[![Build Status](https://github.com/samdark/yii2-psr-log-target/workflows/build/badge.svg)](https://github.com/samdark/yii2-psr-log-target/actions?query=workflow%3Abuild)[![Code Coverage](https://camo.githubusercontent.com/6e9e3dc1a0d5df3776e9381cc2e3cbc4aeddf0390723bd02e320e44345791f7c/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f73616d6461726b2f796969322d7073722d6c6f672d7461726765742f6261646765732f636f7665726167652e706e673f733d33316438306631303336303939653964366133653464373733386636623030306233633364313065)](https://scrutinizer-ci.com/g/samdark/yii2-psr-log-target)[![Scrutinizer Quality Score](https://camo.githubusercontent.com/15ffa29eb06b0bee769742d80a7eab216246926dea89fed86a2abc82402ee03d/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f73616d6461726b2f796969322d7073722d6c6f672d7461726765742f6261646765732f7175616c6974792d73636f72652e706e673f733d62313037346131666636643062323134643534666135616237616262623930666330393234373164)](https://scrutinizer-ci.com/g/samdark/yii2-psr-log-target/)

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

[](#installation)

```
composer require "samdark/yii2-psr-log-target"

```

Usage
-----

[](#usage)

In order to use `PsrTarget` you should configure your `log` application component like the following:

```
// $psrLogger should be an instance of PSR-3 compatible logger.
// As an example, we'll use Monolog to send log to Slack.
$psrLogger = new \Monolog\Logger('my_logger');
$psrLogger->pushHandler(new \Monolog\Handler\SlackHandler('slack_token', 'logs', null, true, null, \Monolog\Logger::DEBUG));

return [
    // ...
    'bootstrap' => ['log'],
    // ...
    'components' => [
        // ...
        'log' => [
            'targets' => [
                [
                    'class' => 'samdark\log\PsrTarget',
                    'logger' => $psrLogger,

                    // It is optional parameter. The message levels that this target is interested in.
                    // The parameter can be an array.
                    'levels' => ['info', yii\log\Logger::LEVEL_WARNING, Psr\Log\LogLevel::CRITICAL],
                    // It is optional parameter. Default value is false. If you use Yii log buffering, you see buffer write time, and not real timestamp.
                    // If you want write real time to logs, you can set addTimestampToContext as true and use timestamp from log event context.
                    'addTimestampToContext' => true,
                ],
                // ...
            ],
        ],
    ],
];
```

Standard usage:

```
Yii::info('Info message');
Yii::error('Error message');
```

Usage with PSR logger levels:

```
Yii::getLogger()->log('Critical message', Psr\Log\LogLevel::CRITICAL);
Yii::getLogger()->log('Alert message', Psr\Log\LogLevel::ALERT);
```

Usage with original timestamp from context in the log:

```
// $psrLogger should be an instance of PSR-3 compatible logger.
// As an example, we'll use Monolog to send log to Slack.
$psrLogger = new \Monolog\Logger('my_logger');

$psrLogger->pushProcessor(function($record) {
    if (isset($record['context']['timestamp'])) {
        $dateTime = DateTime::createFromFormat('U.u', $record['context']['timestamp']);
        $timeZone = $record['datetime']->getTimezone();
        $dateTime->setTimezone($timeZone);
        $record['datetime'] = $dateTime;

        unset($record['context']['timestamp']);
    }

    return $record;
});
```

You can use PsrMessage instead of regular string messages to add custom context.

Standard usage:

```
Yii::error(new \samdark\log\PsrMessage("Critical message", [
    'custom' => 'context',
    'key' => 'value',
]));
```

Usage with PSR logger Levels:

```
Yii::getLogger()->log(new \samdark\log\PsrMessage("Critical message", [
    'important' => 'context'
]), Psr\Log\LogLevel::CRITICAL);
```

Usage with PSR-3 log message processing:

```
$psrLogger = new \Monolog\Logger('my_logger');
$psrLogger->pushProcessor(new \Monolog\Processor\PsrLogMessageProcessor());
```

```
Yii::debug(new \samdark\log\PsrMessage("Greetings from {fruit}", [
    'fruit' => 'banana'
]));
```

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

[](#running-tests)

In order to run tests perform the following commands:

```
composer install
./vendor/bin/phpunit

```

###  Health Score

55

—

FairBetter than 98% of packages

Maintenance49

Moderate activity, may be stable

Popularity55

Moderate usage in the ecosystem

Community31

Small or concentrated contributor base

Maturity71

Established project with proven stability

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

Recently: every ~410 days

Total

13

Last Release

907d ago

### Community

Maintainers

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

---

Top Contributors

[![samdark](https://avatars.githubusercontent.com/u/47294?v=4)](https://github.com/samdark "samdark (13 commits)")[![ilyaplot](https://avatars.githubusercontent.com/u/641257?v=4)](https://github.com/ilyaplot "ilyaplot (4 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (3 commits)")[![mrodikov](https://avatars.githubusercontent.com/u/6941044?v=4)](https://github.com/mrodikov "mrodikov (1 commits)")[![patrick-yi-82](https://avatars.githubusercontent.com/u/2878951?v=4)](https://github.com/patrick-yi-82 "patrick-yi-82 (1 commits)")[![rodion-k](https://avatars.githubusercontent.com/u/2526460?v=4)](https://github.com/rodion-k "rodion-k (1 commits)")[![terabytesoftw](https://avatars.githubusercontent.com/u/42547589?v=4)](https://github.com/terabytesoftw "terabytesoftw (1 commits)")[![arturf](https://avatars.githubusercontent.com/u/987128?v=4)](https://github.com/arturf "arturf (1 commits)")[![versh23](https://avatars.githubusercontent.com/u/1758392?v=4)](https://github.com/versh23 "versh23 (1 commits)")[![de-salvatierra](https://avatars.githubusercontent.com/u/5816848?v=4)](https://github.com/de-salvatierra "de-salvatierra (1 commits)")[![gusiushub](https://avatars.githubusercontent.com/u/35463405?v=4)](https://github.com/gusiushub "gusiushub (1 commits)")

---

Tags

logloggerloggingpsr-3yii2yii2-extensionlogpsr-3extensionyii

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/samdark-yii2-psr-log-target/health.svg)

```
[![Health](https://phpackages.com/badges/samdark-yii2-psr-log-target/health.svg)](https://phpackages.com/packages/samdark-yii2-psr-log-target)
```

###  Alternatives

[elastic/ecs-logging

Format and enrich your log files in the elastic common schema

21907.5k1](/packages/elastic-ecs-logging)[markrogoyski/simplelog-php

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

2818.1k4](/packages/markrogoyski-simplelog-php)[opengento/module-webapi-logger

This module allows you to analyze all the webapi rest done call toward your Magento.

1014.9k](/packages/opengento-module-webapi-logger)

PHPackages © 2026

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