1
|
|
|
<?php |
2
|
|
|
namespace App\Monolog; |
3
|
|
|
|
4
|
|
|
use App\Log; |
5
|
|
|
use Bitrix\Main\Diag\Debug; |
|
|
|
|
6
|
|
|
use Bitrix\Main\Diag\ExceptionHandler; |
|
|
|
|
7
|
|
|
use Monolog\Logger; |
8
|
|
|
use Psr\Log\LogLevel; |
9
|
|
|
|
10
|
|
|
class ExceptionHandlerLog extends \Bitrix\Main\Diag\ExceptionHandlerLog { |
|
|
|
|
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* @var Logger |
14
|
|
|
*/ |
15
|
|
|
protected $logger; |
16
|
|
|
/** |
17
|
|
|
* @var callable |
18
|
|
|
*/ |
19
|
|
|
protected $context; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* {@inheritdoc} |
23
|
|
|
*/ |
24
|
|
|
public function initialize(array $options) |
25
|
|
|
{ |
26
|
|
|
if (isset($options['context'])) |
27
|
|
|
{ |
28
|
|
|
$this->context = $options['context']; |
29
|
|
|
} |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* {@inheritdoc} |
34
|
|
|
*/ |
35
|
|
|
public function write($exception, $logType) |
36
|
|
|
{ |
37
|
|
|
try { |
38
|
|
|
$log = new Log(); |
39
|
|
|
if(is_callable($this->context)) { |
40
|
|
|
try { |
41
|
|
|
$this->context = call_user_func($this->context, $exception); |
42
|
|
|
} catch(\Exception $e) { |
43
|
|
|
self::logInnerException(new \Exception('Can not call ' . (string) $this->context)); |
44
|
|
|
} |
45
|
|
|
} |
46
|
|
|
if(!is_array($this->context)) { |
47
|
|
|
$this->context = (!empty($this->context) ? [$this->context] : []); |
48
|
|
|
} |
49
|
|
|
if($logType == \Bitrix\Main\Diag\ExceptionHandlerLog::LOW_PRIORITY_ERROR) { |
50
|
|
|
$log->error($exception, $this->context); |
51
|
|
|
} else { |
52
|
|
|
$telegramBlocked = false; |
53
|
|
|
if($_ENV['APP_LOG_NO_TELEGRAM']) { |
54
|
|
|
$blockStrings = explode('|', $_ENV['APP_LOG_NO_TELEGRAM']); |
55
|
|
|
foreach($blockStrings as $blockString) { |
56
|
|
|
if(stripos($exception, $blockString) !== false) { |
57
|
|
|
$telegramBlocked = true; |
58
|
|
|
break; |
59
|
|
|
} |
60
|
|
|
} |
61
|
|
|
} |
62
|
|
|
if($telegramBlocked) { |
63
|
|
|
$log->error($exception, $this->context); |
64
|
|
|
} else { |
65
|
|
|
$this->context['source'] = self::logTypeToString($logType); |
66
|
|
|
$log->telegram(LogLevel::CRITICAL, $exception, $this->context); |
67
|
|
|
} |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
} catch(\Exception $e) { |
71
|
|
|
self::logInnerException($e); |
72
|
|
|
} |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* @param \Exception $exception |
77
|
|
|
*/ |
78
|
|
|
protected static function logInnerException(\Exception $exception) |
79
|
|
|
{ |
80
|
|
|
Debug::writeToFile((string) $exception, "", "inner_error.log"); |
81
|
|
|
} |
82
|
|
|
} |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths