Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
log.php
1<?php
2namespace Bitrix\Im;
3
4class Log
5{
6 public static function write($data)
7 {
8 if (!is_array($data['USER_ID']))
9 {
10 $data['USER_ID'] = [(int)$data['USER_ID']];
11 }
12
13 $users = [];
14 foreach ($data['USER_ID'] as $uid)
15 {
16 $uid = (int)$uid;
17 if ($uid)
18 {
19 $users[] = $uid;
20 }
21 }
22
23 if (empty($users))
24 {
25 return;
26 }
27
28 $action = $data['ACTION']?: 'UNKNOWN';
29 $params = $data['PARAMS']?: [];
30 $device = $data['DEVICE']?: 'UNKNOWN';
31
32 global $USER;
33
34 if (!in_array((int)$USER->GetID(), $users, true))
35 {
36 return;
37 }
38
39 $logUserId = $USER->GetID();
40
41 $sessionId = \Bitrix\Main\Application::getInstance()->getKernelSession()->getId();
42 $logName = md5($sessionId);
43 $scriptName = \Bitrix\Main\Context::getCurrent()->getServer()->getScriptName();
44 $userIp = \Bitrix\Main\Context::getCurrent()->getRequest()->getRemoteAddress();
45 if ($device === 'UNKNOWN')
46 {
47 $device = mb_strpos($scriptName, 'desktop_app')? 'DESKTOP' : 'BROWSER';
48 }
49
50 $log = "\n------------------------\n";
51 $log .= date("Y.m.d G:i:s")."\n";
52 $log .= $action.' ['.$device.' - '.$userIp.' :: '.$sessionId."]\n";
53 $log .= print_r($params, 1);
54 $log .= "\n------------------------\n";
55
56 \Bitrix\Main\IO\File::putFileContents($_SERVER["DOCUMENT_ROOT"]."/../logs/im/$logUserId/$logName.log", $log, \Bitrix\Main\IO\File::APPEND);
57 }
58}
59
static write($data)
Definition log.php:6