PHPackages                             index0h/yii2-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. index0h/yii2-log

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

index0h/yii2-log
================

Many Yii2 log targets

0.0.3(10y ago)49204.5k↓28.8%13[4 issues](https://github.com/index0h/yii2-log/issues)MITPHPPHP &gt;=5.4.0

Since Feb 11Pushed 10y ago6 watchersCompare

[ Source](https://github.com/index0h/yii2-log)[ Packagist](https://packagist.org/packages/index0h/yii2-log)[ Docs](https://github.com/index0h/yii2-log)[ RSS](/packages/index0h-yii2-log/feed)WikiDiscussions master Synced 1mo ago

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

yii2-log
========

[](#yii2-log)

[![Build Status](https://camo.githubusercontent.com/32f8526138b083a16c182637806a4ac9cfde3f963fa53453e47165fae2c5a451/68747470733a2f2f7472617669732d63692e6f72672f696e64657830682f796969322d6c6f672e706e673f6272616e63683d6d6173746572)](https://travis-ci.org/index0h/yii2-log) [![Latest Stable Version](https://camo.githubusercontent.com/93b05253826ccc75f22922050a29c2ee457b836b26020fb816d4358a5c2192b3/68747470733a2f2f706f7365722e707567782e6f72672f696e64657830682f796969322d6c6f672f762f737461626c652e706e67)](https://packagist.org/packages/index0h/yii2-log) [![Dependency Status](https://camo.githubusercontent.com/4a131cca3aee9d39a668ed8dedea7ebb8b3f202dce979e9022dbe0d3b4b245ad/68747470733a2f2f67656d6e617369756d2e636f6d2f696e64657830682f796969322d6c6f672e706e67)](https://gemnasium.com/index0h/yii2-log) [![Scrutinizer Quality Score](https://camo.githubusercontent.com/c03ead194660e79dfb813dff68705389305b4fa727dea33c0edbd6cb5905eb96/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f696e64657830682f796969322d6c6f672f6261646765732f7175616c6974792d73636f72652e706e673f733d33303565653463383237613739316162323738393537393964326333663363653935353365613531)](https://scrutinizer-ci.com/g/index0h/yii2-log/) [![Code Coverage](https://camo.githubusercontent.com/d879099786327a293b7ba409eee89f2260345e97dd1ebe85d03fd3ce43c00fd2/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f696e64657830682f796969322d6c6f672f6261646765732f636f7665726167652e706e673f733d32356531373564323138353239623766666130613266333963623932303465356234383136383433)](https://scrutinizer-ci.com/g/index0h/yii2-log/) [![Total Downloads](https://camo.githubusercontent.com/f44ef6aa053337e0223363bc5eb40e1f9d8afae52932856e123899b757e2f5c6/68747470733a2f2f706f7365722e707567782e6f72672f696e64657830682f796969322d6c6f672f646f776e6c6f6164732e706e67)](https://packagist.org/packages/index0h/yii2-log) [![License](https://camo.githubusercontent.com/d7f908582039c0c78e60765bc0210daa231a0e3f4609fd20f2ff5d45cb55608d/68747470733a2f2f706f7365722e707567782e6f72672f696e64657830682f796969322d6c6f672f6c6963656e73652e706e67)](https://packagist.org/packages/index0h/yii2-log)

Different Yii2 log transports

Now available
-------------

[](#now-available)

- ElasticsearchTarget
- LogstashFileTarget
- LogstashTarget
- RedisTarget

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

[](#installation)

The preferred way to install this extension is through [composer](http://getcomposer.org/download/).

```
php composer.phar require --prefer-dist index0h/yii2-log "0.0.3"
```

or add line to require section of `composer.json`

```
"index0h/yii2-log": "0.0.3"
```

Usage
-----

[](#usage)

### Common properties

[](#common-properties)

- `$emergencyLogFile`, default `@app/logs/logService.log`

Elasticsearch, Redis and Logstash - are external services, so if they down our logs must be stored in file. For that **ElasticsearchTarget**, **LogstashTarget**, **RedisTarget** have option `$emergencyLogFile`. It's alias to file where logs will be written on log service is down.

### ElasticsearchTarget

[](#elasticsearchtarget)

Stores logs in elasticsearch. All logs transform to json, so you can simply watch them by [kibana](http://www.elasticsearch.org/overview/kibana/).

Extends yii\\log\\Target, more options see [here](https://github.com/yiisoft/yii2/blob/master/framework/log/Target.php)

##### Example configuration

[](#example-configuration)

```
....
'components' => [
    'log' => [
        'targets' => [
            ['class' => 'index0h\\log\\ElasticsearchTarget'],
        ....
```

##### Properties

[](#properties)

- `index`, default 'yii' - Elasticsearch index name.
- `type`, default 'log' - Elasticsearch index type.
- `componentName` - Name of yii redis component.

### LogstashFileTarget

[](#logstashfiletarget)

Extends yii\\log\\FileTarget, more options see [here](https://github.com/yiisoft/yii2/blob/master/framework/log/FileTarget.php)

##### Example Yii configuration

[](#example-yii-configuration)

```
....
'components' => [
    'log' => [
        'targets' => [
            ['class' => 'index0h\\log\\LogstashFileTarget'],
        ....
```

##### Example Logstash configuration [(current version 1.3.3)](http://logstash.net/docs/1.3.3/)

[](#example-logstash-configuration-current-version-133)

```
input {
  file {
    type => "yii_log"
    path => [ "path/to/yii/logs/*.log*" ]
    start_position => "end"
    stat_interval => 1
    discover_interval => 30
    codec => "json"
  }
}

filter {
  # ...
}

output {
  stdout => {}
}

```

### LogstashTarget

[](#logstashtarget)

Extends yii\\log\\Target, more options see [here](https://github.com/yiisoft/yii2/blob/master/framework/log/Target.php)

##### Example Yii configuration

[](#example-yii-configuration-1)

```
....
'components' => [
    'log' => [
        'targets' => [
            ['class' => 'index0h\\log\\LogstashTarget'],
            // Or UDP.
            [
                'class' => 'index0h\\log\\LogstashTarget',
                'dsn' => 'udp://localhost:3333'
            ],
            // Or unix socket file.
            [
                'class' => 'index0h\\log\\LogstashTarget',
                'dsn' => 'unix:///path/to/logstash.sock'
            ],
        ....
```

##### Example Logstash configuration [(current version 1.3.3)](http://logstash.net/docs/1.3.3/)

[](#example-logstash-configuration-current-version-133-1)

```
input {
  tcp {
    type => "yii_log"
    port => 3333
    codec => "json"
  }
  # Or UDP.
  udp {
    type => "yii_log"
    port => 3333
    codec => "json"
  }
  # Or unix socket file.
  unix {
    type => "yii_log"
    path => "path/to/logstash.sock"
    codec => "json"
  }
}

filter {
  # ...
}

output {
  stdout => {}
}

```

##### Properties

[](#properties-1)

- `dsn`, default `tcp://localhost:3333` - URL to logstash service. Allowed schemas: **tcp**, **udp**, **unix** - for unix sock files.

### RedisTarget

[](#redistarget)

Extends yii\\log\\Target, more options see [here](https://github.com/yiisoft/yii2/blob/master/framework/log/Target.php)

##### Example Yii configuration

[](#example-yii-configuration-2)

```
....
'components' => [
    'log' => [
        'targets' => [
            ['class' => 'index0h\\log\\RedisTarget'],
        ....
```

##### Example Logstash configuration [(current version 1.3.3)](http://logstash.net/docs/1.3.3/)

[](#example-logstash-configuration-current-version-133-2)

```
input {
  redis {
    type => "yii_log"
    key => "yii_log"
    codec => "json"
  }
}

filter {
  # ...
}

output {
  stdout => {}
}

```

##### Properties

[](#properties-2)

- `key`, default `yii_log` - Redis list key.
- `componentName` - Name of yii redis component.

Testing
-------

[](#testing)

#### Run tests from IDE (example for PhpStorm)

[](#run-tests-from-ide-example-for-phpstorm)

- Select Run/Debug Configuration -&gt; Edit Configurations
- Select Add New Configuration -&gt; PHP Script
- Type:
    - File: /path/to/yii-phar/.test.php
    - Arguments run: run --coverage --html
- OK

#### Run tests from console

[](#run-tests-from-console)

```
make test
```

---

#### Thanks to

[](#thanks-to)

[@achretien](https://github.com/achretien)[@Archy812](https://github.com/Archy812)[@xt99](https://github.com/xt99)

###  Health Score

36

—

LowBetter than 82% of packages

Maintenance18

Infrequent updates — may be unmaintained

Popularity46

Moderate usage in the ecosystem

Community16

Small or concentrated contributor base

Maturity50

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 97.5% 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 ~233 days

Total

3

Last Release

4012d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/7b8a28fe7485e2e7c7e42ebd15c4bd6da4f56dcc307c29f52f9b1d08b656ab78?d=identicon)[index0h](/maintainers/index0h)

---

Top Contributors

[![index0h](https://avatars.githubusercontent.com/u/675070?v=4)](https://github.com/index0h "index0h (39 commits)")[![xt99](https://avatars.githubusercontent.com/u/608600?v=4)](https://github.com/xt99 "xt99 (1 commits)")

---

Tags

logelasticsearchredisyii2logstashlog-targetyii2-log

###  Code Quality

TestsCodeception

### Embed Badge

![Health badge](/badges/index0h-yii2-log/health.svg)

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

PHPackages © 2026

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