PHPackages                             silinternational/yii2-json-log-targets - 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. silinternational/yii2-json-log-targets

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

silinternational/yii2-json-log-targets
======================================

A collection of Yii2 log targets that format the log message as a JSON string.

2.3.1(6mo ago)6132.2k↓10.6%12MITPHPPHP &gt;=7.0CI passing

Since Jul 12Pushed 1mo ago5 watchersCompare

[ Source](https://github.com/sil-org/yii2-json-log-targets)[ Packagist](https://packagist.org/packages/silinternational/yii2-json-log-targets)[ RSS](/packages/silinternational-yii2-json-log-targets/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (10)Dependencies (6)Versions (14)Used By (2)

Yii2 JSON Log Targets
=====================

[](#yii2-json-log-targets)

A collection of Yii2 log targets that format the log message as a JSON string.

Usage
-----

[](#usage)

### EmailServiceTarget

[](#emailservicetarget)

The EmailServiceTarget is used to send logs to the email endpoint in [ID Broker](https://github.com/sil-org/idp-id-broker).

Note, this target can throw an exception that should be excluded in the target configuration to ensure a looping event is avoided. The exception is `Sil\Idp\IdBroker\Client\EmailServiceClientException`.

As part of a Yii2 app configuration:

```
    'log' => [
        'targets' => [
            [
                'class' => 'Sil\JsonLog\target\EmailServiceTarget',
                'levels' => ['error'],
                'except' => [
                    'Sil\Idp\IdBroker\Client\EmailServiceClientException',
                ],
                'logVars' => [], // Disable logging of _SERVER, _POST, etc.
                'message' => [
                    'to' => 'alerts@mydomain.com',
                    'cc' => 'noc@mydomain.com',         // optional
                    'bcc' => 'bcc@mydomain.com',     // optional
                    'subject' => 'Alert from application',
                ],
                'baseUrl' => 'https://emailservice.mydomain.com',
                'accessToken' => 'asdf1234',
                'assertValidIp' => true,
                'validIpRanges' => ['10.0.10.0/24','127.0.0.1'],
                'enabled' => true,
            ],
        ],
    ],
```

### JsonFileTarget

[](#jsonfiletarget)

The JsonFileTarget is just like the standard FileTarget except it accepts an array of data in the message and formats it as json before writing to a file.

As part of a Yii2 app configuration:

```
    'log' => [
        'targets' => [
            [
                'class' => 'Sil\JsonLog\target\JsonFileTarget',
                'levels' => ['error', 'warning'],
                'logVars' => [], // Disable logging of _SERVER, _POST, etc.
            ],
        ],
    ],
```

### JsonSyslogTarget

[](#jsonsyslogtarget)

The JsonSyslogTarget is just like the standard SyslogTarget except it accepts an array of data in the message and formats it as json before sending to Syslog.

As part of a Yii2 app configuration:

```
    'log' => [
        'targets' => [
            [
                'class' => 'Sil\JsonLog\target\JsonSyslogTarget',
                'levels' => ['error', 'warning'],
                'except' => [
                    'yii\web\HttpException:401',
                    'yii\web\HttpException:404',
                ],
                'logVars' => [], // Disable logging of _SERVER, _POST, etc.
            ],
        ],
    ],
```

Tips
----

[](#tips)

### Have the log prefix (if used) return JSON

[](#have-the-log-prefix-if-used-return-json)

Example (to be placed into your Yii2 config file's `['components']['log']['targets']` array):

```
[
    'class' => 'Sil\JsonLog\target\JsonFileTarget',
    'levels' => ['error', 'warning'],
    'except' => [
        'yii\web\HttpException:401',
        'yii\web\HttpException:404',
    ],
    'logVars' => [], // Disable logging of _SERVER, _POST, etc.
    'prefix' => function($message) use ($appEnv) {
        $prefixData = [
            'env' => $appEnv,
        ];
        if ( ! \Yii::$app->user->isGuest) {
            $prefixData['user'] = \Yii::$app->user->identity->email;
        }
        return \yii\helpers\Json::encode($prefixData);
    },
],

```

### If using syslog to send to Logentries, only send the JSON content

[](#if-using-syslog-to-send-to-logentries-only-send-the-json-content)

Make sure that the template you define for Logentries in your rsyslog.conf file does not add other content before the `%msg%` data (aside from your Logentries key). For example, do something like this...

```
$template Logentries,"LOGENTRIESKEY %msg%\n"

```

... NOT like this...

```
$template Logentries,"LOGENTRIESKEY %HOSTNAME% %syslogtag%%msg%\n"

```

License
-------

[](#license)

This is released under the MIT license (see LICENSE file).

###  Health Score

54

—

FairBetter than 97% of packages

Maintenance79

Regular maintenance activity

Popularity38

Limited adoption so far

Community24

Small or concentrated contributor base

Maturity65

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

Recently: every ~287 days

Total

13

Last Release

206d ago

Major Versions

0.3.2 → 1.0.02017-08-29

1.1.0 → 2.0.02020-05-13

PHP version history (2 changes)0.1.0PHP &gt;=5.6

2.3.0PHP &gt;=7.0

### Community

Maintainers

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

![](https://www.gravatar.com/avatar/836739aa4f60c754dc9a4a547ebd0c166e4b6e855d9f119df2be5aec92f3a375?d=identicon)[forevermatt](/maintainers/forevermatt)

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

![](https://www.gravatar.com/avatar/5256eacae3564eb6d3e954abc6552ed99a6d948d94d2b07cc1dc9dabb0bce108?d=identicon)[jason-jackson](/maintainers/jason-jackson)

---

Top Contributors

[![fillup](https://avatars.githubusercontent.com/u/556105?v=4)](https://github.com/fillup "fillup (28 commits)")[![forevermatt](https://avatars.githubusercontent.com/u/6233204?v=4)](https://github.com/forevermatt "forevermatt (24 commits)")[![briskt](https://avatars.githubusercontent.com/u/3172830?v=4)](https://github.com/briskt "briskt (22 commits)")[![jason-jackson](https://avatars.githubusercontent.com/u/35783387?v=4)](https://github.com/jason-jackson "jason-jackson (11 commits)")[![mtompset](https://avatars.githubusercontent.com/u/10937901?v=4)](https://github.com/mtompset "mtompset (4 commits)")[![Baggerone](https://avatars.githubusercontent.com/u/8058522?v=4)](https://github.com/Baggerone "Baggerone (3 commits)")[![devon-sil](https://avatars.githubusercontent.com/u/122382412?v=4)](https://github.com/devon-sil "devon-sil (2 commits)")[![wapmorgan](https://avatars.githubusercontent.com/u/6000618?v=4)](https://github.com/wapmorgan "wapmorgan (1 commits)")

---

Tags

logjsonfileyii2targetsyslog

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/silinternational-yii2-json-log-targets/health.svg)

```
[![Health](https://phpackages.com/badges/silinternational-yii2-json-log-targets/health.svg)](https://phpackages.com/packages/silinternational-yii2-json-log-targets)
```

PHPackages © 2026

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