first commit

This commit is contained in:
Sven Wappler
2021-04-17 00:26:33 +02:00
commit 866c63cc63
813 changed files with 100696 additions and 0 deletions

View File

@@ -0,0 +1,99 @@
<?php
namespace WapplerSystems\Meilisearch\System\Logging;
/***************************************************************
* Copyright notice
*
* (c) 2010-2016 Timo Hund <timo.hund@dkd.de
* All rights reserved
*
* This script is part of the TYPO3 project. The TYPO3 project is
* free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* The GNU General Public License can be found at
* http://www.gnu.org/copyleft/gpl.html.
*
* This script is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/
use WapplerSystems\Meilisearch\Util;
use TYPO3\CMS\Core\Utility\DebugUtility;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Utility\DebuggerUtility;
/**
* The DebugWriter is used to write the devLog messages to the output of the page, or to the TYPO3 console in the
* backend to provide a simple and lightweigt debugging possibility.
*
* @author Timo Hund <timo.hund@dkd.de>
*/
class DebugWriter
{
/**
* When the feature is enabled with: plugin.tx_meilisearch.logging.debugOutput the log writer uses the extbase
* debug functionality in the frontend, or the console in the backend to display the devlog messages.
*
* @param int|string $level Log level. Value according to \TYPO3\CMS\Core\Log\LogLevel. Alternatively accepts a string.
* @param string $message Log message.
* @param array $data Additional data to log
*/
public function write($level, $message, $data = [])
{
$debugAllowedForIp = $this->getIsAllowedByDevIPMask();
if (!$debugAllowedForIp) {
return;
}
$isDebugOutputEnabled = $this->getIsDebugOutputEnabled();
if (!$isDebugOutputEnabled) {
return;
}
$this->writeDebugMessage($level, $message, $data);
}
/**
* @return bool
*/
protected function getIsAllowedByDevIPMask()
{
return GeneralUtility::cmpIP(GeneralUtility::getIndpEnv('REMOTE_ADDR'), $GLOBALS['TYPO3_CONF_VARS']['SYS']['devIPmask']);
}
/**
* Check if Logging via debugOutput has been configured
*
* @return bool
*/
protected function getIsDebugOutputEnabled()
{
return Util::getSolrConfiguration()->getLoggingDebugOutput();
}
/**
* @param int|string $level Log level. Value according to \TYPO3\CMS\Core\Log\LogLevel. Alternatively accepts a string.
* @param string $message Log message.
* @param array $data Additional data to log
*/
protected function writeDebugMessage($level, $message, $data)
{
$parameters = ['extKey' => 'meilisearch', 'msg' => $message, 'level' => $level, 'data' => $data];
$message = isset($parameters['msg']) ? $parameters['msg'] : '';
if (TYPO3_MODE === 'BE') {
DebugUtility::debug($parameters, $parameters['extKey'], 'DevLog ext:solr: ' . $message);
} else {
echo $message . ':<br/>';
DebuggerUtility::var_dump($parameters);
}
}
}

View File

@@ -0,0 +1,98 @@
<?php
namespace WapplerSystems\Meilisearch\System\Logging;
/***************************************************************
* Copyright notice
*
* (c) 2017 - Thomas Hohn <tho@systime.dk>
* All rights reserved
*
* This script is part of the TYPO3 project. The TYPO3 project is
* free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* The GNU General Public License can be found at
* http://www.gnu.org/copyleft/gpl.html.
*
* This script is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/
use WapplerSystems\Meilisearch\Util;
use TYPO3\CMS\Core\Log\LogLevel;
use TYPO3\CMS\Core\Log\LogManager;
use TYPO3\CMS\Core\Utility\GeneralUtility;
/**
* Wrapper to for the TYPO3 Logging Framework
*
* @author Thomas Hohn <tho@systime.dk>
*/
class SolrLogManager
{
const WARNING = LogLevel::WARNING;
const ERROR = LogLevel::ERROR;
const INFO = LogLevel::INFO;
const NOTICE = LogLevel::NOTICE;
/**
* @var \TYPO3\CMS\Core\Log\Logger
*/
protected $logger = null;
/**
* @var DebugWriter
*/
protected $debugWriter = null;
/**
* @var string
*/
protected $className = '';
/**
* SolrLogManager constructor.
*
* @param string $className
* @param DebugWriter $debugWriter
*/
public function __construct($className, DebugWriter $debugWriter = null)
{
$this->className = $className;
$this->debugWriter = $debugWriter ?? GeneralUtility::makeInstance(DebugWriter::class);
}
/**
* @return \TYPO3\CMS\Core\Log\Logger
*/
protected function getLogger()
{
if ($this->logger === null) {
$this->logger = GeneralUtility::makeInstance(LogManager::class)->getLogger($this->className);
}
return $this->logger;
}
/**
* Adds an entry to the LogManager
*
* @param int|string $level Log level. Value according to \TYPO3\CMS\Core\Log\LogLevel. Alternatively accepts a string.
* @param string $message Log message.
* @param array $data Additional data to log
*
* @return mixed
*/
public function log($level, $message, array $data = [])
{
$this->getLogger()->log($level, $message, $data);
$this->debugWriter->write($level, $message, $data);
}
}