oxid-sql-logger/src/OxidSQLLogger.php

69 lines
1.7 KiB
PHP
Raw Normal View History

2019-08-20 23:34:33 +02:00
<?php
2019-09-19 19:52:54 +02:00
2019-08-20 23:34:33 +02:00
/**
2019-09-19 19:52:54 +02:00
* @author Tobias Matthaiou <developer@tobimat.eu>
* @author D3 Data Development - Daniel Seifert <support@shopmodule.com>
2019-08-20 23:34:33 +02:00
*/
2019-09-19 19:52:54 +02:00
namespace D3\OxidSqlLogger;
2019-08-20 23:34:33 +02:00
use Doctrine\DBAL\Logging\SQLLogger;
use Monolog;
/**
* Class OxidSQLLogger
*/
class OxidSQLLogger implements SQLLogger
{
public $message;
public $logStartingFile;
public $logStartingLine;
public $logStartingClass;
public $logStartingFunction;
2019-08-20 23:34:33 +02:00
/**
* @inheritDoc
*/
public function __construct($file, $line, $class, $function, $message = null)
2019-08-20 23:34:33 +02:00
{
if (!Monolog\Registry::hasLogger('sql')) {
Monolog\Registry::addLogger((new LoggerFactory())->create('sql'));
2019-08-20 23:34:33 +02:00
}
$this->message = $message;
$this->logStartingFile = $file;
$this->logStartingLine = $line;
$this->logStartingClass = $class;
$this->logStartingFunction = $function;
2019-08-20 23:34:33 +02:00
}
/**
* @inheritDoc
*/
public function startQuery($sql, array $params = null, array $types = null)
{
2020-04-30 20:45:41 +02:00
$formatter = new Formatter();
Monolog\Registry::sql()->addDebug(
$this->message ? $this->message : $sql,
[
2020-04-30 20:45:41 +02:00
'query' => $formatter->format($sql),
'params' => $params,
'types' => $types,
'logStartingFile' => $this->logStartingFile,
'logStartingLine' => $this->logStartingLine,
'logStartingClass' => $this->logStartingClass,
'logStartingFunction' => $this->logStartingFunction,
]
);
2019-08-20 23:34:33 +02:00
}
/**
* @inheritDoc
*/
public function stopQuery()
{
}
}