1
0
mirror of https://github.com/Seldaek/monolog.git synced 2025-08-01 19:00:20 +02:00

Remove non-PSR-3 methods for adding log records

This commit is contained in:
Jordi Boggiano
2015-10-09 19:20:12 +01:00
parent 35ce15e098
commit 39f8a20e6d
4 changed files with 22 additions and 189 deletions

View File

@@ -3,3 +3,6 @@
- The timezone is now set per Logger instance and not statically, either - The timezone is now set per Logger instance and not statically, either
via ->setTimezone or passed in the constructor. Calls to Logger::setTimezone via ->setTimezone or passed in the constructor. Calls to Logger::setTimezone
should be converted. should be converted.
- Removed non-PSR-3 methods to add records, all the `add*` (e.g. `addWarning`)
methods as well as `emerg`, `crit`, `err` and `warn`.

View File

@@ -328,102 +328,6 @@ class Logger implements LoggerInterface
return true; return true;
} }
/**
* Adds a log record at the DEBUG level.
*
* @param string $message The log message
* @param array $context The log context
* @return Boolean Whether the record has been processed
*/
public function addDebug($message, array $context = array())
{
return $this->addRecord(static::DEBUG, $message, $context);
}
/**
* Adds a log record at the INFO level.
*
* @param string $message The log message
* @param array $context The log context
* @return Boolean Whether the record has been processed
*/
public function addInfo($message, array $context = array())
{
return $this->addRecord(static::INFO, $message, $context);
}
/**
* Adds a log record at the NOTICE level.
*
* @param string $message The log message
* @param array $context The log context
* @return Boolean Whether the record has been processed
*/
public function addNotice($message, array $context = array())
{
return $this->addRecord(static::NOTICE, $message, $context);
}
/**
* Adds a log record at the WARNING level.
*
* @param string $message The log message
* @param array $context The log context
* @return Boolean Whether the record has been processed
*/
public function addWarning($message, array $context = array())
{
return $this->addRecord(static::WARNING, $message, $context);
}
/**
* Adds a log record at the ERROR level.
*
* @param string $message The log message
* @param array $context The log context
* @return Boolean Whether the record has been processed
*/
public function addError($message, array $context = array())
{
return $this->addRecord(static::ERROR, $message, $context);
}
/**
* Adds a log record at the CRITICAL level.
*
* @param string $message The log message
* @param array $context The log context
* @return Boolean Whether the record has been processed
*/
public function addCritical($message, array $context = array())
{
return $this->addRecord(static::CRITICAL, $message, $context);
}
/**
* Adds a log record at the ALERT level.
*
* @param string $message The log message
* @param array $context The log context
* @return Boolean Whether the record has been processed
*/
public function addAlert($message, array $context = array())
{
return $this->addRecord(static::ALERT, $message, $context);
}
/**
* Adds a log record at the EMERGENCY level.
*
* @param string $message The log message
* @param array $context The log context
* @return Boolean Whether the record has been processed
*/
public function addEmergency($message, array $context = array())
{
return $this->addRecord(static::EMERGENCY, $message, $context);
}
/** /**
* Gets all supported logging levels. * Gets all supported logging levels.
* *
@@ -544,20 +448,6 @@ class Logger implements LoggerInterface
return $this->addRecord(static::NOTICE, $message, $context); return $this->addRecord(static::NOTICE, $message, $context);
} }
/**
* Adds a log record at the WARNING level.
*
* This method allows for compatibility with common interfaces.
*
* @param string $message The log message
* @param array $context The log context
* @return Boolean Whether the record has been processed
*/
public function warn($message, array $context = array())
{
return $this->addRecord(static::WARNING, $message, $context);
}
/** /**
* Adds a log record at the WARNING level. * Adds a log record at the WARNING level.
* *
@@ -572,20 +462,6 @@ class Logger implements LoggerInterface
return $this->addRecord(static::WARNING, $message, $context); return $this->addRecord(static::WARNING, $message, $context);
} }
/**
* Adds a log record at the ERROR level.
*
* This method allows for compatibility with common interfaces.
*
* @param string $message The log message
* @param array $context The log context
* @return Boolean Whether the record has been processed
*/
public function err($message, array $context = array())
{
return $this->addRecord(static::ERROR, $message, $context);
}
/** /**
* Adds a log record at the ERROR level. * Adds a log record at the ERROR level.
* *
@@ -600,20 +476,6 @@ class Logger implements LoggerInterface
return $this->addRecord(static::ERROR, $message, $context); return $this->addRecord(static::ERROR, $message, $context);
} }
/**
* Adds a log record at the CRITICAL level.
*
* This method allows for compatibility with common interfaces.
*
* @param string $message The log message
* @param array $context The log context
* @return Boolean Whether the record has been processed
*/
public function crit($message, array $context = array())
{
return $this->addRecord(static::CRITICAL, $message, $context);
}
/** /**
* Adds a log record at the CRITICAL level. * Adds a log record at the CRITICAL level.
* *
@@ -642,20 +504,6 @@ class Logger implements LoggerInterface
return $this->addRecord(static::ALERT, $message, $context); return $this->addRecord(static::ALERT, $message, $context);
} }
/**
* Adds a log record at the EMERGENCY level.
*
* This method allows for compatibility with common interfaces.
*
* @param string $message The log message
* @param array $context The log context
* @return Boolean Whether the record has been processed
*/
public function emerg($message, array $context = array())
{
return $this->addRecord(static::EMERGENCY, $message, $context);
}
/** /**
* Adds a log record at the EMERGENCY level. * Adds a log record at the EMERGENCY level.
* *

View File

@@ -121,7 +121,7 @@ class PHPConsoleHandlerTest extends TestCase
public function testDebug() public function testDebug()
{ {
$this->debugDispatcher->expects($this->once())->method('dispatchDebug')->with($this->equalTo('test')); $this->debugDispatcher->expects($this->once())->method('dispatchDebug')->with($this->equalTo('test'));
$this->initLogger()->addDebug('test'); $this->initLogger()->debug('test');
} }
public function testDebugContextInMessage() public function testDebugContextInMessage()
@@ -134,7 +134,7 @@ class PHPConsoleHandlerTest extends TestCase
$this->equalTo($expectedMessage), $this->equalTo($expectedMessage),
$this->equalTo($tag) $this->equalTo($tag)
); );
$this->initLogger()->addDebug($message, $context); $this->initLogger()->debug($message, $context);
} }
public function testDebugTags($tagsContextKeys = null) public function testDebugTags($tagsContextKeys = null)
@@ -151,7 +151,7 @@ class PHPConsoleHandlerTest extends TestCase
$this->equalTo($expectedTags) $this->equalTo($expectedTags)
); );
$this->connector->setDebugDispatcher($debugDispatcher); $this->connector->setDebugDispatcher($debugDispatcher);
$logger->addDebug('test', array($key => $expectedTags)); $logger->debug('test', array($key => $expectedTags));
} }
} }
@@ -198,7 +198,7 @@ class PHPConsoleHandlerTest extends TestCase
public function testOptionEnabled() public function testOptionEnabled()
{ {
$this->debugDispatcher->expects($this->never())->method('dispatchDebug'); $this->debugDispatcher->expects($this->never())->method('dispatchDebug');
$this->initLogger(array('enabled' => false))->addDebug('test'); $this->initLogger(array('enabled' => false))->debug('test');
} }
public function testOptionClassesPartialsTraceIgnore() public function testOptionClassesPartialsTraceIgnore()

View File

@@ -65,7 +65,7 @@ class LoggerTest extends \PHPUnit_Framework_TestCase
$logger = new Logger('foo'); $logger = new Logger('foo');
$handler = new TestHandler; $handler = new TestHandler;
$logger->pushHandler($handler); $logger->pushHandler($handler);
$logger->addWarning('test'); $logger->warning('test');
list($record) = $handler->getRecords(); list($record) = $handler->getRecords();
$this->assertEquals('foo', $record['channel']); $this->assertEquals('foo', $record['channel']);
} }
@@ -82,7 +82,7 @@ class LoggerTest extends \PHPUnit_Framework_TestCase
->method('handle'); ->method('handle');
$logger->pushHandler($handler); $logger->pushHandler($handler);
$this->assertTrue($logger->addWarning('test')); $this->assertTrue($logger->warning('test'));
} }
/** /**
@@ -97,7 +97,7 @@ class LoggerTest extends \PHPUnit_Framework_TestCase
->method('handle'); ->method('handle');
$logger->pushHandler($handler); $logger->pushHandler($handler);
$this->assertFalse($logger->addWarning('test')); $this->assertFalse($logger->warning('test'));
} }
public function testHandlersInCtor() public function testHandlersInCtor()
@@ -206,7 +206,7 @@ class LoggerTest extends \PHPUnit_Framework_TestCase
return $record; return $record;
}); });
$logger->addError('test'); $logger->error('test');
list($record) = $handler->getRecords(); list($record) = $handler->getRecords();
$this->assertTrue($record['extra']['win']); $this->assertTrue($record['extra']['win']);
} }
@@ -239,7 +239,7 @@ class LoggerTest extends \PHPUnit_Framework_TestCase
; ;
$logger->pushProcessor($processor); $logger->pushProcessor($processor);
$logger->addError('test'); $logger->error('test');
} }
/** /**
@@ -258,7 +258,7 @@ class LoggerTest extends \PHPUnit_Framework_TestCase
$logger->pushProcessor(function ($record) use ($that) { $logger->pushProcessor(function ($record) use ($that) {
$that->fail('The processor should not be called'); $that->fail('The processor should not be called');
}); });
$logger->addAlert('test'); $logger->alert('test');
} }
/** /**
@@ -433,22 +433,14 @@ class LoggerTest extends \PHPUnit_Framework_TestCase
/** /**
* @dataProvider logMethodProvider * @dataProvider logMethodProvider
* @covers Monolog\Logger::addDebug
* @covers Monolog\Logger::addInfo
* @covers Monolog\Logger::addNotice
* @covers Monolog\Logger::addWarning
* @covers Monolog\Logger::addError
* @covers Monolog\Logger::addCritical
* @covers Monolog\Logger::addAlert
* @covers Monolog\Logger::addEmergency
* @covers Monolog\Logger::debug * @covers Monolog\Logger::debug
* @covers Monolog\Logger::info * @covers Monolog\Logger::info
* @covers Monolog\Logger::notice * @covers Monolog\Logger::notice
* @covers Monolog\Logger::warn * @covers Monolog\Logger::warning
* @covers Monolog\Logger::err * @covers Monolog\Logger::error
* @covers Monolog\Logger::crit * @covers Monolog\Logger::critical
* @covers Monolog\Logger::alert * @covers Monolog\Logger::alert
* @covers Monolog\Logger::emerg * @covers Monolog\Logger::emergency
*/ */
public function testLogMethods($method, $expectedLevel) public function testLogMethods($method, $expectedLevel)
{ {
@@ -463,25 +455,15 @@ class LoggerTest extends \PHPUnit_Framework_TestCase
public function logMethodProvider() public function logMethodProvider()
{ {
return array( return array(
// monolog methods // PSR-3 methods
array('addDebug', Logger::DEBUG),
array('addInfo', Logger::INFO),
array('addNotice', Logger::NOTICE),
array('addWarning', Logger::WARNING),
array('addError', Logger::ERROR),
array('addCritical', Logger::CRITICAL),
array('addAlert', Logger::ALERT),
array('addEmergency', Logger::EMERGENCY),
// ZF/Sf2 compat methods
array('debug', Logger::DEBUG), array('debug', Logger::DEBUG),
array('info', Logger::INFO), array('info', Logger::INFO),
array('notice', Logger::NOTICE), array('notice', Logger::NOTICE),
array('warn', Logger::WARNING), array('warning', Logger::WARNING),
array('err', Logger::ERROR), array('error', Logger::ERROR),
array('crit', Logger::CRITICAL), array('critical', Logger::CRITICAL),
array('alert', Logger::ALERT), array('alert', Logger::ALERT),
array('emerg', Logger::EMERGENCY), array('emergency', Logger::EMERGENCY),
); );
} }