@@ -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} |
@@ -34,15 +34,15 @@ |
||
| 34 | 34 | { |
| 35 | 35 | try { |
| 36 | 36 | $log = new Log(); |
| 37 | - if(is_callable($this->context)) { |
|
| 37 | + if (is_callable($this->context)) { |
|
| 38 | 38 | try { |
| 39 | 39 | $context = call_user_func($this->context, $exception); |
| 40 | - } catch(\Exception $e) { |
|
| 40 | + } catch (\Exception $e) { |
|
| 41 | 41 | Log::logInnerException(new \Exception('Can not call ' . $this->context)); |
| 42 | 42 | } |
| 43 | 43 | } |
| 44 | 44 | $log->critical($exception, (array) $this->context); |
| 45 | - } catch(\Exception $e) { |
|
| 45 | + } catch (\Exception $e) { |
|
| 46 | 46 | Log::logInnerException($e); |
| 47 | 47 | } |
| 48 | 48 | } |
@@ -5,17 +5,17 @@ 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 | - if(is_array($record['context'])) { |
|
| 18 | - if(count($record['context']) == 1) { |
|
| 17 | + if(is_array($record['context'])) { |
|
| 18 | + if(count($record['context']) == 1) { |
|
| 19 | 19 | $output[] = current($record['context']); |
| 20 | 20 | } else if(count($record['context']) > 1) { |
| 21 | 21 | $output[] = print_r($record['context'], true); |
@@ -24,6 +24,6 @@ discard block |
||
| 24 | 24 | $output[] = $record['context']; |
| 25 | 25 | } |
| 26 | 26 | |
| 27 | - return join("\r\n", $output) . "\r\n------------------------------------------------------------------------\r\n"; |
|
| 28 | - } |
|
| 27 | + return join("\r\n", $output) . "\r\n------------------------------------------------------------------------\r\n"; |
|
| 28 | + } |
|
| 29 | 29 | } |
@@ -14,13 +14,13 @@ |
||
| 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(is_array($record['context'])) { |
|
| 18 | - if(count($record['context']) == 1) { |
|
| 17 | + if (is_array($record['context'])) { |
|
| 18 | + if (count($record['context']) == 1) { |
|
| 19 | 19 | $output[] = current($record['context']); |
| 20 | - } else if(count($record['context']) > 1) { |
|
| 20 | + } else if (count($record['context']) > 1) { |
|
| 21 | 21 | $output[] = print_r($record['context'], true); |
| 22 | 22 | } |
| 23 | - } else if(!empty($record['context'])) { |
|
| 23 | + } else if (!empty($record['context'])) { |
|
| 24 | 24 | $output[] = $record['context']; |
| 25 | 25 | } |
| 26 | 26 | |
@@ -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'); |
@@ -24,7 +24,7 @@ discard block |
||
| 24 | 24 | public function __construct($channel = '') { |
| 25 | 25 | |
| 26 | 26 | $this->minDebugLevel = ($_ENV['APP_DEBUG_LEVEL'] ?: 'DEBUG'); |
| 27 | - if(!empty($channel)) { |
|
| 27 | + if (!empty($channel)) { |
|
| 28 | 28 | $this->channel = $channel; |
| 29 | 29 | //TODO: get channel options |
| 30 | 30 | } else { |
@@ -180,35 +180,35 @@ discard block |
||
| 180 | 180 | } |
| 181 | 181 | |
| 182 | 182 | $isEnabled = false; |
| 183 | - if(isset($_ENV['APP_LOG_TELEGRAM'])) { |
|
| 183 | + if (isset($_ENV['APP_LOG_TELEGRAM'])) { |
|
| 184 | 184 | $APP_LOG_TELEGRAM = trim(strtolower($_ENV['APP_LOG_TELEGRAM'])); |
| 185 | - if($APP_LOG_TELEGRAM === 'on' || $APP_LOG_TELEGRAM === 'true' || $APP_LOG_TELEGRAM === '1') { |
|
| 185 | + if ($APP_LOG_TELEGRAM === 'on' || $APP_LOG_TELEGRAM === 'true' || $APP_LOG_TELEGRAM === '1') { |
|
| 186 | 186 | $isEnabled = true; |
| 187 | 187 | } |
| 188 | 188 | } |
| 189 | 189 | |
| 190 | - if(!isset($_ENV['APP_LOG_TELEGRAM_KEY']) || empty($_ENV['APP_LOG_TELEGRAM_KEY'])) { |
|
| 190 | + if (!isset($_ENV['APP_LOG_TELEGRAM_KEY']) || empty($_ENV['APP_LOG_TELEGRAM_KEY'])) { |
|
| 191 | 191 | $isEnabled = false; |
| 192 | 192 | } |
| 193 | - if(!isset($_ENV['APP_LOG_TELEGRAM_CHANNEL']) || empty($_ENV['APP_LOG_TELEGRAM_CHANNEL'])) { |
|
| 193 | + if (!isset($_ENV['APP_LOG_TELEGRAM_CHANNEL']) || empty($_ENV['APP_LOG_TELEGRAM_CHANNEL'])) { |
|
| 194 | 194 | $isEnabled = false; |
| 195 | 195 | } |
| 196 | 196 | |
| 197 | - if(!$isEnabled) { |
|
| 197 | + if (!$isEnabled) { |
|
| 198 | 198 | return; |
| 199 | 199 | } |
| 200 | 200 | |
| 201 | 201 | $sender = new TelegramBotHandler($_ENV['APP_LOG_TELEGRAM_KEY'], $_ENV['APP_LOG_TELEGRAM_CHANNEL']); |
| 202 | 202 | |
| 203 | - if(isset($context['parse_mode']) && !empty($context['parse_mode'])) { |
|
| 203 | + if (isset($context['parse_mode']) && !empty($context['parse_mode'])) { |
|
| 204 | 204 | $sender->setParseMode($context['parse_mode']); |
| 205 | 205 | unset($context['parse_mode']); |
| 206 | 206 | } |
| 207 | - if(isset($context['disable_notification']) && $context['disable_notification'] === true) { |
|
| 207 | + if (isset($context['disable_notification']) && $context['disable_notification'] === true) { |
|
| 208 | 208 | $sender->disableNotification(true); |
| 209 | 209 | unset($context['disable_notification']); |
| 210 | 210 | } |
| 211 | - if(isset($context['disable_preview']) && $context['disable_preview'] === true) { |
|
| 211 | + if (isset($context['disable_preview']) && $context['disable_preview'] === true) { |
|
| 212 | 212 | $sender->disableWebPagePreview(true); |
| 213 | 213 | unset($context['disable_preview']); |
| 214 | 214 | } |
@@ -226,9 +226,9 @@ discard block |
||
| 226 | 226 | */ |
| 227 | 227 | private function formatMessage($message) { |
| 228 | 228 | |
| 229 | - if($message instanceof \Exception || $message instanceof Error) { |
|
| 229 | + if ($message instanceof \Exception || $message instanceof Error) { |
|
| 230 | 230 | $message = (string) $message; |
| 231 | - } else if(is_array($message) || is_object($message)) { |
|
| 231 | + } else if (is_array($message) || is_object($message)) { |
|
| 232 | 232 | $message = json_encode((array) $message, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES); |
| 233 | 233 | $message = str_replace('\\u0000', '', $message); |
| 234 | 234 | } |
@@ -240,15 +240,15 @@ discard block |
||
| 240 | 240 | */ |
| 241 | 241 | public function getLogger() { |
| 242 | 242 | |
| 243 | - if(Registry::hasLogger($this->channel)) { |
|
| 243 | + if (Registry::hasLogger($this->channel)) { |
|
| 244 | 244 | return Registry::getInstance($this->channel); |
| 245 | 245 | } |
| 246 | 246 | $logPath = $_SERVER['DOCUMENT_ROOT'] . ($_ENV['APP_LOG_FOLDER'] ?: '/log/'); |
| 247 | 247 | $logPath .= $this->channel . '/' . date('Y-m-d') . '.log'; |
| 248 | 248 | $logDir = pathinfo($logPath, PATHINFO_DIRNAME); |
| 249 | - if(!file_exists($logDir)) { |
|
| 249 | + if (!file_exists($logDir)) { |
|
| 250 | 250 | $mode = 0775; |
| 251 | - if(defined('BX_DIR_PERMISSIONS') && BX_DIR_PERMISSIONS) { |
|
| 251 | + if (defined('BX_DIR_PERMISSIONS') && BX_DIR_PERMISSIONS) { |
|
| 252 | 252 | $mode = BX_DIR_PERMISSIONS; |
| 253 | 253 | } |
| 254 | 254 | mkdir($logDir, $mode, true); |
@@ -271,7 +271,7 @@ discard block |
||
| 271 | 271 | |
| 272 | 272 | $levels = Logger::getLevels(); |
| 273 | 273 | |
| 274 | - if($this->minDebugLevel && isset($levels[$this->minDebugLevel])) { |
|
| 274 | + if ($this->minDebugLevel && isset($levels[$this->minDebugLevel])) { |
|
| 275 | 275 | return $levels[$this->minDebugLevel]; |
| 276 | 276 | } else { |
| 277 | 277 | return Logger::DEBUG; |
@@ -289,7 +289,7 @@ discard block |
||
| 289 | 289 | } |
| 290 | 290 | |
| 291 | 291 | $min_level = $this->getMinErrorLevel(); |
| 292 | - if($level >= $min_level) { |
|
| 292 | + if ($level >= $min_level) { |
|
| 293 | 293 | return true; |
| 294 | 294 | } |
| 295 | 295 | return false; |