2011-02-24 21:05:08 +00:00
< ? php
/*
* This file is part of the Symfony package .
*
2011-03-17 18:15:16 +00:00
* ( c ) Fabien Potencier < fabien @ symfony . com >
2011-02-24 21:05:08 +00:00
*
* For the full copyright and license information , please view the LICENSE
* file that was distributed with this source code .
*/
2011-05-07 09:35:19 +01:00
namespace Symfony\Bridge\Monolog ;
2011-02-24 21:05:08 +00:00
use Monolog\Logger as BaseLogger ;
2017-07-29 01:08:59 +01:00
use Symfony\Component\HttpFoundation\Request ;
2011-02-24 21:05:08 +00:00
use Symfony\Component\HttpKernel\Log\DebugLoggerInterface ;
2018-07-13 18:06:58 +01:00
use Symfony\Contracts\Service\ResetInterface ;
2011-02-24 21:05:08 +00:00
/**
2011-03-17 18:15:16 +00:00
* @ author Fabien Potencier < fabien @ symfony . com >
2011-02-24 21:05:08 +00:00
*/
2018-04-29 15:58:54 +01:00
class Logger extends BaseLogger implements DebugLoggerInterface , ResetInterface
2011-02-24 21:05:08 +00:00
{
2011-05-31 06:59:30 +01:00
/**
2014-12-21 16:36:15 +00:00
* { @ inheritdoc }
2011-05-31 06:59:30 +01:00
*/
2017-07-29 01:08:59 +01:00
public function getLogs ( /* Request $request = null */ )
2011-05-31 06:59:30 +01:00
{
2018-08-29 10:05:16 +01:00
if ( \func_num_args () < 1 && __CLASS__ !== \get_class ( $this ) && __CLASS__ !== ( new \ReflectionMethod ( $this , __FUNCTION__ )) -> getDeclaringClass () -> getName () && ! $this instanceof \PHPUnit\Framework\MockObject\MockObject && ! $this instanceof \Prophecy\Prophecy\ProphecySubjectInterface ) {
@ trigger_error ( sprintf ( 'The "%s()" method will have a new "Request $request = null" argument in version 5.0, not defining it is deprecated since Symfony 4.2.' , __METHOD__ ), E_USER_DEPRECATED );
}
2011-05-31 06:59:30 +01:00
if ( $logger = $this -> getDebugLogger ()) {
2018-09-11 08:26:54 +01:00
return $logger -> getLogs ( ... \func_get_args ());
2011-05-31 06:59:30 +01:00
}
2013-05-14 18:40:35 +01:00
return array ();
2011-05-31 06:59:30 +01:00
}
/**
2014-12-21 16:36:15 +00:00
* { @ inheritdoc }
2011-05-31 06:59:30 +01:00
*/
2017-07-29 01:08:59 +01:00
public function countErrors ( /* Request $request = null */ )
2011-05-31 06:59:30 +01:00
{
2018-08-29 10:05:16 +01:00
if ( \func_num_args () < 1 && __CLASS__ !== \get_class ( $this ) && __CLASS__ !== ( new \ReflectionMethod ( $this , __FUNCTION__ )) -> getDeclaringClass () -> getName () && ! $this instanceof \PHPUnit\Framework\MockObject\MockObject && ! $this instanceof \Prophecy\Prophecy\ProphecySubjectInterface ) {
@ trigger_error ( sprintf ( 'The "%s()" method will have a new "Request $request = null" argument in version 5.0, not defining it is deprecated since Symfony 4.2.' , __METHOD__ ), E_USER_DEPRECATED );
}
2011-05-31 06:59:30 +01:00
if ( $logger = $this -> getDebugLogger ()) {
2018-09-11 08:26:54 +01:00
return $logger -> countErrors ( ... \func_get_args ());
2011-05-31 06:59:30 +01:00
}
2013-05-14 18:40:35 +01:00
return 0 ;
2011-05-31 06:59:30 +01:00
}
2017-10-05 10:48:08 +01:00
/**
* { @ inheritdoc }
*/
public function clear ()
{
2017-10-10 11:58:54 +01:00
if ( $logger = $this -> getDebugLogger ()) {
2017-10-05 10:48:08 +01:00
$logger -> clear ();
}
}
2018-04-29 15:58:54 +01:00
/**
* { @ inheritdoc }
*/
public function reset ()
{
$this -> clear ();
}
2011-02-24 21:05:08 +00:00
/**
* Returns a DebugLoggerInterface instance if one is registered with this logger .
*
2013-05-14 18:40:35 +01:00
* @ return DebugLoggerInterface | null A DebugLoggerInterface instance or null if none is registered
2011-02-24 21:05:08 +00:00
*/
2011-05-31 06:59:30 +01:00
private function getDebugLogger ()
2011-02-24 21:05:08 +00:00
{
2016-11-04 20:47:40 +00:00
foreach ( $this -> processors as $processor ) {
if ( $processor instanceof DebugLoggerInterface ) {
return $processor ;
}
}
2011-02-25 21:20:16 +00:00
foreach ( $this -> handlers as $handler ) {
2011-02-24 21:05:08 +00:00
if ( $handler instanceof DebugLoggerInterface ) {
return $handler ;
}
}
}
}