Giter Club home page Giter Club logo

yii2-log's Introduction

yii2-log

Build Status Latest Stable Version Dependency Status Scrutinizer Quality Score Code Coverage Total Downloads License

Different Yii2 log transports

Now available

  • ElasticsearchTarget
  • LogstashFileTarget
  • LogstashTarget
  • RedisTarget

Installation

The preferred way to install this extension is through composer.

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

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

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

Extends yii\log\Target, more options see here

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

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

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

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

yii2-log's People

Contributors

index0h avatar xt99 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

yii2-log's Issues

TargetTrait don't parse Exception Message as @message when it parseText

If we want to gather Log information in some target (ie LogStash) we lost the message and it will not be exported.

Because on TargetTrait the parseText method will call get_object_vars() on $text when it's an instance of Exception. Unfortunately default Exception use protected attributes and we lost the default Exception message at this step.

We can do something like this :

case 'object':
                $vars = get_object_vars($text);
                if ($text instanceof \Exception) {
                    $vars['@message'] = $text->getMessage();
                }

                return $vars;

But I don't think it's the best manner to handle it.

Composer Yii version

Привязка к Yii 2.0.0 является критичной?
Есть ли возможность указать гибкую версию? (например ">=2.0.0")

Спасибо за полезный плагин.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.