Compare commits
6 Commits
Author | SHA1 | Date |
---|---|---|
Daniel Seifert | f6f9ddc7e7 | |
Daniel Seifert | 8397868fdf | |
Daniel Seifert | e6e772a2ce | |
Daniel Seifert | 001eafec6c | |
Daniel Seifert | 66a842db84 | |
Daniel Seifert | 806de37cc9 |
31
CHANGELOG.md
31
CHANGELOG.md
|
@ -4,7 +4,36 @@ All notable changes to this project will be documented in this file.
|
|||
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
||||
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
||||
|
||||
## [Unreleased]
|
||||
## [1.3.0] - 2021-03-02
|
||||
|
||||
### Fixed
|
||||
|
||||
- fix missing static methods
|
||||
|
||||
### Added
|
||||
|
||||
- add configurable FirePHP handler
|
||||
|
||||
---
|
||||
|
||||
## [1.2.2] - 2021-01-23
|
||||
|
||||
### Changed
|
||||
|
||||
- change static methods to non-static methods for better testable code
|
||||
- change line endings for easy patching
|
||||
|
||||
### Added
|
||||
|
||||
- add prepared statement generator
|
||||
|
||||
---
|
||||
|
||||
## [1.2.1] - 2020-05-01
|
||||
|
||||
### Fixed
|
||||
|
||||
- add missing autoload file item in composer.json
|
||||
|
||||
---
|
||||
|
||||
|
|
27
README.md
27
README.md
|
@ -30,6 +30,33 @@ CLI:
|
|||
|
||||
![Example CLI](https://raw.githubusercontent.com/d3datadevelopment/oxid-sql-logger/master/img/screenshot-cli.jpg)
|
||||
|
||||
## Configuration
|
||||
|
||||
Add the sections to the config.inc.php of the shop if needed:
|
||||
|
||||
```php
|
||||
$this->SqlLoggerGUIHandlers = [
|
||||
\Monolog\Handler\BrowserConsoleHandler::class,
|
||||
\D3\OxidSqlLogger\Handler\d3FirePHPHandler::class
|
||||
];
|
||||
```
|
||||
|
||||
Standard handlers are BrowserConsoleHandler and d3FirePHPHandler.
|
||||
|
||||
```php
|
||||
$this->SqlLoggerCLIHandlers = [
|
||||
...
|
||||
];
|
||||
```
|
||||
|
||||
Standard handler is StreamHandler.
|
||||
|
||||
```php
|
||||
$this->d3FirePHPOptions = [
|
||||
\D3\OxidSqlLogger\Handler\d3FirePHPHandler::ADD_TRACE
|
||||
];
|
||||
```
|
||||
|
||||
## Credits
|
||||
|
||||
Many thanks to [Tobias Matthaiou](https://github.com/TumTum/oxid-sql-logger) for his inspiration.
|
||||
|
|
|
@ -4,7 +4,8 @@
|
|||
"type": "library",
|
||||
"require": {
|
||||
"monolog/monolog": "^1",
|
||||
"nilportugues/sql-query-formatter": "^1.2.2"
|
||||
"nilportugues/sql-query-formatter": "^1.2.2",
|
||||
"firephp/firephp-core": "^0.5.3"
|
||||
},
|
||||
"license": "GPL-3.0",
|
||||
"autoload": {
|
||||
|
@ -23,7 +24,7 @@
|
|||
{
|
||||
"name": "D3 Data Development (Inh. Thomas Dartsch)",
|
||||
"email": "info@shopmodule.com",
|
||||
"homepage": "http://www.d3data.de"
|
||||
"homepage": "https://www.d3data.de"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
|
|
@ -0,0 +1,79 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* This Software is the property of Data Development and is protected
|
||||
* by copyright law - it is NOT Freeware.
|
||||
* Any unauthorized use of this software without a valid license
|
||||
* is a violation of the license agreement and will be prosecuted by
|
||||
* civil and criminal law.
|
||||
* http://www.shopmodule.com
|
||||
*
|
||||
* @copyright (C) D3 Data Development (Inh. Thomas Dartsch)
|
||||
* @author D3 Data Development - Daniel Seifert <support@shopmodule.com>
|
||||
* @link http://www.oxidmodule.com
|
||||
*/
|
||||
|
||||
namespace D3\OxidSqlLogger\Extensions;
|
||||
|
||||
use D3\OxidSqlLogger\Handler\d3FirePHPHandler;
|
||||
use D3\OxidSqlLogger\OxidSQLLogger;
|
||||
use Doctrine\DBAL\Connection;
|
||||
use \FirePHP;
|
||||
use Monolog\Handler\AbstractProcessingHandler;
|
||||
use Monolog\Logger;
|
||||
use OxidEsales\EshopCommunity\Core\Database\Adapter\Doctrine\Database;
|
||||
|
||||
class d3FirePHP extends FirePHP
|
||||
{
|
||||
/**
|
||||
* Gets singleton instance of FirePHP
|
||||
*
|
||||
* @param boolean $autoCreate
|
||||
* @return FirePHP
|
||||
*/
|
||||
public static function getInstance($autoCreate = false)
|
||||
{
|
||||
if ($autoCreate === true && !self::$instance) {
|
||||
self::init();
|
||||
}
|
||||
return self::$instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates FirePHP object and stores it for singleton access
|
||||
*
|
||||
* @return FirePHP
|
||||
*/
|
||||
public static function init()
|
||||
{
|
||||
return self::setInstance(new self());
|
||||
}
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
$this->ignoreClassInTraces(d3FirePHP::class);
|
||||
$this->ignoreClassInTraces(d3FirePHPHandler::class);
|
||||
$this->ignoreClassInTraces(Logger::class);
|
||||
$this->ignoreClassInTraces(AbstractProcessingHandler::class);
|
||||
$this->ignoreClassInTraces(OxidSQLLogger::class);
|
||||
$this->ignoreClassInTraces(Connection::class);
|
||||
$this->ignoreClassInTraces(Database::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Log a trace in the firebug console
|
||||
*
|
||||
* @see FirePHP::TRACE
|
||||
* @param string $label
|
||||
* @return true
|
||||
* @throws Exception
|
||||
*/
|
||||
public function trace($label)
|
||||
{
|
||||
return $this->fb($label, $label, FirePHP::TRACE, array(
|
||||
'trace' => debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS)
|
||||
));
|
||||
}
|
||||
}
|
|
@ -0,0 +1,43 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* This Software is the property of Data Development and is protected
|
||||
* by copyright law - it is NOT Freeware.
|
||||
* Any unauthorized use of this software without a valid license
|
||||
* is a violation of the license agreement and will be prosecuted by
|
||||
* civil and criminal law.
|
||||
* http://www.shopmodule.com
|
||||
*
|
||||
* @copyright (C) D3 Data Development (Inh. Thomas Dartsch)
|
||||
* @author D3 Data Development - Daniel Seifert <support@shopmodule.com>
|
||||
* @link http://www.oxidmodule.com
|
||||
*/
|
||||
|
||||
namespace D3\OxidSqlLogger\Handler;
|
||||
|
||||
use D3\OxidSqlLogger\Extensions\d3FirePHP;
|
||||
use OxidEsales\Eshop\Core\Registry;
|
||||
|
||||
class d3FirePHPHandler extends \Monolog\Handler\AbstractProcessingHandler
|
||||
{
|
||||
const ADD_TRACE = 'addTrace';
|
||||
|
||||
protected function write(array $record): void
|
||||
{
|
||||
$options = Registry::getConfig()->getConfigParam(d3FirePHPOptions);
|
||||
$options = isset($options) && is_array($options) ? $options : [];
|
||||
|
||||
$fp = d3FirePHP::getInstance(true);
|
||||
|
||||
if (in_array(self::ADD_TRACE, $options)) {
|
||||
$fp->group( $record['message'], [ 'Collapsed' => true ] );
|
||||
}
|
||||
|
||||
$fp->log( $record['formatted'], $record['message']);
|
||||
|
||||
if (in_array(self::ADD_TRACE, $options)) {
|
||||
$fp->trace( 'trace', 'trace' );
|
||||
$fp->groupEnd();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -8,6 +8,7 @@
|
|||
namespace D3\OxidSqlLogger;
|
||||
|
||||
use Monolog;
|
||||
use OxidEsales\Eshop\Core\Registry;
|
||||
use Symfony\Component\Console\Formatter\OutputFormatterStyle;
|
||||
|
||||
/**
|
||||
|
@ -29,16 +30,56 @@ class LoggerFactory
|
|||
*/
|
||||
private function getHandlers()
|
||||
{
|
||||
$handlers = [];
|
||||
if (PHP_SAPI == 'cli') {
|
||||
$handlers[] = $this->getStreamHandler();
|
||||
$configuredHandlers = Registry::getConfig()->getConfigParam('SqlLoggerCLIHandlers');
|
||||
|
||||
$handlers = (isset($configuredHandlers) && $this->is_iterable($configuredHandlers)) ?
|
||||
$this->getInstancesFromHandlerList($configuredHandlers) :
|
||||
[
|
||||
$this->getStreamHandler()
|
||||
];
|
||||
} else {
|
||||
$handlers[] = $this->getBrowserConsoleHandler();
|
||||
$handlers[] = $this->getFirePHPHandler();
|
||||
$configuredHandlers = Registry::getConfig()->getConfigParam('SqlLoggerGUIHandlers');
|
||||
|
||||
$handlers = (isset($configuredHandlers) && $this->is_iterable($configuredHandlers)) ?
|
||||
$this->getInstancesFromHandlerList($configuredHandlers) :
|
||||
[
|
||||
$this->getBrowserConsoleHandler(),
|
||||
$this->getFirePHPHandler()
|
||||
];
|
||||
}
|
||||
|
||||
return $handlers;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $classNames
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private function getInstancesFromHandlerList(array $classNames)
|
||||
{
|
||||
return array_map(
|
||||
function($className){
|
||||
return new $className();
|
||||
},
|
||||
$classNames
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* polyfill for is_iterable() - available from PHP 7.1
|
||||
* @param $obj
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
private function is_iterable($obj)
|
||||
{
|
||||
return function_exists('is_iterable') ?
|
||||
is_iterable($obj) :
|
||||
is_array($obj) || (is_object($obj) && ($obj instanceof \Traversable));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Monolog\Handler\StreamHandler
|
||||
*/
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
namespace D3\OxidSqlLogger;
|
||||
|
||||
use Doctrine\DBAL\Configuration;
|
||||
use Doctrine\DBAL\Logging\SQLLogger;
|
||||
|
||||
/**
|
||||
* Class OxidEsalesDatabase
|
||||
|
@ -15,6 +16,18 @@ use Doctrine\DBAL\Configuration;
|
|||
*/
|
||||
class OxidEsalesDatabase extends \OxidEsales\Eshop\Core\Database\Adapter\Doctrine\Database
|
||||
{
|
||||
/**
|
||||
* @param null $message
|
||||
*
|
||||
* @throws \OxidEsales\Eshop\Core\Exception\DatabaseConnectionException
|
||||
* @deprecated use non static d3EnableLogger method or D3StartSQLLog function
|
||||
*/
|
||||
public static function enableLogger($message = null)
|
||||
{
|
||||
$database = oxNew(OxidEsalesDatabase::class);
|
||||
$database->d3EnableLogger($message);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws \OxidEsales\Eshop\Core\Exception\DatabaseConnectionException
|
||||
*/
|
||||
|
@ -23,6 +36,7 @@ class OxidEsalesDatabase extends \OxidEsales\Eshop\Core\Database\Adapter\Doctrin
|
|||
$trace = debug_backtrace((PHP_VERSION_ID < 50306) ? 2 : DEBUG_BACKTRACE_IGNORE_ARGS);
|
||||
|
||||
$database = \OxidEsales\Eshop\Core\DatabaseProvider::getDb(\OxidEsales\Eshop\Core\DatabaseProvider::FETCH_MODE_ASSOC);
|
||||
/** @var Configuration $dbalConfig */
|
||||
$dbalConfig = $database->getConnection()->getConfiguration();
|
||||
$dbalConfig->setSQLLogger(
|
||||
new OxidSQLLogger(
|
||||
|
@ -36,22 +50,45 @@ class OxidEsalesDatabase extends \OxidEsales\Eshop\Core\Database\Adapter\Doctrin
|
|||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
* @return SQLLogger|null
|
||||
* @throws \OxidEsales\Eshop\Core\Exception\DatabaseConnectionException
|
||||
* @deprecated use non static d3GetLogger method
|
||||
*/
|
||||
public static function getLogger()
|
||||
{
|
||||
$database = oxNew(OxidEsalesDatabase::class);
|
||||
return $database->d3GetLogger();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return SQLLogger|null
|
||||
* @throws \OxidEsales\Eshop\Core\Exception\DatabaseConnectionException
|
||||
*/
|
||||
public function d3GetLogger()
|
||||
{
|
||||
$database = \OxidEsales\Eshop\Core\DatabaseProvider::getDb(\OxidEsales\Eshop\Core\DatabaseProvider::FETCH_MODE_ASSOC);
|
||||
/** @var Configuration $dbalConfig */
|
||||
$dbalConfig = $database->getConnection()->getConfiguration();
|
||||
return $dbalConfig->getSQLLogger();
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws \OxidEsales\Eshop\Core\Exception\DatabaseConnectionException
|
||||
* @deprecated use non static d3DisableLogger method or D3StopSQLLog function
|
||||
*/
|
||||
public static function disableLogger()
|
||||
{
|
||||
$database = oxNew(OxidEsalesDatabase::class);
|
||||
$database->d3DisableLogger();
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws \OxidEsales\Eshop\Core\Exception\DatabaseConnectionException
|
||||
*/
|
||||
public function d3DisableLogger()
|
||||
{
|
||||
$database = \OxidEsales\Eshop\Core\DatabaseProvider::getDb(\OxidEsales\Eshop\Core\DatabaseProvider::FETCH_MODE_ASSOC);
|
||||
/** @var Configuration $dbalConfig */
|
||||
$dbalConfig = $database->getConnection()->getConfiguration();
|
||||
$dbalConfig->setSQLLogger(null);
|
||||
}
|
||||
|
|
|
@ -17,3 +17,11 @@ function D3StopSQLLog()
|
|||
$database = oxNew(\D3\OxidSqlLogger\OxidEsalesDatabase::class);
|
||||
$database->d3DisableLogger();
|
||||
}
|
||||
|
||||
function D3AddSQLLogItem($message)
|
||||
{
|
||||
/** @var \D3\OxidSqlLogger\OxidEsalesDatabase $database */
|
||||
$database = oxNew(\D3\OxidSqlLogger\OxidEsalesDatabase::class);
|
||||
$database->d3GetLogger()->startQuery($message);
|
||||
$database->d3GetLogger()->stopQuery($message);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue