A log target object will filter the messages logged by Logger according to its [[levels]] and [[categories]] properties. It may also export the filtered messages to specific destination defined by the target, such as emails, files. Level filter and category filter are combinatorial, i.e., only messages satisfying both filter conditions will be handled. Additionally, you may specify [[except]] to exclude messages of certain categories.
Since: 2.0
Author: Qiang Xue (qiang.xue@gmail.com)
Inheritance: extends yii\base\Component
Exemplo n.º 1
0
 /**
  * @inheritdoc
  */
 public function init()
 {
     parent::init();
     $this->stderrIsNotStdout = fstat(\STDERR)['dev'] != fstat(\STDOUT)['dev'];
     $this->stderrSupportsColors = Console::streamSupportsAnsiColors(\STDERR);
     $this->stdoutSupportsColors = Console::streamSupportsAnsiColors(\STDOUT);
 }
Exemplo n.º 2
0
 /**
  * {@inheritdoc}
  */
 public function export()
 {
     foreach ($this->messages as $message) {
         list($context, $level, $category, $timestamp, $traces) = $message;
         $extra = [];
         if ($context instanceof \Throwable || $context instanceof \Exception) {
             $this->client->captureException($context);
             $description = $context->getMessage();
         } elseif (isset($context['msg'])) {
             $description = $context['msg'];
             $extra = $context;
             unset($extra['msg']);
         } else {
             $description = $context;
         }
         if ($this->context) {
             $extra['context'] = parent::getContextMessage();
         }
         if (is_callable($this->extraCallback)) {
             $extra = call_user_func($this->extraCallback, $context, $extra);
         }
         $data = ['level' => static::getLevelName($level), 'timestamp' => $timestamp, 'message' => $description, 'extra' => $extra, 'tags' => ['category' => $category]];
         $this->client->capture($data, $traces);
     }
 }
Exemplo n.º 3
0
 /**
  * @inheritdoc
  */
 public function init()
 {
     parent::init();
     if ($this->options === null) {
         $this->options = LOG_ODELAY | LOG_PID;
     }
 }
Exemplo n.º 4
0
 /**
  * @inheritdoc
  */
 public function init()
 {
     parent::init();
     if (empty($this->message['to'])) {
         throw new InvalidConfigException('The "to" option must be set for EmailTarget::message.');
     }
     $this->mailer = Instance::ensure($this->mailer, 'yii\\mail\\MailerInterface');
 }
 /**
  * @inheritdoc
  */
 public function init()
 {
     parent::init();
     //assert proper config of formatLineCallback
     if ($this->formatLineCallback !== null && !$this->formatLineCallback instanceof \Closure) {
         $msg = Yii::t('app', 'formatLineCallback needs to be a closure');
         throw new InvalidConfigException($msg);
     }
 }
Exemplo n.º 6
0
 /**
  * @inheritdoc
  */
 public function init()
 {
     parent::init();
     // Make sure log token is given
     if (empty($this->logToken)) {
         $className = get_class($this);
         throw new InvalidCallException("{$className} requires \"\$logToken\" attribute to be set.");
     }
 }
Exemplo n.º 7
0
 /**
  * Check required properties
  */
 public function init()
 {
     parent::init();
     foreach (['botToken', 'chatId'] as $property) {
         if ($this->{$property} === null) {
             throw new InvalidConfigException(self::className() . "::\${$property} property must be set");
         }
     }
 }
Exemplo n.º 8
0
 /**
  * Initializes the DbTarget component.
  * This method will initialize the [[db]] property to make sure it refers to a valid DB connection.
  * @throws InvalidConfigException if [[db]] is invalid.
  */
 public function init()
 {
     parent::init();
     if (is_string($this->db)) {
         $this->db = Yii::$app->getComponent($this->db);
     }
     if (!$this->db instanceof Connection) {
         throw new InvalidConfigException("DbTarget::db must be either a DB connection instance or the application component ID of a DB connection.");
     }
 }
Exemplo n.º 9
0
 public function init()
 {
     $this->_stdoutIsTerminal = posix_isatty(\STDOUT);
     if ($this->_stdoutIsTerminal) {
         $this->logVars = [];
     }
     $this->_stdoutSupportsAnsiColors = Console::streamSupportsAnsiColors(\STDOUT);
     $this->_stderrIsTerminal = posix_isatty(\STDERR);
     $this->_stderrSupportsAnsiColors = Console::streamSupportsAnsiColors(\STDERR);
     $this->_levelAnsiColorMap = [Logger::LEVEL_ERROR => $this->errorAnsiColor, Logger::LEVEL_WARNING => $this->warningAnsiColor, Logger::LEVEL_INFO => $this->infoAnsiColor, Logger::LEVEL_TRACE => $this->traceAnsiColor, Logger::LEVEL_PROFILE => $this->profileAnsiColor, Logger::LEVEL_PROFILE_BEGIN => $this->profileBeginAnsiColor, Logger::LEVEL_PROFILE_END => $this->profileEndAnsiColor];
     parent::init();
 }
 /**
  * @inheritdoc
  */
 public function init()
 {
     parent::init();
     if (empty($this->message['to'])) {
         throw new InvalidConfigException('The "to" option must be set for EmailTarget::message.');
     }
     if (is_string($this->mail)) {
         $this->mail = Yii::$app->getComponent($this->mail);
     }
     if (!$this->mail instanceof MailerInterface) {
         throw new InvalidConfigException("EmailTarget::mailer must be either a mailer object or the application component ID of a mailer object.");
     }
 }
