log() public method

If [[traceLevel]] is greater than 0, additional call stack information about the application code will be logged as well.
public log ( string | array $message, integer $level, string $category = 'application' )
$message string | array the message to be logged. This can be a simple string or a more complex data structure that will be handled by a [[Target|log target]].
$level integer the level of the message. This must be one of the following: `Logger::LEVEL_ERROR`, `Logger::LEVEL_WARNING`, `Logger::LEVEL_INFO`, `Logger::LEVEL_TRACE`, `Logger::LEVEL_PROFILE_BEGIN`, `Logger::LEVEL_PROFILE_END`.
$category string the category of the message.
コード例 #1
0
ファイル: LoggerTest.php プロジェクト: howq/yii2
 public function testLog()
 {
     $logger = new Logger();
     $logger->log('test1', Logger::LEVEL_INFO);
     $this->assertEquals(1, count($logger->messages));
     $this->assertEquals('test1', $logger->messages[0][0]);
     $this->assertEquals(Logger::LEVEL_INFO, $logger->messages[0][1]);
     $this->assertEquals('application', $logger->messages[0][2]);
     $logger->log('test2', Logger::LEVEL_ERROR, 'category');
     $this->assertEquals(2, count($logger->messages));
     $this->assertEquals('test2', $logger->messages[1][0]);
     $this->assertEquals(Logger::LEVEL_ERROR, $logger->messages[1][1]);
     $this->assertEquals('category', $logger->messages[1][2]);
 }
コード例 #2
0
ファイル: FileTargetTest.php プロジェクト: howq/yii2
 /**
  * @dataProvider booleanDataProvider
  */
 public function testRotate($rotateByCopy)
 {
     $logFile = Yii::getAlias('@yiiunit/runtime/log/filetargettest.log');
     FileHelper::removeDirectory(dirname($logFile));
     mkdir(dirname($logFile), 0777, true);
     $logger = new Logger();
     $dispatcher = new Dispatcher(['logger' => $logger, 'targets' => ['file' => ['class' => 'yii\\log\\FileTarget', 'logFile' => $logFile, 'levels' => ['warning'], 'maxFileSize' => 1024, 'maxLogFiles' => 1, 'logVars' => [], 'rotateByCopy' => $rotateByCopy]]]);
     // one file
     $logger->log(str_repeat('x', 1024), Logger::LEVEL_WARNING);
     $logger->flush(true);
     clearstatcache();
     $this->assertTrue(file_exists($logFile));
     $this->assertFalse(file_exists($logFile . '.1'));
     $this->assertFalse(file_exists($logFile . '.2'));
     $this->assertFalse(file_exists($logFile . '.3'));
     $this->assertFalse(file_exists($logFile . '.4'));
     // exceed max size
     for ($i = 0; $i < 1024; $i++) {
         $logger->log(str_repeat('x', 1024), Logger::LEVEL_WARNING);
     }
     $logger->flush(true);
     // first rotate
     $logger->log(str_repeat('x', 1024), Logger::LEVEL_WARNING);
     $logger->flush(true);
     clearstatcache();
     $this->assertTrue(file_exists($logFile));
     $this->assertTrue(file_exists($logFile . '.1'));
     $this->assertFalse(file_exists($logFile . '.2'));
     $this->assertFalse(file_exists($logFile . '.3'));
     $this->assertFalse(file_exists($logFile . '.4'));
     // second rotate
     for ($i = 0; $i < 1024; $i++) {
         $logger->log(str_repeat('x', 1024), Logger::LEVEL_WARNING);
     }
     $logger->flush(true);
     clearstatcache();
     $this->assertTrue(file_exists($logFile));
     $this->assertTrue(file_exists($logFile . '.1'));
     $this->assertFalse(file_exists($logFile . '.2'));
     $this->assertFalse(file_exists($logFile . '.3'));
     $this->assertFalse(file_exists($logFile . '.4'));
 }
コード例 #3
0
 public function log($message, $level, $category = 'application')
 {
     $mougrimLoggerLevel = $this->getMougrimPhpLoggerLevel($level);
     if ($mougrimLoggerLevel !== null) {
         $this->getMougrimLogger($category)->log($mougrimLoggerLevel, $message);
         if (!$this->getAlwaysYiiLoggerLog()) {
             return;
         }
     }
     parent::log($message, $level, $category);
 }
コード例 #4
0
ファイル: Logger.php プロジェクト: hiqdev/hidev
 /**
  * Logs a message to console and then to yii\log\Logger.
  */
 public function log($message, $level, $category = 'application')
 {
     if ($level <= $this->getSpamLevel()) {
         $style = self::$styles[$level];
         if ($style) {
             $message = Console::ansiFormat($message, $style);
         }
         Console::stdout($message . "\n");
     }
     parent::log($message, $level, $category);
 }
コード例 #5
0
ファイル: TargetTest.php プロジェクト: howq/yii2
 /**
  * @dataProvider filters
  */
 public function testFilter($filter, $expected)
 {
     static::$messages = [];
     $logger = new Logger();
     $dispatcher = new Dispatcher(['logger' => $logger, 'targets' => [new TestTarget(array_merge($filter, ['logVars' => []]))], 'flushInterval' => 1]);
     $logger->log('testA', Logger::LEVEL_INFO);
     $logger->log('testB', Logger::LEVEL_ERROR);
     $logger->log('testC', Logger::LEVEL_WARNING);
     $logger->log('testD', Logger::LEVEL_TRACE);
     $logger->log('testE', Logger::LEVEL_INFO, 'application');
     $logger->log('testF', Logger::LEVEL_INFO, 'application.components.Test');
     $logger->log('testG', Logger::LEVEL_ERROR, 'yii.db.Command');
     $logger->log('testH', Logger::LEVEL_ERROR, 'yii.db.Command.whatever');
     $this->assertEquals(count($expected), count(static::$messages));
     $i = 0;
     foreach ($expected as $e) {
         $this->assertEquals('test' . $e, static::$messages[$i++][0]);
     }
 }