2017 © Pedro Peláez
 

yii2-extension yii2-log

Many Yii2 log targets

image

index0h/yii2-log

Many Yii2 log targets

  • Monday, May 25, 2015
  • by index0h
  • Repository
  • 7 Watchers
  • 44 Stars
  • 35,920 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 12 Forks
  • 4 Open issues
  • 4 Versions
  • 7 % Grown

The README.md

yii2-log

Build Status Latest Stable Version Dependency Status Scrutinizer Quality Score Code Coverage Total Downloads License, (*1)

Different Yii2 log transports, (*2)

Now available

  • ElasticsearchTarget
  • LogstashFileTarget
  • LogstashTarget
  • RedisTarget

Installation

The preferred way to install this extension is through composer., (*3)

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

or add line to require section of composer.json, (*4)

"index0h/yii2-log": "0.0.3"

Usage

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., (*5)

ElasticsearchTarget

Stores logs in elasticsearch. All logs transform to json, so you can simply watch them by kibana., (*6)

Extends yii\log\Target, more options see here, (*7)

Example configuration
....
'components' => [
    'log' => [
        'targets' => [
            ['class' => 'index0h\\log\\ElasticsearchTarget'],
        ....
Properties
  • index, default 'yii' - Elasticsearch index name.
  • type, default 'log' - Elasticsearch index type.
  • componentName - Name of yii redis component.

LogstashFileTarget

Extends yii\log\FileTarget, more options see here, (*8)

Example Yii configuration
....
'components' => [
    'log' => [
        'targets' => [
            ['class' => 'index0h\\log\\LogstashFileTarget'],
        ....
Example Logstash configuration (current version 1.3.3)
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

Extends yii\log\Target, more options see here, (*9)

Example Yii configuration
....
'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)
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
  • dsn, default tcp://localhost:3333 - URL to logstash service. Allowed schemas: tcp, udp, unix - for unix sock files.

RedisTarget

Extends yii\log\Target, more options see here, (*10)

Example Yii configuration
....
'components' => [
    'log' => [
        'targets' => [
            ['class' => 'index0h\\log\\RedisTarget'],
        ....
Example Logstash configuration (current version 1.3.3)
input {
  redis {
    type => "yii_log"
    key => "yii_log"
    codec => "json"
  }
}

filter {
  # ...
}

output {
  stdout => {}
}
Properties
  • key, default yii_log - Redis list key.
  • componentName - Name of yii redis component.

Testing

Run tests from IDE (example for PhpStorm)

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

Run tests from console

make test

Thanks to

@achretien @Archy812 @xt99, (*11)

The Versions

25/05 2015

dev-master

9999999-dev https://github.com/index0h/yii2-log

Many Yii2 log targets

  Sources   Download

MIT

The Requires

 

The Development Requires

log yii2 redis elasticsearch logstash log-target yii2-log

25/05 2015

0.0.3

0.0.3.0 https://github.com/index0h/yii2-log

Many Yii2 log targets

  Sources   Download

MIT

The Requires

 

The Development Requires

log yii2 redis elasticsearch logstash log-target yii2-log

01/03 2014

0.0.2

0.0.2.0 https://github.com/index0h/yii2-log

Many Yii2 log targets

  Sources   Download

MIT

The Requires

 

The Development Requires

log yii2 redis elasticsearch logstash log-target yii2-log