Exemplo n.º 11
0
 /**
  * Initializes the route.
  * This method is invoked after the route is created by the route manager.
  */
 public function init()
 {
     parent::init();
     if (!$this->webhookUrl) {
         $this->enabled = false;
     }
     if (!$this->username) {
         $this->username = Yii::$app->name;
     }
     // Not pushing Slackbot requests to slack.
     if (isset(Yii::$app->request->userAgent) && preg_match('/^Slackbot-/', Yii::$app->request->userAgent)) {
         $this->enabled = false;
     }
 }
Exemplo n.º 12
0
 /**
  * Filter all exceptions. They're logged via ErrorHandler
  * @inheritdoc
  */
 public static function filterMessages($messages, $levels = 0, $categories = [], $except = [])
 {
     $messages = parent::filterMessages($messages, $levels, $categories, $except);
     foreach ($messages as $i => $message) {
         $type = explode(':', $message[2]);
         // shutdown function not working in yii2 yet: https://github.com/yiisoft/yii2/issues/6637
         // allow fatal errors exceptions in log messages
         if (is_array($type) && sizeof($type) == 2 && $type[0] == 'yii\\base\\ErrorException' && ErrorException::isFatalError(['type' => $type[1]])) {
             continue;
         }
         if (is_string($message[0]) && strpos($message[0], 'exception \'') === 0) {
             unset($messages[$i]);
         }
     }
     return $messages;
 }
Exemplo n.º 13
0
 /**
  * Initializes the route.
  * This method is invoked after the route is created by the route manager.
  */
 public function init()
 {
     parent::init();
     if ($this->logFile === null) {
         $this->logFile = Yii::$app->getRuntimePath() . '/logs/app.log';
     } else {
         $this->logFile = Yii::getAlias($this->logFile);
     }
     $logPath = dirname($this->logFile);
     if (!is_dir($logPath)) {
         FileHelper::createDirectory($logPath, $this->dirMode, true);
     }
     if ($this->maxLogFiles < 1) {
         $this->maxLogFiles = 1;
     }
     if ($this->maxFileSize < 1) {
         $this->maxFileSize = 1;
     }
 }
Exemplo n.º 14
0
 /**
  * @inheritdoc
  */
 public function init()
 {
     parent::init();
     $this->_logger = FluentLogger::open($this->host, $this->port, $this->options);
 }
Exemplo n.º 15
0
 /**
  * @inheritdoc
  * @return string
  */
 protected function getContextMessage()
 {
     return $this->enableContextMassage ? parent::getContextMessage() : '';
 }
 /**
  * Ability to hide context message. See parent implementation for more details.
  * @return string
  */
 protected function getContextMessage()
 {
     return $this->includeContextMessage ? parent::getContextMessage() : '';
 }
Exemplo n.º 17
0
 /**
  * @param \yii\debug\Module $module
  * @param array $config
  */
 public function __construct($module, $config = [])
 {
     parent::__construct($config);
     $this->module = $module;
     $this->tag = uniqid();
 }
Exemplo n.º 18
0
 /**
  * @inheritdoc
  */
 public function init()
 {
     parent::init();
     $this->setLevels(Logger::LEVEL_PROFILE);
     $this->exportInterval = 1;
 }
Exemplo n.º 19
0
 /**
  * @inheritDoc
  */
 public function init()
 {
     parent::init();
     $this->httpClient = Instance::ensure($this->httpClient, Client::className());
 }
 /**
  * Initializes the route.
  * This method is invoked after the route is created by the route manager.
  */
 public function init()
 {
     $this->_fp = \FirePHP::getInstance(true);
     parent::init();
 }
Exemplo n.º 21
0
<?php

use yii\log\Target;
use yii\log\Logger;
?>

<?php 
$title = 'Logged ' . count($data['messages']) . ' messages';
$errorCount = count(Target::filterMessages($data['messages'], Logger::LEVEL_ERROR));
$warningCount = count(Target::filterMessages($data['messages'], Logger::LEVEL_WARNING));
$output = [];
if ($errorCount) {
    $output[] = "<span class=\"label label-important\">{$errorCount}</span>";
    $title .= ", {$errorCount} errors";
}
if ($warningCount) {
    $output[] = "<span class=\"label label-warning\">{$warningCount}</span>";
    $title .= ", {$warningCount} warnings";
}
?>

<div class="yii-debug-toolbar-block">
    <a href="<?php 
echo $panel->getUrl();
?>
" title="<?php 
echo $title;
?>
">Log
        <span class="label"><?php 
echo count($data['messages']);
Exemplo n.º 22
0
 /**
  * Initializes the DbTarget component.
  * This method will initialize the [[db]] property to make sure it refers to a valid DB connection.
  * @throws InvalidConfigException if [[db]] is invalid.
  */
 public function init()
 {
     parent::init();
     $this->db = Instance::ensure($this->db, Connection::className());
 }
Exemplo n.º 23
0
 /**
  * Initializes the route.
  * This method is invoked after the route is created by the route manager.
  */
 public function init()
 {
     parent::init();
 }
Exemplo n.º 24
0
 /**
  * {@inheritdoc}
  */
 public function init()
 {
     parent::init();
     $this->robot = Yii::createObject(['class' => Pubu::class, 'remote' => $this->channel]);
 }
Exemplo n.º 25
0
 /**
  * Initializes the DbTarget component.
  * This method will initialize the [[db]] property to make sure it refers to a valid DB connection.
  * @throws InvalidConfigException if [[db]] is invalid.
  */
 public function init()
 {
     parent::init();
     $this->client = new \Raven_Client($this->dsn);
 }
Exemplo n.º 26
0
 public function init()
 {
     $this->requestId = uniqid(gethostname(), true);
     parent::init();
 }