Compare commits
6 Commits
Author | SHA1 | Date | |
---|---|---|---|
2b6ab8f809
|
|||
c37768f2fa
|
|||
6327bfb06d
|
|||
a57605a729
|
|||
9b1a1b24ed
|
|||
b76507025e
|
47
CHANGELOG.md
47
CHANGELOG.md
@ -4,62 +4,53 @@ 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).
|
||||
|
||||
## [1.3.0] - 2021-03-02
|
||||
## [Unreleased](https://git.d3data.de/D3Public/oxid-sql-logger/compare/1.3.3...master)
|
||||
|
||||
## [1.3.3](https://git.d3data.de/D3Public/oxid-sql-logger/compare/1.3.2...1.3.3) - 2022-09-05
|
||||
### Fixed
|
||||
- fix argument error if no parameter list was set in stopDebug
|
||||
|
||||
## [1.3.2](https://git.d3data.de/D3Public/oxid-sql-logger/compare/1.3.1...1.3.2) - 2022-07-18
|
||||
### Fixed
|
||||
- fix some code style issues
|
||||
|
||||
## [1.3.1](https://git.d3data.de/D3Public/oxid-sql-logger/compare/1.3.0...1.3.1) - 2021-04-29
|
||||
### Fixed
|
||||
- prevent the use of not countable parameters in prepared statemant rendering
|
||||
|
||||
## [1.3.0](https://git.d3data.de/D3Public/oxid-sql-logger/compare/1.2.2...1.3.0) - 2021-03-02
|
||||
### Fixed
|
||||
- fix missing static methods
|
||||
|
||||
### Added
|
||||
|
||||
- add configurable FirePHP handler
|
||||
|
||||
---
|
||||
|
||||
## [1.2.2] - 2021-01-23
|
||||
|
||||
## [1.2.2](https://git.d3data.de/D3Public/oxid-sql-logger/compare/1.2.1...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
|
||||
|
||||
## [1.2.1](https://git.d3data.de/D3Public/oxid-sql-logger/compare/1.2.0...1.2.1) - 2020-05-01
|
||||
### Fixed
|
||||
|
||||
- add missing autoload file item in composer.json
|
||||
|
||||
---
|
||||
|
||||
## [1.2.0] - 2020-04-30
|
||||
|
||||
## [1.2.0](https://git.d3data.de/D3Public/oxid-sql-logger/compare/1.1.0...1.2.0) - 2020-04-30
|
||||
### Added
|
||||
|
||||
- Format SQL query
|
||||
- Measures the SQL execution time
|
||||
|
||||
---
|
||||
|
||||
## [1.1.0] - 2019-09-20
|
||||
|
||||
## [1.1.0](https://git.d3data.de/D3Public/oxid-sql-logger/compare/1.0.0...1.1.0) - 2019-09-20
|
||||
### Added
|
||||
|
||||
- add log message
|
||||
- add position specifications of the calling source code
|
||||
|
||||
---
|
||||
|
||||
## [1.0.0] - 2019-07-21
|
||||
## [1.0.0](https://git.d3data.de/D3Public/oxid-sql-logger/releases/tag/1.0.0) - 2019-07-21
|
||||
|
||||
available in tumtum/oxid-sql-logger package only
|
||||
|
||||
### Added
|
||||
|
||||
- Global function `StartSQLLog` and `StopSQLLog`
|
||||
- Display SQL Querys on Browser or CLI
|
||||
- Display SQL Querys on Browser or CLI
|
@ -1,19 +1,21 @@
|
||||
<?php
|
||||
|
||||
use OxidEsales\Eshop\Core\DatabaseProvider;
|
||||
|
||||
require __DIR__ . '/../../../../source/bootstrap.php';
|
||||
|
||||
\D3StartSQLLog('Query for 100 items cheaper than 49,99');
|
||||
D3StartSQLLog( 'Query for 100 items cheaper than 49,99');
|
||||
|
||||
$db = \OxidEsales\Eshop\Core\DatabaseProvider::getDb(\OxidEsales\Eshop\Core\DatabaseProvider::FETCH_MODE_ASSOC);
|
||||
$db = DatabaseProvider::getDb( DatabaseProvider::FETCH_MODE_ASSOC);
|
||||
$list = $db->getAll('SELECT * '.PHP_EOL.'FROM oxarticles WHERE oxprice < ? LIMIT 100', [49.99]);
|
||||
|
||||
\D3StopSQLLog();
|
||||
D3StopSQLLog();
|
||||
|
||||
// or
|
||||
|
||||
\D3StartSQLLog();
|
||||
D3StartSQLLog();
|
||||
|
||||
$db = \OxidEsales\Eshop\Core\DatabaseProvider::getDb(\OxidEsales\Eshop\Core\DatabaseProvider::FETCH_MODE_ASSOC);
|
||||
$db = DatabaseProvider::getDb( DatabaseProvider::FETCH_MODE_ASSOC);
|
||||
$list = $db->getAll('SELECT * FROM oxarticles WHERE oxprice < ? LIMIT 100', [49.99]);
|
||||
|
||||
\D3StopSQLLog();
|
||||
D3StopSQLLog();
|
||||
|
@ -18,7 +18,8 @@ namespace D3\OxidSqlLogger\Extensions;
|
||||
use D3\OxidSqlLogger\Handler\d3FirePHPHandler;
|
||||
use D3\OxidSqlLogger\OxidSQLLogger;
|
||||
use Doctrine\DBAL\Connection;
|
||||
use \FirePHP;
|
||||
use Exception;
|
||||
use FirePHP;
|
||||
use Monolog\Handler\AbstractProcessingHandler;
|
||||
use Monolog\Logger;
|
||||
use OxidEsales\EshopCommunity\Core\Database\Adapter\Doctrine\Database;
|
||||
|
@ -16,15 +16,22 @@
|
||||
namespace D3\OxidSqlLogger\Handler;
|
||||
|
||||
use D3\OxidSqlLogger\Extensions\d3FirePHP;
|
||||
use Exception;
|
||||
use Monolog\Handler\AbstractProcessingHandler;
|
||||
use OxidEsales\Eshop\Core\Registry;
|
||||
|
||||
class d3FirePHPHandler extends \Monolog\Handler\AbstractProcessingHandler
|
||||
class d3FirePHPHandler extends AbstractProcessingHandler
|
||||
{
|
||||
const ADD_TRACE = 'addTrace';
|
||||
|
||||
|
||||
/**
|
||||
* @param array $record
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
protected function write(array $record): void
|
||||
{
|
||||
$options = Registry::getConfig()->getConfigParam(d3FirePHPOptions);
|
||||
$options = Registry::getConfig()->getConfigParam('d3FirePHPOptions');
|
||||
$options = isset($options) && is_array($options) ? $options : [];
|
||||
|
||||
$fp = d3FirePHP::getInstance(true);
|
||||
@ -36,7 +43,7 @@ class d3FirePHPHandler extends \Monolog\Handler\AbstractProcessingHandler
|
||||
$fp->log( $record['formatted'], $record['message']);
|
||||
|
||||
if (in_array(self::ADD_TRACE, $options)) {
|
||||
$fp->trace( 'trace', 'trace' );
|
||||
$fp->trace( 'trace');
|
||||
$fp->groupEnd();
|
||||
}
|
||||
}
|
||||
|
@ -10,6 +10,7 @@ namespace D3\OxidSqlLogger;
|
||||
use Monolog;
|
||||
use OxidEsales\Eshop\Core\Registry;
|
||||
use Symfony\Component\Console\Formatter\OutputFormatterStyle;
|
||||
use Traversable;
|
||||
|
||||
/**
|
||||
* Class Factory
|
||||
@ -77,7 +78,7 @@ class LoggerFactory
|
||||
{
|
||||
return function_exists('is_iterable') ?
|
||||
is_iterable($obj) :
|
||||
is_array($obj) || (is_object($obj) && ($obj instanceof \Traversable));
|
||||
is_array($obj) || ( $obj instanceof Traversable);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -93,7 +94,7 @@ class LoggerFactory
|
||||
$context = (new OutputFormatterStyle('yellow'))->apply('%context%');
|
||||
$newline = PHP_EOL . str_repeat(' ', 10);
|
||||
|
||||
$ttl_color = "$channel $level_name: $message {$newline} $context {$newline} %extra%" . PHP_EOL;
|
||||
$ttl_color = "$channel $level_name: $message $newline $context $newline %extra%" . PHP_EOL;
|
||||
|
||||
$streamHandler->setFormatter(
|
||||
new Monolog\Formatter\LineFormatter(
|
||||
|
@ -9,17 +9,20 @@ namespace D3\OxidSqlLogger;
|
||||
|
||||
use Doctrine\DBAL\Configuration;
|
||||
use Doctrine\DBAL\Logging\SQLLogger;
|
||||
use OxidEsales\Eshop\Core\Database\Adapter\Doctrine\Database;
|
||||
use OxidEsales\Eshop\Core\DatabaseProvider;
|
||||
use OxidEsales\Eshop\Core\Exception\DatabaseConnectionException;
|
||||
|
||||
/**
|
||||
* Class OxidEsalesDatabase
|
||||
* Is a depenction injection Helper Class
|
||||
*/
|
||||
class OxidEsalesDatabase extends \OxidEsales\Eshop\Core\Database\Adapter\Doctrine\Database
|
||||
class OxidEsalesDatabase extends Database
|
||||
{
|
||||
/**
|
||||
* @param null $message
|
||||
*
|
||||
* @throws \OxidEsales\Eshop\Core\Exception\DatabaseConnectionException
|
||||
* @throws DatabaseConnectionException
|
||||
* @deprecated use non static d3EnableLogger method or D3StartSQLLog function
|
||||
*/
|
||||
public static function enableLogger($message = null)
|
||||
@ -29,21 +32,21 @@ class OxidEsalesDatabase extends \OxidEsales\Eshop\Core\Database\Adapter\Doctrin
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws \OxidEsales\Eshop\Core\Exception\DatabaseConnectionException
|
||||
* @throws DatabaseConnectionException
|
||||
*/
|
||||
public function d3EnableLogger($message)
|
||||
{
|
||||
$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);
|
||||
$database = DatabaseProvider::getDb( DatabaseProvider::FETCH_MODE_ASSOC);
|
||||
/** @var Configuration $dbalConfig */
|
||||
$dbalConfig = $database->getConnection()->getConfiguration();
|
||||
$dbalConfig->setSQLLogger(
|
||||
new OxidSQLLogger(
|
||||
isset($trace[1]['file']) ? $trace[1]['file'] : null,
|
||||
isset($trace[1]['line']) ? $trace[1]['line'] : null,
|
||||
isset($trace[2]['class']) ? $trace[2]['class'] : null,
|
||||
isset($trace[2]['function']) ? $trace[2]['function'] : null,
|
||||
$trace[1]['file'] ?? null,
|
||||
$trace[1]['line'] ?? null,
|
||||
$trace[2]['class'] ?? null,
|
||||
$trace[2]['function'] ?? null,
|
||||
$message
|
||||
)
|
||||
);
|
||||
@ -51,7 +54,7 @@ class OxidEsalesDatabase extends \OxidEsales\Eshop\Core\Database\Adapter\Doctrin
|
||||
|
||||
/**
|
||||
* @return SQLLogger|null
|
||||
* @throws \OxidEsales\Eshop\Core\Exception\DatabaseConnectionException
|
||||
* @throws DatabaseConnectionException
|
||||
* @deprecated use non static d3GetLogger method
|
||||
*/
|
||||
public static function getLogger()
|
||||
@ -62,18 +65,18 @@ class OxidEsalesDatabase extends \OxidEsales\Eshop\Core\Database\Adapter\Doctrin
|
||||
|
||||
/**
|
||||
* @return SQLLogger|null
|
||||
* @throws \OxidEsales\Eshop\Core\Exception\DatabaseConnectionException
|
||||
* @throws DatabaseConnectionException
|
||||
*/
|
||||
public function d3GetLogger()
|
||||
{
|
||||
$database = \OxidEsales\Eshop\Core\DatabaseProvider::getDb(\OxidEsales\Eshop\Core\DatabaseProvider::FETCH_MODE_ASSOC);
|
||||
$database = DatabaseProvider::getDb( DatabaseProvider::FETCH_MODE_ASSOC);
|
||||
/** @var Configuration $dbalConfig */
|
||||
$dbalConfig = $database->getConnection()->getConfiguration();
|
||||
return $dbalConfig->getSQLLogger();
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws \OxidEsales\Eshop\Core\Exception\DatabaseConnectionException
|
||||
* @throws DatabaseConnectionException
|
||||
* @deprecated use non static d3DisableLogger method or D3StopSQLLog function
|
||||
*/
|
||||
public static function disableLogger()
|
||||
@ -83,13 +86,13 @@ class OxidEsalesDatabase extends \OxidEsales\Eshop\Core\Database\Adapter\Doctrin
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws \OxidEsales\Eshop\Core\Exception\DatabaseConnectionException
|
||||
* @throws DatabaseConnectionException
|
||||
*/
|
||||
public function d3DisableLogger()
|
||||
{
|
||||
$database = \OxidEsales\Eshop\Core\DatabaseProvider::getDb(\OxidEsales\Eshop\Core\DatabaseProvider::FETCH_MODE_ASSOC);
|
||||
$database = DatabaseProvider::getDb( DatabaseProvider::FETCH_MODE_ASSOC);
|
||||
/** @var Configuration $dbalConfig */
|
||||
$dbalConfig = $database->getConnection()->getConfiguration();
|
||||
$dbalConfig->setSQLLogger(null);
|
||||
$dbalConfig->setSQLLogger();
|
||||
}
|
||||
}
|
||||
|
@ -11,6 +11,7 @@ use D3\ModCfg\Application\Model\d3database;
|
||||
use Doctrine\DBAL\Logging\SQLLogger;
|
||||
use Monolog;
|
||||
use NilPortugues\Sql\QueryFormatter\Formatter;
|
||||
use OxidEsales\Eshop\Core\Exception\DatabaseConnectionException;
|
||||
|
||||
/**
|
||||
* Class OxidSQLLogger
|
||||
@ -29,7 +30,11 @@ class OxidSQLLogger implements SQLLogger
|
||||
private $SQLQuery = null;
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
* @param $file
|
||||
* @param $line
|
||||
* @param $class
|
||||
* @param $function
|
||||
* @param null $message
|
||||
*/
|
||||
public function __construct($file, $line, $class, $function, $message = null)
|
||||
{
|
||||
@ -45,7 +50,11 @@ class OxidSQLLogger implements SQLLogger
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
* @param string $sql
|
||||
* @param array|null $params
|
||||
* @param array|null $types
|
||||
*
|
||||
* @throws DatabaseConnectionException
|
||||
*/
|
||||
public function startQuery($sql, array $params = null, array $types = null)
|
||||
{
|
||||
@ -54,7 +63,7 @@ class OxidSQLLogger implements SQLLogger
|
||||
$this->stopQuery();
|
||||
}
|
||||
|
||||
$this->getPreparedStatementQuery($sql, $params);
|
||||
$this->getPreparedStatementQuery($sql, $params ?? []);
|
||||
|
||||
$this->SQLQuery = (new SQLQuery()) ->setSql($sql)
|
||||
->setParams($params)
|
||||
@ -68,12 +77,13 @@ class OxidSQLLogger implements SQLLogger
|
||||
/**
|
||||
* @param string $sql
|
||||
* @param array $params
|
||||
* @throws \OxidEsales\Eshop\Core\Exception\DatabaseConnectionException
|
||||
* @throws DatabaseConnectionException
|
||||
*/
|
||||
public function getPreparedStatementQuery(&$sql, array $params = null)
|
||||
public function getPreparedStatementQuery(&$sql, array $params = [])
|
||||
{
|
||||
if (class_exists(d3database::class)
|
||||
&& method_exists(d3database::class, 'getPreparedStatementQuery')
|
||||
&& is_array($params)
|
||||
&& count($params)
|
||||
&& ($query = d3database::getInstance()->getPreparedStatementQuery($sql, $params))
|
||||
&& strlen(trim($query))
|
||||
@ -91,7 +101,7 @@ class OxidSQLLogger implements SQLLogger
|
||||
$formatter = new Formatter();
|
||||
|
||||
Monolog\Registry::sql()->addDebug(
|
||||
'['.$this->SQLQuery->getReadableElapsedTime().'] ' . ( $this->message ? $this->message : $this->SQLQuery->getSql() ),
|
||||
'['.$this->SQLQuery->getReadableElapsedTime().'] ' . ( $this->message ?: $this->SQLQuery->getSql() ),
|
||||
[
|
||||
'query' => $formatter->format($this->SQLQuery->getSql()),
|
||||
'params' => $this->SQLQuery->getParams(),
|
||||
|
@ -16,7 +16,7 @@ class SQLQuery
|
||||
/**
|
||||
* @var float|null
|
||||
*/
|
||||
private $start_time = null;
|
||||
private $start_time;
|
||||
|
||||
/**
|
||||
* @var float|null
|
||||
@ -46,9 +46,6 @@ class SQLQuery
|
||||
|
||||
private $logStartingFunction;
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->start_time = microtime(true);
|
||||
@ -224,6 +221,7 @@ class SQLQuery
|
||||
*
|
||||
* @param float $microtime
|
||||
* @param string $format The format to display (printf format)
|
||||
* @param int $round
|
||||
* @return string
|
||||
*/
|
||||
private function readableElapsedTime($microtime, $format = '%.3f%s', $round = 3)
|
||||
|
@ -1,27 +1,43 @@
|
||||
<?php
|
||||
|
||||
use D3\OxidSqlLogger\OxidEsalesDatabase;
|
||||
use OxidEsales\Eshop\Core\Exception\DatabaseConnectionException;
|
||||
|
||||
/**
|
||||
* @author Tobias Matthaiou <developer@tobimat.eu>
|
||||
* @author D3 Data Development - Daniel Seifert <support@shopmodule.com>
|
||||
*/
|
||||
|
||||
/**
|
||||
* @param string $message
|
||||
*
|
||||
* @throws DatabaseConnectionException
|
||||
*/
|
||||
function D3StartSQLLog($message = null) {
|
||||
/** @var \D3\OxidSqlLogger\OxidEsalesDatabase $database */
|
||||
$database = oxNew(\D3\OxidSqlLogger\OxidEsalesDatabase::class);
|
||||
/** @var OxidEsalesDatabase $database */
|
||||
$database = oxNew( OxidEsalesDatabase::class);
|
||||
$database->d3EnableLogger($message);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws DatabaseConnectionException
|
||||
*/
|
||||
function D3StopSQLLog()
|
||||
{
|
||||
/** @var \D3\OxidSqlLogger\OxidEsalesDatabase $database */
|
||||
$database = oxNew(\D3\OxidSqlLogger\OxidEsalesDatabase::class);
|
||||
/** @var OxidEsalesDatabase $database */
|
||||
$database = oxNew( OxidEsalesDatabase::class);
|
||||
$database->d3DisableLogger();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $message
|
||||
*
|
||||
* @throws DatabaseConnectionException
|
||||
*/
|
||||
function D3AddSQLLogItem($message)
|
||||
{
|
||||
/** @var \D3\OxidSqlLogger\OxidEsalesDatabase $database */
|
||||
$database = oxNew(\D3\OxidSqlLogger\OxidEsalesDatabase::class);
|
||||
/** @var OxidEsalesDatabase $database */
|
||||
$database = oxNew( OxidEsalesDatabase::class);
|
||||
$database->d3GetLogger()->startQuery($message);
|
||||
$database->d3GetLogger()->stopQuery($message);
|
||||
$database->d3GetLogger()->stopQuery();
|
||||
}
|
||||
|
Reference in New Issue
Block a user