1
0
mirror of https://github.com/Seldaek/monolog.git synced 2025-08-05 20:57:36 +02:00
This commit is contained in:
Jordi Boggiano
2016-09-25 17:46:38 +02:00
parent 941c21b793
commit 96f4fd718f
15 changed files with 39 additions and 36 deletions

View File

@@ -40,7 +40,7 @@ class RollbarHandler extends AbstractProcessingHandler
*/ */
protected $rollbarNotifier; protected $rollbarNotifier;
protected $levelMap = array( protected $levelMap = [
Logger::DEBUG => 'debug', Logger::DEBUG => 'debug',
Logger::INFO => 'info', Logger::INFO => 'info',
Logger::NOTICE => 'info', Logger::NOTICE => 'info',
@@ -49,7 +49,7 @@ class RollbarHandler extends AbstractProcessingHandler
Logger::CRITICAL => 'critical', Logger::CRITICAL => 'critical',
Logger::ALERT => 'critical', Logger::ALERT => 'critical',
Logger::EMERGENCY => 'critical', Logger::EMERGENCY => 'critical',
); ];
/** /**
* Records whether any log records have been added since the last flush of the rollbar notifier * Records whether any log records have been added since the last flush of the rollbar notifier
@@ -76,17 +76,17 @@ class RollbarHandler extends AbstractProcessingHandler
protected function write(array $record) protected function write(array $record)
{ {
$context = $record['context']; $context = $record['context'];
$payload = array(); $payload = [];
if (isset($context['payload'])) { if (isset($context['payload'])) {
$payload = $context['payload']; $payload = $context['payload'];
unset($context['payload']); unset($context['payload']);
} }
$context = array_merge($context, $record['extra'], array( $context = array_merge($context, $record['extra'], [
'level' => $this->levelMap[$record['level']], 'level' => $this->levelMap[$record['level']],
'monolog_level' => $record['level_name'], 'monolog_level' => $record['level_name'],
'channel' => $record['channel'], 'channel' => $record['channel'],
'datetime' => $record['datetime']->format('U'), 'datetime' => $record['datetime']->format('U'),
)); ]);
if (isset($context['exception']) && $context['exception'] instanceof Exception) { if (isset($context['exception']) && $context['exception'] instanceof Exception) {
$exception = $context['exception']; $exception = $context['exception'];

View File

@@ -186,8 +186,8 @@ class Logger implements LoggerInterface
/** /**
* Pops a handler from the stack * Pops a handler from the stack
* *
* @throws \LogicException If empty handler stack
* @return HandlerInterface * @return HandlerInterface
* @throws \LogicException If empty handler stack
*/ */
public function popHandler(): HandlerInterface public function popHandler(): HandlerInterface
{ {
@@ -240,8 +240,8 @@ class Logger implements LoggerInterface
/** /**
* Removes the processor on top of the stack and returns it. * Removes the processor on top of the stack and returns it.
* *
* @throws \LogicException If empty processor stack
* @return callable * @return callable
* @throws \LogicException If empty processor stack
*/ */
public function popProcessor(): callable public function popProcessor(): callable
{ {
@@ -347,9 +347,9 @@ class Logger implements LoggerInterface
/** /**
* Gets the name of the logging level. * Gets the name of the logging level.
* *
* @param int $level * @param int $level
* @return string
* @throws \Psr\Log\InvalidArgumentException If level is not defined * @throws \Psr\Log\InvalidArgumentException If level is not defined
* @return string
*/ */
public static function getLevelName(int $level): string public static function getLevelName(int $level): string
{ {
@@ -364,8 +364,8 @@ class Logger implements LoggerInterface
* Converts PSR-3 levels to Monolog ones if necessary * Converts PSR-3 levels to Monolog ones if necessary
* *
* @param string|int Level number (monolog) or name (PSR-3) * @param string|int Level number (monolog) or name (PSR-3)
* @return int
* @throws \Psr\Log\InvalidArgumentException If level is not defined * @throws \Psr\Log\InvalidArgumentException If level is not defined
* @return int
*/ */
public static function toMonologLevel($level): int public static function toMonologLevel($level): int
{ {

View File

@@ -3,7 +3,7 @@
/* /*
* This file is part of the Monolog package. * This file is part of the Monolog package.
* *
* (c) Jonathan A. Schweder <jonathanschweder@gmail.com> * (c) Jordi Boggiano <j.boggiano@seld.be>
* *
* For the full copyright and license information, please view the LICENSE * For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code. * file that was distributed with this source code.
@@ -51,9 +51,10 @@ class MercurialProcessor
} }
$result = explode(' ', trim(`hg id -nb`)); $result = explode(' ', trim(`hg id -nb`));
return self::$cache = array(
return self::$cache = [
'branch' => $result[1], 'branch' => $result[1],
'revision' => $result[2], 'revision' => $result[2],
); ];
} }
} }

View File

@@ -125,21 +125,22 @@ class JsonFormatterTest extends TestCase
} }
/** /**
* @param JsonFormatter $formatter * @param JsonFormatter $formatter
* @param \Exception|\Throwable $exception * @param \Exception|\Throwable $exception
* *
* @return string * @return string
*/ */
private function formatRecordWithExceptionInContext(JsonFormatter $formatter, $exception) private function formatRecordWithExceptionInContext(JsonFormatter $formatter, $exception)
{ {
$message = $formatter->format(array( $message = $formatter->format([
'level_name' => 'CRITICAL', 'level_name' => 'CRITICAL',
'channel' => 'core', 'channel' => 'core',
'context' => array('exception' => $exception), 'context' => ['exception' => $exception],
'datetime' => null, 'datetime' => null,
'extra' => array(), 'extra' => [],
'message' => 'foobar', 'message' => 'foobar',
)); ]);
return $message; return $message;
} }

View File

@@ -93,14 +93,14 @@ class NormalizerFormatterTest extends \PHPUnit_Framework_TestCase
$formatter = new NormalizerFormatter('Y-m-d'); $formatter = new NormalizerFormatter('Y-m-d');
$e = new \SoapFault('foo', 'bar', 'hello', 'world'); $e = new \SoapFault('foo', 'bar', 'hello', 'world');
$formatted = $formatter->format(array( $formatted = $formatter->format([
'exception' => $e, 'exception' => $e,
)); ]);
unset($formatted['exception']['trace']); unset($formatted['exception']['trace']);
$this->assertEquals(array( $this->assertEquals([
'exception' => array( 'exception' => [
'class' => 'SoapFault', 'class' => 'SoapFault',
'message' => 'bar', 'message' => 'bar',
'code' => 0, 'code' => 0,
@@ -108,8 +108,8 @@ class NormalizerFormatterTest extends \PHPUnit_Framework_TestCase
'faultcode' => 'foo', 'faultcode' => 'foo',
'faultactor' => 'hello', 'faultactor' => 'hello',
'detail' => 'world', 'detail' => 'world',
), ],
), $formatted); ], $formatted);
} }
public function testFormatToStringExceptionHandle() public function testFormatToStringExceptionHandle()

View File

@@ -68,7 +68,7 @@ class FlowdockHandlerTest extends TestCase
->setMethods(['fsockopen', 'streamSetTimeout', 'closeSocket']) ->setMethods(['fsockopen', 'streamSetTimeout', 'closeSocket'])
->getMock(); ->getMock();
$reflectionProperty = new \ReflectionProperty('\Monolog\Handler\SocketHandler', 'connectionString'); $reflectionProperty = new \ReflectionProperty('Monolog\Handler\SocketHandler', 'connectionString');
$reflectionProperty->setAccessible(true); $reflectionProperty->setAccessible(true);
$reflectionProperty->setValue($this->handler, 'localhost:1234'); $reflectionProperty->setValue($this->handler, 'localhost:1234');

View File

@@ -209,7 +209,7 @@ class HipChatHandlerTest extends TestCase
->setMethods(['fsockopen', 'streamSetTimeout', 'closeSocket']) ->setMethods(['fsockopen', 'streamSetTimeout', 'closeSocket'])
->getMock(); ->getMock();
$reflectionProperty = new \ReflectionProperty('\Monolog\Handler\SocketHandler', 'connectionString'); $reflectionProperty = new \ReflectionProperty('Monolog\Handler\SocketHandler', 'connectionString');
$reflectionProperty->setAccessible(true); $reflectionProperty->setAccessible(true);
$reflectionProperty->setValue($this->handler, 'localhost:1234'); $reflectionProperty->setValue($this->handler, 'localhost:1234');

View File

@@ -66,7 +66,7 @@ class LogEntriesHandlerTest extends TestCase
->setMethods(['fsockopen', 'streamSetTimeout', 'closeSocket']) ->setMethods(['fsockopen', 'streamSetTimeout', 'closeSocket'])
->getMock(); ->getMock();
$reflectionProperty = new \ReflectionProperty('\Monolog\Handler\SocketHandler', 'connectionString'); $reflectionProperty = new \ReflectionProperty('Monolog\Handler\SocketHandler', 'connectionString');
$reflectionProperty->setAccessible(true); $reflectionProperty->setAccessible(true);
$reflectionProperty->setValue($this->handler, 'localhost:1234'); $reflectionProperty->setValue($this->handler, 'localhost:1234');

View File

@@ -66,7 +66,7 @@ class LogmaticHandlerTest extends TestCase
->setMethods(['fsockopen', 'streamSetTimeout', 'closeSocket']) ->setMethods(['fsockopen', 'streamSetTimeout', 'closeSocket'])
->getMock(); ->getMock();
$reflectionProperty = new \ReflectionProperty('\Monolog\Handler\SocketHandler', 'connectionString'); $reflectionProperty = new \ReflectionProperty('Monolog\Handler\SocketHandler', 'connectionString');
$reflectionProperty->setAccessible(true); $reflectionProperty->setAccessible(true);
$reflectionProperty->setValue($this->handler, 'localhost:1234'); $reflectionProperty->setValue($this->handler, 'localhost:1234');

View File

@@ -121,7 +121,7 @@ class PushoverHandlerTest extends TestCase
->setMethods(['fsockopen', 'streamSetTimeout', 'closeSocket']) ->setMethods(['fsockopen', 'streamSetTimeout', 'closeSocket'])
->getMock(); ->getMock();
$reflectionProperty = new \ReflectionProperty('\Monolog\Handler\SocketHandler', 'connectionString'); $reflectionProperty = new \ReflectionProperty('Monolog\Handler\SocketHandler', 'connectionString');
$reflectionProperty->setAccessible(true); $reflectionProperty->setAccessible(true);
$reflectionProperty->setValue($this->handler, 'localhost:1234'); $reflectionProperty->setValue($this->handler, 'localhost:1234');

View File

@@ -170,7 +170,7 @@ class RotatingFileHandlerTest extends TestCase
['Y-m-', false], ['Y-m-', false],
['Y--', false], ['Y--', false],
['m-d', false], ['m-d', false],
['Y-d', false] ['Y-d', false],
]; ];
} }

View File

@@ -131,7 +131,7 @@ class SlackHandlerTest extends TestCase
->setMethods(['fsockopen', 'streamSetTimeout', 'closeSocket']) ->setMethods(['fsockopen', 'streamSetTimeout', 'closeSocket'])
->getMock(); ->getMock();
$reflectionProperty = new \ReflectionProperty('\Monolog\Handler\SocketHandler', 'connectionString'); $reflectionProperty = new \ReflectionProperty('Monolog\Handler\SocketHandler', 'connectionString');
$reflectionProperty->setAccessible(true); $reflectionProperty->setAccessible(true);
$reflectionProperty->setValue($this->handler, 'localhost:1234'); $reflectionProperty->setValue($this->handler, 'localhost:1234');

View File

@@ -31,7 +31,7 @@ class SyslogUdpHandlerTest extends TestCase
$handler = new SyslogUdpHandler("127.0.0.1", 514, "authpriv"); $handler = new SyslogUdpHandler("127.0.0.1", 514, "authpriv");
$handler->setFormatter(new \Monolog\Formatter\ChromePHPFormatter()); $handler->setFormatter(new \Monolog\Formatter\ChromePHPFormatter());
$socket = $this->getMockBuilder('\Monolog\Handler\SyslogUdp\UdpSocket') $socket = $this->getMockBuilder('Monolog\Handler\SyslogUdp\UdpSocket')
->setMethods(['write']) ->setMethods(['write'])
->setConstructorArgs(['lol', 'lol']) ->setConstructorArgs(['lol', 'lol'])
->getMock(); ->getMock();
@@ -52,7 +52,7 @@ class SyslogUdpHandlerTest extends TestCase
$handler = new SyslogUdpHandler("127.0.0.1", 514, "authpriv"); $handler = new SyslogUdpHandler("127.0.0.1", 514, "authpriv");
$handler->setFormatter($this->getIdentityFormatter()); $handler->setFormatter($this->getIdentityFormatter());
$socket = $this->getMockBuilder('\Monolog\Handler\SyslogUdp\UdpSocket') $socket = $this->getMockBuilder('Monolog\Handler\SyslogUdp\UdpSocket')
->setMethods(['write']) ->setMethods(['write'])
->setConstructorArgs(['lol', 'lol']) ->setConstructorArgs(['lol', 'lol'])
->getMock(); ->getMock();

View File

@@ -21,7 +21,7 @@ class UdpSocketTest extends TestCase
{ {
public function testWeDoNotTruncateShortMessages() public function testWeDoNotTruncateShortMessages()
{ {
$socket = $this->getMockBuilder('\Monolog\Handler\SyslogUdp\UdpSocket') $socket = $this->getMockBuilder('Monolog\Handler\SyslogUdp\UdpSocket')
->setMethods(['send']) ->setMethods(['send'])
->setConstructorArgs(['lol', 'lol']) ->setConstructorArgs(['lol', 'lol'])
->getMock(); ->getMock();
@@ -35,7 +35,7 @@ class UdpSocketTest extends TestCase
public function testLongMessagesAreTruncated() public function testLongMessagesAreTruncated()
{ {
$socket = $this->getMockBuilder('\Monolog\Handler\SyslogUdp\UdpSocket') $socket = $this->getMockBuilder('Monolog\Handler\SyslogUdp\UdpSocket')
->setMethods(['send']) ->setMethods(['send'])
->setConstructorArgs(['lol', 'lol']) ->setConstructorArgs(['lol', 'lol'])
->getMock(); ->getMock();

View File

@@ -3,7 +3,7 @@
/* /*
* This file is part of the Monolog package. * This file is part of the Monolog package.
* *
* (c) Jonathan A. Schweder <jonathanschweder@gmail.com> * (c) Jordi Boggiano <j.boggiano@seld.be>
* *
* For the full copyright and license information, please view the LICENSE * For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code. * file that was distributed with this source code.
@@ -27,6 +27,7 @@ class MercurialProcessorTest extends TestCase
} }
if ($result != 0) { if ($result != 0) {
$this->markTestSkipped('hg is missing'); $this->markTestSkipped('hg is missing');
return; return;
} }