Neos\Flow\Log\Logger::log PHP Метод

log() публичный Метод

Writes the given message along with the additional information into the log.
public log ( string $message, integer $severity = LOG_INFO, mixed $additionalData = null, string $packageKey = null, string $className = null, string $methodName = null ) : void
$message string The message to log
$severity integer An integer value, one of the LOG_* constants
$additionalData mixed A variable containing more information about the event to be logged
$packageKey string Key of the package triggering the log (determined automatically if not specified)
$className string Name of the class triggering the log (determined automatically if not specified)
$methodName string Name of the method triggering the log (determined automatically if not specified)
Результат void
    public function log($message, $severity = LOG_INFO, $additionalData = null, $packageKey = null, $className = null, $methodName = null)
    {
        if ($packageKey === null) {
            $backtrace = debug_backtrace(false);
            $className = isset($backtrace[1]['class']) ? $backtrace[1]['class'] : null;
            $methodName = isset($backtrace[1]['function']) ? $backtrace[1]['function'] : null;
            $explodedClassName = explode('\\', $className);
            // FIXME: This is not really the package key:
            $packageKey = isset($explodedClassName[1]) ? $explodedClassName[1] : '';
        }
        foreach ($this->backends as $backend) {
            $backend->append($message, $severity, $additionalData, $packageKey, $className, $methodName);
        }
    }

Usage Example

 /**
  * @test
  */
 public function removeBackendRunsTheBackendsCloseMethodAndRemovesItFromTheLogger()
 {
     $mockBackend = $this->getMockBuilder(BackendInterface::class)->setMethods(['open', 'append', 'close'])->getMock();
     $mockBackend->expects($this->once())->method('close');
     $mockBackend->expects($this->once())->method('append');
     $logger = new Logger();
     $logger->addBackend($mockBackend);
     $logger->log('theMessage', 2, ['foo'], 'Foo', 'Bar', 'Baz');
     $logger->removeBackend($mockBackend);
     $logger->log('theMessage', 2, ['foo'], 'Foo', 'Bar', 'Baz');
 }