Phergie\Irc\Client\React\Client::getLogger PHP Method

getLogger() public method

Returns a stream instance for logging data on the socket connection.
public getLogger ( ) : Psr\Log\LoggerInterface
return Psr\Log\LoggerInterface
    public function getLogger()
    {
        if (!$this->logger) {
            // See testGetLoggerRunFromStdin
            // @codeCoverageIgnoreStart
            $stderr = defined('\\STDERR') && !is_null(\STDERR) ? \STDERR : fopen('php://stderr', 'w');
            // @codeCoverageIgnoreEnd
            $handler = new StreamHandler($stderr, Logger::DEBUG);
            $handler->setFormatter(new LineFormatter("%datetime% %level_name% %message% %context%\n"));
            $this->logger = new Logger(get_class($this));
            $this->logger->pushHandler($handler);
        }
        return $this->logger;
    }

Usage Example

コード例 #1
0
 /**
  * Tests addConnection() with a concrete write stream, where most other
  * tests have it mocked out.
  */
 public function testAddConnectionWithConcreteWriteStream()
 {
     $connection = $this->getMockConnectionForAddConnection();
     $logger = $this->client->getLogger();
     $logger->popHandler();
     $stream = fopen('php://memory', 'w+');
     $handler = new StreamHandler($stream, Logger::DEBUG);
     $handler->setFormatter(new LineFormatter("%message%\r\n"));
     $logger->pushHandler($handler);
     $this->client->setResolver($this->getMockResolver());
     $this->client->addConnection($connection);
     $mask = '[email protected]';
     $expected = "{$mask} PASS :password\r\n{$mask} USER username hostname servername :realname\r\n{$mask} NICK :nickname\r\n";
     fseek($stream, 0);
     $actual = stream_get_contents($stream);
     $this->assertSame($expected, $actual);
 }