2017 © Pedro Peláez
 

library yii2-email-log-target

Yii2 log target for sending data to email without trace information

image

silinternational/yii2-email-log-target

Yii2 log target for sending data to email without trace information

  • Thursday, April 13, 2017
  • by fillup
  • Repository
  • 4 Watchers
  • 0 Stars
  • 1,260 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 1 Open issues
  • 2 Versions
  • 5 % Grown

The README.md

yii2-email-log-target

Custom version of yii\log\EmailTarget to exclude trace information from messages., (*1)

What & Why

The built in yii\log\EmailTarget class does a nice job of serializing and sending log and exception messages via email. Unfortunately when the message is an exception itself the exception is serialized to string using default\Exception::__toString() method which includes stack trace information. The Yii logger component allows configuration of whether or not to include trace information but it does not apply to exception messages., (*2)

This class is a modified version of yii\log\EmailTarget to ensure no trace information is set in the email., (*3)

Have the log prefix (if used)

Example configuration ['components']['log']['targets'] array):, (*4)

[
    'class' => 'Sil\Log\EmailTarget',
    'levels' => ['error'],
    'except' => [
        'yii\web\HttpException:401',
        'yii\web\HttpException:404',
    ],
    'logVars' => [], // Disable logging of _SERVER, _POST, etc.
    'prefix' => function($message) use ($appEnv) {
        $prefix = 'env=' . $appEnv . PHP_EOL;

        // There is no user when a console command is run
        try {
            $appUser = \Yii::$app->user;
        } catch (\Exception $e) {
            $appUser = Null;
        }
        if ($appUser && ! \Yii::$app->user->isGuest){
            $prefix .= 'user='.\Yii::$app->user->identity->email . PHP_EOL;
        }

        // Try to get requested url and method
        try {
            $request = \Yii::$app->request;
            $prefix .= 'Requested URL: ' . $request->getUrl() . PHP_EOL;
            $prefix .= 'Request method: ' . $request->getMethod() . PHP_EOL;
        } catch (\Exception $e) {
            $prefix .= 'Requested URL: not available';
        }

        return PHP_EOL . $prefix;
    },
],

License

This is released under the MIT license (see LICENSE file)., (*5)

The Versions

13/04 2017

dev-master

9999999-dev

Yii2 log target for sending data to email without trace information

  Sources   Download

MIT

The Requires

 

log email json yii2

13/04 2017

1.0.1

1.0.1.0

Yii2 log target for sending data to email without trace information

  Sources   Download

MIT

The Requires

 

log email json yii2