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/rospirotorg.ru/bitrix/modules/sale/lib/cashbox/

Upload File :
current_dir [ Writeable] document_root [ Writeable]

 

Command :


[ Back ]     

Current File : /home/bitrix/ext_www/rospirotorg.ru/bitrix/modules/sale/lib/cashbox/logger.php
<?php

namespace Bitrix\Sale\Cashbox;

use Bitrix\Main\ArgumentTypeException;
use Bitrix\Main\Config\Option;
use Bitrix\Main\Type\DateTime;
use Bitrix\Sale\Cashbox\Internals\CashboxErrLogTable;

/**
 * Class Logger
 * @package Bitrix\Sale\Cashbox
 */
class Logger
{
	/* trace levels */
	protected const TRACE_LEVEL_ERROR = 1;
	protected const TRACE_LEVEL_WARNING = 2;
	protected const TRACE_LEVEL_DEBUG = 3;

	/**
	 * @param ?string $message
	 * @param null $cashboxId
	 */
	public static function addError(?string $message, $cashboxId = null): void
	{
		self::addToLog($message, $cashboxId, static::TRACE_LEVEL_ERROR);
	}

	/**
	 * @param ?string $message
	 * @param null $cashboxId
	 */
	public static function addWarning(?string $message, $cashboxId = null): void
	{
		self::addToLog($message, $cashboxId, static::TRACE_LEVEL_WARNING);
	}

	/**
	 * @param ?string $message
	 * @param null $cashboxId
	 */
	public static function addDebugInfo(?string $message, $cashboxId = null): void
	{
		self::addToLog($message, $cashboxId, static::TRACE_LEVEL_DEBUG);
	}

	/**
	 * @param ?string $message
	 * @return bool
	 */
	private static function validateMessage(?string $message): bool
	{
		return !empty($message);
	}

	/**
	 * @param int $messageLevel
	 * @return bool
	 */
	private static function checkMessageLevel(int $messageLevel): bool
	{
		return $messageLevel <= self::getLevel();
	}

	/**
	 * @param ?string $message
	 * @param $cashboxId
	 * @param $messageLevel
	 */
	private static function addToLog(?string $message, $cashboxId, $messageLevel): void
	{
		if (self::checkMessageLevel($messageLevel) && self::validateMessage($message))
		{
			$data = [
				'CASHBOX_ID' => $cashboxId,
				'MESSAGE' => $message,
				'DATE_INSERT' => new DateTime()
			];

			CashboxErrLogTable::add($data);
		}
	}

	/**
	 * @return int
	 * @throws \Bitrix\Main\ArgumentNullException
	 * @throws \Bitrix\Main\ArgumentOutOfRangeException
	 */
	private static function getLevel(): int
	{
		return (int)Option::get('sale', 'cashbox_log_level', static::TRACE_LEVEL_ERROR);
	}
}

Youez - 2016 - github.com/yon3zu
LinuXploit