33 $this->dateFormat =
$dateFormat ?: static::SIMPLE_DATE;
34 if (!function_exists(
'json_encode')) {
35 throw new \RuntimeException(
'PHP\'s json extension is required to use Monolog\'s NormalizerFormatter');
42 public function format(array $record)
52 foreach ($records as
$key => $record) {
62 return 'Over 9 levels deep, aborting normalization';
66 if (is_float(
$data)) {
67 if (is_infinite(
$data)) {
68 return (
$data > 0 ?
'' :
'-') .
'INF';
78 if (is_array(
$data)) {
79 $normalized = array();
83 if ($count++ > 1000) {
84 $normalized[
'...'] =
'Over 1000 items ('.count(
$data).
' total), aborting normalization';
95 return $data->format($this->dateFormat);
98 if (is_object(
$data)) {
106 $value =
$data->__toString();
115 if (is_resource(
$data)) {
116 return sprintf(
'[resource] (%s)', get_resource_type(
$data));
119 return '[unknown('.gettype(
$data).
')]';
126 throw new \InvalidArgumentException(
'Exception/Throwable expected, got '.gettype($e).
' / '.
Utils::getClass($e));
131 'message' => $e->getMessage(),
132 'code' => $e->getCode(),
133 'file' => $e->getFile().
':'.$e->getLine(),
136 if ($e instanceof \SoapFault) {
137 if (isset($e->faultcode)) {
138 $data[
'faultcode'] = $e->faultcode;
141 if (isset($e->faultactor)) {
142 $data[
'faultactor'] = $e->faultactor;
145 if (isset($e->detail)) {
146 $data[
'detail'] = $e->detail;
150 $trace = $e->getTrace();
151 foreach ($trace as $frame) {
152 if (isset($frame[
'file'])) {
153 $data[
'trace'][] = $frame[
'file'].
':'.$frame[
'line'];
154 } elseif (isset($frame[
'function']) && $frame[
'function'] ===
'{closure}') {
156 $data[
'trace'][] = $frame[
'function'];
158 if (isset($frame[
'args'])) {
161 $frame[
'args'] = array_map(
function ($arg) {
174 if ($previous = $e->getPrevious()) {
198 if ($json ===
false) {
211 if (version_compare(PHP_VERSION,
'5.4.0',
'>=')) {
212 return json_encode(
$data, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
215 return json_encode(
$data);
233 if (
$code !== JSON_ERROR_UTF8) {
237 if (is_string(
$data)) {
239 } elseif (is_array(
$data)) {
240 array_walk_recursive(
$data, array($this,
'detectAndCleanUtf8'));
247 if ($json ===
false) {
264 case JSON_ERROR_DEPTH:
265 $msg =
'Maximum stack depth exceeded';
267 case JSON_ERROR_STATE_MISMATCH:
268 $msg =
'Underflow or the modes mismatch';
270 case JSON_ERROR_CTRL_CHAR:
271 $msg =
'Unexpected control character found';
273 case JSON_ERROR_UTF8:
274 $msg =
'Malformed UTF-8 characters, possibly incorrectly encoded';
277 $msg =
'Unknown error';
280 throw new \RuntimeException(
'JSON encoding failed: '.$msg.
'. Encoding: '.var_export(
$data,
true));
301 if (is_string(
$data) && !preg_match(
'//u',
$data)) {
302 $data = preg_replace_callback(
304 function (
$m) {
return utf8_encode(
$m[0]); },
308 array(
'¤',
'¦',
'¨',
'´',
'¸',
'¼',
'½',
'¾'),
309 array(
'€',
'Š',
'š',
'Ž',
'ž',
'Œ',
'œ',
'Ÿ'),