Coder Social home page Coder Social logo

yii2-compact-file-target's Introduction

CompactFileTarget

Ignores traces in FileTarget log.

Even if traceLevel is set greater than 0, the trace data will not be written to a log file.

This is needed to have more clean logs on development environment.

Installation

The preferred way to install this extension is through composer.

Either run

php composer.phar require --prefer-dist roslov/yii2-compact-file-target "*"

or add

"roslov/yii2-compact-file-target": "*"

to the require section of your composer.json file.

Usage

Once the extension is installed, simply use it in your code by :

Let’s imagine you have such configuration:

return [
    'bootstrap' => ['log'],
    'components' => [
        'log' => [
            'targets' => [
                [
                    'class' => 'yii\log\FileTarget',
                    'levels' => ['info'],
                    'categories' => ['analytics'],
                    'logVars' => [],
                ],
            ],
        ],
    ],
];

After Yii::info($text, 'analytics'); your log will have such output:

2017-10-30 12:11:41 [172.18.0.1][43][-][info][analytics] User 123 updated.
    in /var/www/html/components/analytics/Analytics.php:110
    in /var/www/html/components/analytics/Analytics.php:75
    in /var/www/html/modules/api/v2/behaviors/EventTracker.php:40
2017-10-30 12:11:42 [172.18.0.1][43][-][info][analytics] Notification sent to user 123.
    in /var/www/html/components/analytics/Analytics.php:110
    in /var/www/html/components/analytics/Analytics.php:75
    in /var/www/html/modules/api/v2/behaviors/ActivityTracker.php:85
2017-10-30 12:11:55 [172.18.0.1][43][-][info][analytics] User 456 logged out.
    in /var/www/html/components/analytics/Analytics.php:110
    in /var/www/html/components/analytics/Analytics.php:41
    in /var/www/html/modules/api/v2/behaviors/ActivityTracker.php:57

For just logging events you may not need any trace information.

So you can change class from yii\log\FileTarget to roslov\log\CompactFileTarget:

return [
    'bootstrap' => ['log'],
    'components' => [
        'log' => [
            'targets' => [
                [
                    'class' => 'roslov\log\CompactFileTarget',
                    'levels' => ['info'],
                    'categories' => ['analytics'],
                    'logVars' => [],
                ],
            ],
        ],
    ],
];

In this case the log will look more clean.

2017-10-30 12:11:41 [172.18.0.1][43][-][info][analytics] User 123 updated.
2017-10-30 12:11:42 [172.18.0.1][43][-][info][analytics] Notification sent to user 123.
2017-10-30 12:11:55 [172.18.0.1][43][-][info][analytics] User 456 logged out.

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.