Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
fileexceptionhandlerlog.php
1<?php
2
3namespace Bitrix\Main\Diag;
4
6use Psr\Log;
7
9{
10 const MAX_LOG_SIZE = 1000000;
11 const DEFAULT_LOG_FILE = "bitrix/modules/error.log";
12
13 private $level;
14
16 protected $logger;
17
18 public function initialize(array $options)
19 {
20 $logFile = static::DEFAULT_LOG_FILE;
21 if (isset($options["file"]) && !empty($options["file"]))
22 {
23 $logFile = $options["file"];
24 }
25
26 if ((substr($logFile, 0, 1) !== "/") && !preg_match("#^[a-z]:/#", $logFile))
27 {
28 $logFile = Main\Application::getDocumentRoot()."/".$logFile;
29 }
30
31 $maxLogSize = static::MAX_LOG_SIZE;
32 if (isset($options["log_size"]) && $options["log_size"] > 0)
33 {
34 $maxLogSize = (int)$options["log_size"];
35 }
36
37 $this->logger = new FileLogger($logFile, $maxLogSize);
38
39 if (isset($options["level"]) && $options["level"] > 0)
40 {
41 $this->level = (int)$options["level"];
42 }
43 }
44
49 public function write($exception, $logType)
50 {
51 $text = ExceptionHandlerFormatter::format($exception, false, $this->level);
52
53 $context = [
54 'type' => static::logTypeToString($logType),
55 ];
56
57 $logLevel = static::logTypeToLevel($logType);
58
59 $message = "{date} - Host: {host} - {type} - {$text}\n";
60
61 $this->logger->log($logLevel, $message, $context);
62 }
63
67 protected function writeToLog($text)
68 {
69 $this->logger->debug($text);
70 }
71}
static format($exception, $htmlMode=false, $level=0)