403Webshell
Server IP : 80.87.202.40  /  Your IP : 216.73.216.169
Web Server : Apache
System : Linux rospirotorg.ru 5.14.0-539.el9.x86_64 #1 SMP PREEMPT_DYNAMIC Thu Dec 5 22:26:13 UTC 2024 x86_64
User : bitrix ( 600)
PHP Version : 8.2.27
Disable Function : NONE
MySQL : OFF |  cURL : ON |  WGET : ON |  Perl : ON |  Python : OFF |  Sudo : ON |  Pkexec : ON
Directory :  /home/bitrix/ext_www/ilovecveti.ru/bitrix/modules/calendar/lib/sync/util/

Upload File :
current_dir [ Writeable] document_root [ Writeable]

 

Command :


[ Back ]     

Current File : /home/bitrix/ext_www/ilovecveti.ru/bitrix/modules/calendar/lib/sync/util/requestlogger.php
<?php

namespace Bitrix\Calendar\Sync\Util;

use Bitrix\Main;
use Bitrix\Main\Config\Option;
use Psr\Log\LoggerInterface;
use Psr\Log\LogLevel;

class RequestLogger extends Main\Diag\Logger
{
	private const OPTION_KEY = 'calendar_logger_enable';

	/**
	 * @var string
	 */
	protected string $serviceName;

	/**
	 * @var int
	 */
	protected int $userId;

	/**
	 * @var LoggerInterface|null
	 */
	private ?LoggerInterface $logger;

	/**
	 * @param int $ttl
	 * @return void
	 * @throws Main\ArgumentOutOfRangeException
	 */
	public static function enable(int $ttl = 0): void
	{
		$dateEnd = 0;
		if ($ttl)
		{
			$dateEnd = (time() + $ttl);
		}

		Option::set('calendar', self::OPTION_KEY, $dateEnd, '-');
	}

	/**
	 * @return bool
	 */
	public static function isEnabled(): bool
	{
		$value = Option::get('calendar', self::OPTION_KEY, null, '-');
		if ($value === null)
		{
			return false;
		}

		$value = (int) $value;
		if (
			$value === 0
			|| $value > time()
		)
		{
			return true;
		}

		return false;
	}

	/**
	 * @param int $userId
	 * @param string $serviceName
	 */
	public function __construct(int $userId, string $serviceName)
	{
		$this->userId = $userId;
		$this->serviceName = $serviceName;
	}

	/**
	 * this method for log data from sync request
	 * you should send params in context:
	 *  - requestParams
	 *  - url
	 *  - method
	 *  - statusCode
	 *  - response
	 *  - error
	 * @param array $context{
		requestParams: array,
		url: string,
		method: string,
		statusCode: string,
		response: string,
		error: string,
		host: string,
	}
	 * @return void
	 *
	 * @throws Main\LoaderException
	 */
	public function write(array $context): void
	{
		$context['serviceName'] = $this->serviceName;
		$context['userId'] = $this->userId;
		$logger = $this->getLogger();
		if (is_a($logger, DatabaseLogger::class))
		{
			$logger->logToDatabase($context);
		}
		else
		{
			$logger->log(LogLevel::DEBUG, $this->prepareMessage(), $context);
		}
	}

	private function prepareMessage(): string
	{
		return "{date} SERVICE_NAME {serviceName}
			HOST: {host},
			REQUEST_PARAMS: {requestParams}, 
			URL: {url},
			METHOD: {method},
			STATUS_CODE: {statusCode},
			RESPONSE: {response},
			ERROR: {error}
		";
	}


	/**
	 * @return LoggerInterface
	 */
	private function getLogger(): LoggerInterface
	{
		if (empty($this->logger))
		{
			$this->logger = $this->getDatabaseLogger();
		}
		return $this->logger;
	}

	private function getDatabaseLogger(): DatabaseLogger
	{
		return new DatabaseLogger();
	}

	protected function logMessage(string $level, string $message)
	{

	}
}

Youez - 2016 - github.com/yon3zu
LinuXploit