@@ -10,11 +10,11 @@ |
||
10 | 10 | /** |
11 | 11 | * @var Logger |
12 | 12 | */ |
13 | - protected $logger; |
|
14 | - /** |
|
13 | + protected $logger; |
|
14 | + /** |
|
15 | 15 | * @var callable |
16 | 16 | */ |
17 | - protected $context; |
|
17 | + protected $context; |
|
18 | 18 | |
19 | 19 | /** |
20 | 20 | * {@inheritdoc} |
@@ -36,30 +36,30 @@ discard block |
||
36 | 36 | { |
37 | 37 | try { |
38 | 38 | $log = new Log(); |
39 | - if(is_callable($this->context)) { |
|
39 | + if (is_callable($this->context)) { |
|
40 | 40 | try { |
41 | 41 | $this->context = call_user_func($this->context, $exception); |
42 | - } catch(\Exception $e) { |
|
42 | + } catch (\Exception $e) { |
|
43 | 43 | self::logInnerException(new \Exception('Can not call ' . (string) $this->context)); |
44 | 44 | } |
45 | 45 | } |
46 | - if(!is_array($this->context)) { |
|
46 | + if (!is_array($this->context)) { |
|
47 | 47 | $this->context = (!empty($this->context) ? [$this->context] : []); |
48 | 48 | } |
49 | - if($logType == \Bitrix\Main\Diag\ExceptionHandlerLog::LOW_PRIORITY_ERROR) { |
|
49 | + if ($logType == \Bitrix\Main\Diag\ExceptionHandlerLog::LOW_PRIORITY_ERROR) { |
|
50 | 50 | $log->error($exception, $this->context); |
51 | 51 | } else { |
52 | 52 | $telegramBlocked = false; |
53 | - if($_ENV['APP_LOG_NO_TELEGRAM']) { |
|
53 | + if ($_ENV['APP_LOG_NO_TELEGRAM']) { |
|
54 | 54 | $blockStrings = explode('|', $_ENV['APP_LOG_NO_TELEGRAM']); |
55 | - foreach($blockStrings as $blockString) { |
|
56 | - if(stripos($exception, $blockString) !== false) { |
|
55 | + foreach ($blockStrings as $blockString) { |
|
56 | + if (stripos($exception, $blockString) !== false) { |
|
57 | 57 | $telegramBlocked = true; |
58 | 58 | break; |
59 | 59 | } |
60 | 60 | } |
61 | 61 | } |
62 | - if($telegramBlocked) { |
|
62 | + if ($telegramBlocked) { |
|
63 | 63 | $log->error($exception, $this->context); |
64 | 64 | } else { |
65 | 65 | $this->context['source'] = self::logTypeToString($logType); |
@@ -67,7 +67,7 @@ discard block |
||
67 | 67 | } |
68 | 68 | } |
69 | 69 | |
70 | - } catch(\Exception $e) { |
|
70 | + } catch (\Exception $e) { |
|
71 | 71 | self::logInnerException($e); |
72 | 72 | } |
73 | 73 | } |
@@ -1,7 +1,7 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | define("NO_KEEP_STATISTIC", "Y"); |
3 | -define("NO_AGENT_STATISTIC","Y"); |
|
4 | -require_once($_SERVER['DOCUMENT_ROOT'].'/bitrix/modules/main/include/prolog_before.php'); |
|
3 | +define("NO_AGENT_STATISTIC", "Y"); |
|
4 | +require_once($_SERVER['DOCUMENT_ROOT'] . '/bitrix/modules/main/include/prolog_before.php'); |
|
5 | 5 | |
6 | 6 | $log = new \App\Log('test'); |
7 | 7 | |
@@ -13,7 +13,7 @@ discard block |
||
13 | 13 | |
14 | 14 | try { |
15 | 15 | throw new Exception('test exception'); |
16 | -} catch(Exception $e) { |
|
16 | +} catch (Exception $e) { |
|
17 | 17 | $log->error($e); |
18 | 18 | } |
19 | 19 | throw new Exception('test exception'); |
@@ -9,9 +9,9 @@ discard block |
||
9 | 9 | */ |
10 | 10 | public static function stringfyMessage($message) { |
11 | 11 | |
12 | - if($message instanceof \Throwable) { |
|
12 | + if ($message instanceof \Throwable) { |
|
13 | 13 | $message = (string) $message; |
14 | - } else if(is_array($message) || is_object($message)) { |
|
14 | + } else if (is_array($message) || is_object($message)) { |
|
15 | 15 | $message = json_encode((array) $message, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES); |
16 | 16 | $message = str_replace('\\u0000', '', $message); |
17 | 17 | } |
@@ -27,21 +27,21 @@ discard block |
||
27 | 27 | |
28 | 28 | $source = (isset($context['source']) ? sprintf("<b>%s</b>", (string) $context['source']) : ''); |
29 | 29 | |
30 | - if($message instanceof \Throwable) { |
|
30 | + if ($message instanceof \Throwable) { |
|
31 | 31 | |
32 | 32 | $message = sprintf("%s, <i>File: %s</i>", $message->getMessage(), $message->getFile()); |
33 | 33 | |
34 | - } else if(is_array($message) || is_object($message)) { |
|
34 | + } else if (is_array($message) || is_object($message)) { |
|
35 | 35 | |
36 | 36 | $message = json_encode((array) $message, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES); |
37 | 37 | $message = str_replace('\\u0000', '', $message); |
38 | - if(strlen($message) > 4000) { |
|
38 | + if (strlen($message) > 4000) { |
|
39 | 39 | $message = substr($message, 0, 4000) . '...'; |
40 | 40 | } |
41 | 41 | $message = sprintf("<code>%s</code>", $message); |
42 | 42 | } |
43 | 43 | |
44 | - if(!empty($source)) { |
|
44 | + if (!empty($source)) { |
|
45 | 45 | return sprintf("%s: %s", $source, $message); |
46 | 46 | } else { |
47 | 47 | return $message; |
@@ -5,14 +5,14 @@ discard block |
||
5 | 5 | |
6 | 6 | class ArrayFormatter extends NormalizerFormatter |
7 | 7 | { |
8 | - /** |
|
9 | - * {@inheritdoc} |
|
10 | - */ |
|
11 | - public function format(array $record) |
|
12 | - { |
|
13 | - /** @var \DateTime $date */ |
|
14 | - $date = $record['datetime']; |
|
15 | - $output = array(sprintf("%s %s", $record['level_name'], $date->format("d.m.Y H:i:s"))); |
|
8 | + /** |
|
9 | + * {@inheritdoc} |
|
10 | + */ |
|
11 | + public function format(array $record) |
|
12 | + { |
|
13 | + /** @var \DateTime $date */ |
|
14 | + $date = $record['datetime']; |
|
15 | + $output = array(sprintf("%s %s", $record['level_name'], $date->format("d.m.Y H:i:s"))); |
|
16 | 16 | $output[] = $record['message']; |
17 | 17 | if(!empty($record['context'])) { |
18 | 18 | if(is_array($record['context'])) { |
@@ -22,6 +22,6 @@ discard block |
||
22 | 22 | } |
23 | 23 | } |
24 | 24 | |
25 | - return join("\r\n", $output) . "\r\n------------------------------------------------------------------------\r\n"; |
|
26 | - } |
|
25 | + return join("\r\n", $output) . "\r\n------------------------------------------------------------------------\r\n"; |
|
26 | + } |
|
27 | 27 | } |
@@ -14,8 +14,8 @@ |
||
14 | 14 | $date = $record['datetime']; |
15 | 15 | $output = array(sprintf("%s %s", $record['level_name'], $date->format("d.m.Y H:i:s"))); |
16 | 16 | $output[] = $record['message']; |
17 | - if(!empty($record['context'])) { |
|
18 | - if(is_array($record['context'])) { |
|
17 | + if (!empty($record['context'])) { |
|
18 | + if (is_array($record['context'])) { |
|
19 | 19 | $output[] = print_r($record['context'], true); |
20 | 20 | } else { |
21 | 21 | $output[] = $record['context']; |
@@ -17,7 +17,7 @@ discard block |
||
17 | 17 | */ |
18 | 18 | public function __construct($channel = '') { |
19 | 19 | |
20 | - if(!empty($channel)) { |
|
20 | + if (!empty($channel)) { |
|
21 | 21 | $this->channel = $channel; |
22 | 22 | } else { |
23 | 23 | $this->channel = ($_ENV['APP_LOG_BITRIX_CHANNEL'] ?: 'bitrix'); |
@@ -186,7 +186,7 @@ discard block |
||
186 | 186 | |
187 | 187 | $logger = LoggerFactory::getInstance(LoggerFactory::TELEGRAM_CHANNEL, $context); |
188 | 188 | |
189 | - if($logger) { |
|
189 | + if ($logger) { |
|
190 | 190 | try { |
191 | 191 | $message = FormatHelper::stringfyTelegramMessage($message, (array) $context); |
192 | 192 | $logger->log($level, $message, $context); |
@@ -211,7 +211,7 @@ discard block |
||
211 | 211 | $minDebugLevel = ($_ENV['APP_DEBUG_LEVEL'] ?: LogLevel::DEBUG); |
212 | 212 | $minDebugLevel = Logger::toMonologLevel($minDebugLevel); |
213 | 213 | |
214 | - if($level >= $minDebugLevel) { |
|
214 | + if ($level >= $minDebugLevel) { |
|
215 | 215 | return true; |
216 | 216 | } |
217 | 217 | return false; |
@@ -222,7 +222,7 @@ discard block |
||
222 | 222 | */ |
223 | 223 | protected function logInnerException(\Exception $exception) |
224 | 224 | { |
225 | - if(class_exists('\Bitrix\Main\Diag\Debug')) { |
|
225 | + if (class_exists('\Bitrix\Main\Diag\Debug')) { |
|
226 | 226 | Debug::writeToFile((string) $exception, "", "monolog_error.log"); |
227 | 227 | } else { |
228 | 228 | $logPath = $_SERVER['DOCUMENT_ROOT'] . ($_ENV['APP_LOG_FOLDER'] ?: '/log/'); |
@@ -14,45 +14,45 @@ discard block |
||
14 | 14 | public static function getInstance($channel, $context) { |
15 | 15 | |
16 | 16 | $key = md5(json_encode([$channel, $context])); |
17 | - if(Registry::hasLogger($key)) { |
|
17 | + if (Registry::hasLogger($key)) { |
|
18 | 18 | return Registry::getInstance($key); |
19 | 19 | } |
20 | 20 | |
21 | - if($channel == self::TELEGRAM_CHANNEL) { |
|
21 | + if ($channel == self::TELEGRAM_CHANNEL) { |
|
22 | 22 | |
23 | - if(isset($_ENV['APP_LOG_TELEGRAM'])) { |
|
23 | + if (isset($_ENV['APP_LOG_TELEGRAM'])) { |
|
24 | 24 | $APP_LOG_TELEGRAM = trim(strtolower($_ENV['APP_LOG_TELEGRAM'])); |
25 | - if($APP_LOG_TELEGRAM !== 'on' && $APP_LOG_TELEGRAM !== 'true' && $APP_LOG_TELEGRAM !== '1') { |
|
25 | + if ($APP_LOG_TELEGRAM !== 'on' && $APP_LOG_TELEGRAM !== 'true' && $APP_LOG_TELEGRAM !== '1') { |
|
26 | 26 | return null; |
27 | 27 | } |
28 | 28 | } else { |
29 | 29 | return null; |
30 | 30 | } |
31 | 31 | |
32 | - if(!isset($_ENV['APP_LOG_TELEGRAM_KEY']) || empty($_ENV['APP_LOG_TELEGRAM_KEY'])) { |
|
32 | + if (!isset($_ENV['APP_LOG_TELEGRAM_KEY']) || empty($_ENV['APP_LOG_TELEGRAM_KEY'])) { |
|
33 | 33 | return null; |
34 | 34 | } |
35 | - if(!isset($_ENV['APP_LOG_TELEGRAM_CHATID']) || empty($_ENV['APP_LOG_TELEGRAM_CHATID'])) { |
|
35 | + if (!isset($_ENV['APP_LOG_TELEGRAM_CHATID']) || empty($_ENV['APP_LOG_TELEGRAM_CHATID'])) { |
|
36 | 36 | return null; |
37 | 37 | } |
38 | 38 | |
39 | - if(!class_exists('\Monolog\Handler\TelegramBotHandler')) { |
|
39 | + if (!class_exists('\Monolog\Handler\TelegramBotHandler')) { |
|
40 | 40 | return null; |
41 | 41 | } |
42 | 42 | |
43 | 43 | $sender = new TelegramBotHandler($_ENV['APP_LOG_TELEGRAM_KEY'], $_ENV['APP_LOG_TELEGRAM_CHATID']); |
44 | 44 | |
45 | - if(isset($context['parse_mode']) && !empty($context['parse_mode'])) { |
|
45 | + if (isset($context['parse_mode']) && !empty($context['parse_mode'])) { |
|
46 | 46 | $sender->setParseMode($context['parse_mode']); |
47 | 47 | unset($context['parse_mode']); |
48 | 48 | } else { |
49 | 49 | $sender->setParseMode('HTML'); |
50 | 50 | } |
51 | - if(isset($context['disable_notification']) && $context['disable_notification'] === true) { |
|
51 | + if (isset($context['disable_notification']) && $context['disable_notification'] === true) { |
|
52 | 52 | $sender->disableNotification(true); |
53 | 53 | unset($context['disable_notification']); |
54 | 54 | } |
55 | - if(isset($context['disable_preview']) && $context['disable_preview'] === false) { |
|
55 | + if (isset($context['disable_preview']) && $context['disable_preview'] === false) { |
|
56 | 56 | $sender->disableWebPagePreview(false); |
57 | 57 | unset($context['disable_preview']); |
58 | 58 | } else { |
@@ -72,9 +72,9 @@ discard block |
||
72 | 72 | $logPath = $_SERVER['DOCUMENT_ROOT'] . ($_ENV['APP_LOG_FOLDER'] ?: '/log/'); |
73 | 73 | $logPath .= $channel . '/' . date('Y-m-d') . '.log'; |
74 | 74 | $logDir = pathinfo($logPath, PATHINFO_DIRNAME); |
75 | - if(!file_exists($logDir)) { |
|
75 | + if (!file_exists($logDir)) { |
|
76 | 76 | $mode = 0775; |
77 | - if(defined('BX_DIR_PERMISSIONS') && BX_DIR_PERMISSIONS) { |
|
77 | + if (defined('BX_DIR_PERMISSIONS') && BX_DIR_PERMISSIONS) { |
|
78 | 78 | $mode = BX_DIR_PERMISSIONS; |
79 | 79 | } |
80 | 80 | mkdir($logDir, $mode, true); |