Skip to content

Commit ca3813e

Browse files
committed
Merge remote-tracking branch 'nicolas-grekas/anon' into 1.x
2 parents a03084c + 9117a6c commit ca3813e

7 files changed

+32
-13
lines changed

src/Monolog/ErrorHandler.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use Psr\Log\LoggerInterface;
1515
use Psr\Log\LogLevel;
1616
use Monolog\Handler\AbstractHandler;
17+
use Monolog\Registry;
1718

1819
/**
1920
* Monolog error handler
@@ -133,7 +134,7 @@ public function handleException($e)
133134
{
134135
$this->logger->log(
135136
$this->uncaughtExceptionLevel === null ? LogLevel::ERROR : $this->uncaughtExceptionLevel,
136-
sprintf('Uncaught Exception %s: "%s" at %s line %s', get_class($e), $e->getMessage(), $e->getFile(), $e->getLine()),
137+
sprintf('Uncaught Exception %s: "%s" at %s line %s', Registry::getClass($e), $e->getMessage(), $e->getFile(), $e->getLine()),
137138
array('exception' => $e)
138139
);
139140

src/Monolog/Formatter/JsonFormatter.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Monolog\Formatter;
1313

1414
use Exception;
15+
use Monolog\Registry;
1516
use Throwable;
1617

1718
/**
@@ -179,11 +180,11 @@ protected function normalizeException($e)
179180
{
180181
// TODO 2.0 only check for Throwable
181182
if (!$e instanceof Exception && !$e instanceof Throwable) {
182-
throw new \InvalidArgumentException('Exception/Throwable expected, got '.gettype($e).' / '.get_class($e));
183+
throw new \InvalidArgumentException('Exception/Throwable expected, got '.gettype($e).' / '.Registry::getClass($e));
183184
}
184185

185186
$data = array(
186-
'class' => get_class($e),
187+
'class' => Registry::getClass($e),
187188
'message' => $e->getMessage(),
188189
'code' => $e->getCode(),
189190
'file' => $e->getFile().':'.$e->getLine(),

src/Monolog/Formatter/LineFormatter.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111

1212
namespace Monolog\Formatter;
1313

14+
use Monolog\Registry;
15+
1416
/**
1517
* Formats incoming records into a one-line string
1618
*
@@ -129,17 +131,17 @@ protected function normalizeException($e)
129131
{
130132
// TODO 2.0 only check for Throwable
131133
if (!$e instanceof \Exception && !$e instanceof \Throwable) {
132-
throw new \InvalidArgumentException('Exception/Throwable expected, got '.gettype($e).' / '.get_class($e));
134+
throw new \InvalidArgumentException('Exception/Throwable expected, got '.gettype($e).' / '.Registry::getClass($e));
133135
}
134136

135137
$previousText = '';
136138
if ($previous = $e->getPrevious()) {
137139
do {
138-
$previousText .= ', '.get_class($previous).'(code: '.$previous->getCode().'): '.$previous->getMessage().' at '.$previous->getFile().':'.$previous->getLine();
140+
$previousText .= ', '.Registry::getClass($previous).'(code: '.$previous->getCode().'): '.$previous->getMessage().' at '.$previous->getFile().':'.$previous->getLine();
139141
} while ($previous = $previous->getPrevious());
140142
}
141143

142-
$str = '[object] ('.get_class($e).'(code: '.$e->getCode().'): '.$e->getMessage().' at '.$e->getFile().':'.$e->getLine().$previousText.')';
144+
$str = '[object] ('.Registry::getClass($e).'(code: '.$e->getCode().'): '.$e->getMessage().' at '.$e->getFile().':'.$e->getLine().$previousText.')';
143145
if ($this->includeStacktraces) {
144146
$str .= "\n[stacktrace]\n".$e->getTraceAsString()."\n";
145147
}

src/Monolog/Formatter/MongoDBFormatter.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111

1212
namespace Monolog\Formatter;
1313

14+
use Monolog\Registry;
15+
1416
/**
1517
* Formats a record for use with the MongoDBHandler.
1618
*
@@ -75,15 +77,15 @@ protected function formatArray(array $record, $nestingLevel = 0)
7577
protected function formatObject($value, $nestingLevel)
7678
{
7779
$objectVars = get_object_vars($value);
78-
$objectVars['class'] = get_class($value);
80+
$objectVars['class'] = Registry::getClass($value);
7981

8082
return $this->formatArray($objectVars, $nestingLevel);
8183
}
8284

8385
protected function formatException(\Exception $exception, $nestingLevel)
8486
{
8587
$formattedException = array(
86-
'class' => get_class($exception),
88+
'class' => Registry::getClass($exception),
8789
'message' => $exception->getMessage(),
8890
'code' => $exception->getCode(),
8991
'file' => $exception->getFile() . ':' . $exception->getLine(),

src/Monolog/Formatter/NormalizerFormatter.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Monolog\Formatter;
1313

1414
use Exception;
15+
use Monolog\Registry;
1516

1617
/**
1718
* Normalizes incoming records to remove objects/resources so it's easier to dump to various targets
@@ -108,7 +109,7 @@ protected function normalize($data, $depth = 0)
108109
$value = $this->toJson($data, true);
109110
}
110111

111-
return sprintf("[object] (%s: %s)", get_class($data), $value);
112+
return sprintf("[object] (%s: %s)", Registry::getClass($data), $value);
112113
}
113114

114115
if (is_resource($data)) {
@@ -122,11 +123,11 @@ protected function normalizeException($e)
122123
{
123124
// TODO 2.0 only check for Throwable
124125
if (!$e instanceof Exception && !$e instanceof \Throwable) {
125-
throw new \InvalidArgumentException('Exception/Throwable expected, got '.gettype($e).' / '.get_class($e));
126+
throw new \InvalidArgumentException('Exception/Throwable expected, got '.gettype($e).' / '.Registry::getClass($e));
126127
}
127128

128129
$data = array(
129-
'class' => get_class($e),
130+
'class' => Registry::getClass($e),
130131
'message' => $e->getMessage(),
131132
'code' => $e->getCode(),
132133
'file' => $e->getFile().':'.$e->getLine(),
@@ -159,7 +160,7 @@ protected function normalizeException($e)
159160
// as a class name to avoid any unexpected leak of sensitive information
160161
$frame['args'] = array_map(function ($arg) {
161162
if (is_object($arg) && !($arg instanceof \DateTime || $arg instanceof \DateTimeInterface)) {
162-
return sprintf("[object] (%s)", get_class($arg));
163+
return sprintf("[object] (%s)", Registry::getClass($arg));
163164
}
164165

165166
return $arg;

src/Monolog/Processor/PsrLogMessageProcessor.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111

1212
namespace Monolog\Processor;
1313

14+
use Monolog\Registry;
15+
1416
/**
1517
* Processes a record's message according to PSR-3 rules
1618
*
@@ -35,7 +37,7 @@ public function __invoke(array $record)
3537
if (is_null($val) || is_scalar($val) || (is_object($val) && method_exists($val, "__toString"))) {
3638
$replacements['{'.$key.'}'] = $val;
3739
} elseif (is_object($val)) {
38-
$replacements['{'.$key.'}'] = '[object '.get_class($val).']';
40+
$replacements['{'.$key.'}'] = '[object '.Registry::getClass($val).']';
3941
} else {
4042
$replacements['{'.$key.'}'] = '['.gettype($val).']';
4143
}

src/Monolog/Registry.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,4 +131,14 @@ public static function __callStatic($name, $arguments)
131131
{
132132
return self::getInstance($name);
133133
}
134+
135+
/**
136+
* @internal
137+
*/
138+
public function getClass($object)
139+
{
140+
$class = \get_class($object);
141+
142+
return 'c' === $class[0] && 0 === strpos($class, "class@anonymous\0") ? get_parent_class($class).'@anonymous' : $class;
143+
}
134144
}

0 commit comments

Comments
 (0)