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

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

gusgusius/yii2-psr-log-target
=============================

Yii 2 log target which uses PSR-3 compatible logger

03[1 PRs](https://github.com/gusiushub/testlog/pulls)PHP

Since Nov 13Pushed 2y ago1 watchersCompare

[ Source](https://github.com/gusiushub/testlog)[ Packagist](https://packagist.org/packages/gusgusius/yii2-psr-log-target)[ RSS](/packages/gusgusius-yii2-psr-log-target/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependenciesVersions (2)Used By (0)

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

14

—

LowBetter than 2% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity3

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity22

Early-stage or recently created project

 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.

### Community

Maintainers

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

---

Top Contributors

[![gusiushub](https://avatars.githubusercontent.com/u/35463405?v=4)](https://github.com/gusiushub "gusiushub (1 commits)")

### Embed Badge

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

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

###  Alternatives

[psr/log

Common interface for logging libraries

10.4k1.2B9.2k](/packages/psr-log)[itsgoingd/clockwork

php dev tools in your browser

5.9k27.6M94](/packages/itsgoingd-clockwork)[graylog2/gelf-php

A php implementation to send log-messages to a GELF compatible backend like Graylog2.

41838.2M138](/packages/graylog2-gelf-php)[bugsnag/bugsnag-psr-logger

Official Bugsnag PHP PSR Logger.

32132.5M2](/packages/bugsnag-bugsnag-psr-logger)[consolidation/log

Improved Psr-3 / Psr\\Log logger based on Symfony Console components.

15462.2M7](/packages/consolidation-log)[datadog/php-datadogstatsd

An extremely simple PHP datadogstatsd client

19124.6M15](/packages/datadog-php-datadogstatsd)

PHPackages © 2026

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