1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
filelogger.php
См. документацию.
1<?php
2
9
10namespace Bitrix\Main\Diag;
11
12class FileLogger extends Logger
13{
14 protected $fileName;
15 protected $maxSize = 1048576;
16
21 public function __construct(string $fileName, int $maxSize = null)
22 {
23 $this->fileName = $fileName;
24
25 if ($maxSize !== null)
26 {
27 $this->maxSize = $maxSize;
28 }
29 }
30
31 protected function logMessage(string $level, string $message)
32 {
33 $current = ignore_user_abort(true);
34
35 if ($fp = fopen($this->fileName, 'ab'))
36 {
37 if (flock($fp, LOCK_EX))
38 {
39 if ($this->maxSize > 0)
40 {
41 // need it for filesize()
42 clearstatcache();
43 $logSize = filesize($this->fileName);
44
45 if ($logSize > $this->maxSize)
46 {
47 $this->rotateLog();
48 ftruncate($fp, 0);
49 }
50 }
51
52 fwrite($fp, $message);
53 fflush($fp);
54 flock($fp, LOCK_UN);
55 }
56 fclose($fp);
57 }
58
59 ignore_user_abort($current);
60 }
61
62 protected function rotateLog()
63 {
64 $historyName = $this->fileName . '.old';
65
66 copy($this->fileName, $historyName);
67 }
68}
logMessage(string $level, string $message)
Определения filelogger.php:31
__construct(string $fileName, int $maxSize=null)
Определения filelogger.php:21
string $message
Определения logger.php:36
$level
Определения logger.php:30