Last active
August 10, 2022 06:30
-
-
Save niksamokhvalov/1fc4493fe006f753f2b6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
use Bitrix\Main\Application; | |
use Monolog\Handler\StreamHandler; | |
use Monolog\Logger; | |
use Monolog\Registry; | |
use Monolog\Formatter\LogstashFormatter; | |
use Monolog\Processor\WebProcessor; | |
/** | |
* Основной класс приложения. Содержит базовые вспомогательные методы, инициализирует и настраивает окружение, | |
* занимается подгрузкой необходимых классов и библиотек. | |
*/ | |
class XXX | |
{ | |
/** | |
* Каталог билда вёрстки. | |
*/ | |
const MARKUP = '/path/to/dir'; | |
public function __construct() | |
{ | |
// … | |
$autoload = Application::getDocumentRoot() . '/vendor/autoload.php'; | |
if (file_exists($autoload)) | |
{ | |
include_once $autoload; | |
} | |
// … | |
} | |
/** | |
* Запуск приложения. | |
*/ | |
public function run() | |
{ | |
$exceptionOutputHandler = new ExceptionHandlerOutput(); | |
Application::getInstance()->getExceptionHandler()->setHandlerOutput($exceptionOutputHandler); | |
$this->createLogger(); | |
} | |
/** | |
* Регистрация общего логера приложения. | |
*/ | |
protected function createLogger() | |
{ | |
$appLogger = new Logger('app'); | |
$handler = new StreamHandler(static::logPath('app')); | |
$handler->setFormatter(new LogstashFormatter('bitrix')); | |
$appLogger->pushProcessor(new WebProcessor()); | |
$appLogger->pushHandler($handler); | |
Registry::addLogger($appLogger, 'app'); | |
} | |
/** | |
* Получить сформированный абсолютный путь до лог-файла. | |
* | |
* @param string $logName Имя лога (без расширения файла). Может состоять из пути, например: dir/path/file. | |
* @param string $module Код модуля, к которому относится лог. | |
* | |
* @return string | |
*/ | |
public static function logPath($logName, $module = null) | |
{ | |
return 'XXX'; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment