2017 © Pedro Peláez
 

yii2-extension yii2-compact-file-target

Ignores traces in FileTarget log.

image

roslov/yii2-compact-file-target

Ignores traces in FileTarget log.

  • Monday, October 30, 2017
  • by tr
  • Repository
  • 1 Watchers
  • 0 Stars
  • 184 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 2 Versions
  • 47 % Grown

The README.md

CompactFileTarget

Ignores traces in FileTarget log., (*1)

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

This is needed to have more clean logs on development environment., (*3)

Installation

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

Either run, (*5)

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

or add, (*6)

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

to the require section of your composer.json file., (*7)

Usage

Once the extension is installed, simply use it in your code by :, (*8)

Let’s imagine you have such configuration:, (*9)

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:, (*10)

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

So you can change class from yii\log\FileTarget to roslov\log\CompactFileTarget:, (*12)

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

In this case the log will look more clean., (*13)

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.

The Versions

30/10 2017

dev-master

9999999-dev

Ignores traces in FileTarget log.

  Sources   Download

BSD-3-Clause

The Requires

 

by Oleksandr Roslov

log extension yii2 filetarget

30/10 2017

0.1.0

0.1.0.0

Ignores traces in FileTarget log.

  Sources   Download

BSD-3-Clause

The Requires

 

by Oleksandr Roslov

log extension yii2 filetarget