PluginProbe
ManageWP Worker / 4.9.25
ManageWP Worker v4.9.25
4.9.38 4.9.37 4.9.36 4.9.35 4.9.34 3.8.7 3.8.8 3.9.0 3.9.1 3.9.10 3.9.11 3.9.12 3.9.13 3.9.14 3.9.15 3.9.16 3.9.17 3.9.18 3.9.19 3.9.2 3.9.20 3.9.21 3.9.22 3.9.23 3.9.24 All 73 releases
worker / src / Monolog / Formatter / LineFormatter.php

LineFormatter.php in ManageWP Worker 4.9.25, at src/Monolog/Formatter/LineFormatter.php

98 lines 2.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /*
4 * This file is part of the Monolog package.
5 *
6 * (c) Jordi Boggiano <j.boggiano@seld.be>
7 *
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
10 */
11
12 /**
13 * Formats incoming records into a one-line string
14 *
15 * This is especially useful for logging to files
16 *
17 * @author Jordi Boggiano <j.boggiano@seld.be>
18 * @author Christophe Coevoet <stof@notk.org>
19 */
20 class Monolog_Formatter_LineFormatter extends Monolog_Formatter_NormalizerFormatter
21 {
22 const SIMPLE_FORMAT = "[%datetime%] %channel%.%level_name%: %message% %context% %extra%\n";
23
24 protected $format;
25
26 /**
27 * @param string $format The format of the message
28 * @param string $dateFormat The format of the timestamp: one supported by DateTime::format
29 */
30 public function __construct($format = null, $dateFormat = null)
31 {
32 $this->format = $format ? $format : self::SIMPLE_FORMAT;
33 parent::__construct($dateFormat);
34 }
35
36 /**
37 * {@inheritdoc}
38 */
39 public function format(array $record)
40 {
41 $vars = parent::format($record);
42
43 $output = $this->format;
44 foreach ($vars['extra'] as $var => $val) {
45 if (false !== strpos($output, '%extra.'.$var.'%')) {
46 $output = str_replace('%extra.'.$var.'%', $this->convertToString($val), $output);
47 unset($vars['extra'][$var]);
48 }
49 }
50 foreach ($vars as $var => $val) {
51 if (false !== strpos($output, '%'.$var.'%')) {
52 $output = str_replace('%'.$var.'%', $this->convertToString($val), $output);
53 }
54 }
55
56 return $output;
57 }
58
59 public function formatBatch(array $records)
60 {
61 $message = '';
62 foreach ($records as $record) {
63 $message .= $this->format($record);
64 }
65
66 return $message;
67 }
68
69 protected function normalizeException(Exception $e)
70 {
71 $previousText = '';
72 if (is_callable(array($e, 'getPrevious')) && $previous = $e->getPrevious()) {
73 do {
74 $previousText .= ', '.get_class($previous).': '.$previous->getMessage().' at '.$previous->getFile().':'.$previous->getLine();
75 } while ($previous = $previous->getPrevious());
76 }
77
78 return '[object] ('.get_class($e).': '.$e->getMessage().' at '.$e->getFile().':'.$e->getLine().$previousText.')';
79 }
80
81 protected function convertToString($data)
82 {
83 if (null === $data || is_bool($data)) {
84 return var_export($data, true);
85 }
86
87 if (is_scalar($data)) {
88 return (string) $data;
89 }
90
91 if (version_compare(PHP_VERSION, '5.4.0', '>=')) {
92 return $this->toJson($data, true);
93 }
94
95 return str_replace('\\/', '/', @json_encode($data));
96 }
97 }
98