add headline and information about calling script, add logger getter

Cette révision appartient à :
Daniel Seifert 2019-09-19 16:03:06 +02:00
Parent 35270ae271
révision 156429f7ea
3 fichiers modifiés avec 34 ajouts et 6 suppressions

Voir le fichier

@ -17,11 +17,22 @@ use Doctrine\DBAL\Configuration;
*/
class OxidEsalesDatabase extends \OxidEsales\Eshop\Core\Database\Adapter\Doctrine\Database
{
public static function enableLogger()
public static function enableLogger($message = null, $file = null, $line = null)
{
$database = \OxidEsales\Eshop\Core\DatabaseProvider::getDb(\OxidEsales\Eshop\Core\DatabaseProvider::FETCH_MODE_ASSOC);
$dbalConfig = $database->getConnection()->getConfiguration();
$dbalConfig->setSQLLogger(new OxidSQLLogger());
$dbalConfig->setSQLLogger(new OxidSQLLogger($message, $file, $line));
}
/**
* @return OxidSQLLogger
* @throws \OxidEsales\Eshop\Core\Exception\DatabaseConnectionException
*/
public static function getLogger()
{
$database = \OxidEsales\Eshop\Core\DatabaseProvider::getDb(\OxidEsales\Eshop\Core\DatabaseProvider::FETCH_MODE_ASSOC);
$dbalConfig = $database->getConnection()->getConfiguration();
return $dbalConfig->getSQLLogger();
}
public static function disableLogger()

Voir le fichier

@ -16,14 +16,22 @@ use Monolog;
*/
class OxidSQLLogger implements SQLLogger
{
public $message;
public $file;
public $line;
/**
* @inheritDoc
*/
public function __construct()
public function __construct($message = null, $file = null, $line = null)
{
if (!Monolog\Registry::hasLogger('sql')) {
Monolog\Registry::addLogger((new LoggerFactory())->create('sql'));
}
$this->message = $message;
$this->file = $file;
$this->line = $line;
}
/**
@ -31,7 +39,16 @@ class OxidSQLLogger implements SQLLogger
*/
public function startQuery($sql, array $params = null, array $types = null)
{
Monolog\Registry::sql()->addDebug($sql, ['params' => $params, 'types' => $types]);
Monolog\Registry::sql()->addDebug(
$this->message,
[
'query' => $sql,
'params' => $params,
'types' => $types,
'calling_file' => $this->file,
'calling_line' => $this->line,
]
);
}
/**

Voir le fichier

@ -5,8 +5,8 @@
* Time: 23:11
*/
function StartSQLLog() {
\tm\oxid\sql\logger\OxidEsalesDatabase::enableLogger();
function StartSQLLog($message = null, $file = null, $line = null) {
\tm\oxid\sql\logger\OxidEsalesDatabase::enableLogger($message, $file, $line);
}
function StopSQLLog() {