Feat: Override core logger to add timestamps without microseconds

This commit is contained in:
Björn Fromme
2023-07-06 11:19:48 +02:00
parent 5143427ca4
commit fa79ef8c80
6 changed files with 335 additions and 282 deletions
@@ -97,7 +97,7 @@ class SearchController extends ActionController
if (in_array($remoteIp, $ignoreIps)) {
return;
}
/** @var $logger \TYPO3\CMS\Core\Log\Logger */
$logger = GeneralUtility::makeInstance(LogManager::class)->getLogger(__CLASS__);
$logger->info('Searchresult processed', [
'search' => $search->getQuery(),
@@ -166,7 +166,7 @@ call_user_func(function() {
$GLOBALS['TYPO3_CONF_VARS']['LOG']['EP']['EpEvents']['Controller']['writerConfiguration'] = [
\TYPO3\CMS\Core\Log\LogLevel::INFO => [
\TYPO3\CMS\Core\Log\Writer\DatabaseWriter::class => [
\EP\EpProducts\Log\Writer::class => [
'logTable' => 'tx_epevents_log'
],
],
+38 -26
View File
@@ -1,7 +1,8 @@
#
# Table structure for table 'tx_epevents_domain_model_traveltype'
#
CREATE TABLE tx_epevents_domain_model_traveltype (
CREATE TABLE tx_epevents_domain_model_traveltype
(
uid int(11) NOT NULL auto_increment,
pid int(11) DEFAULT '0' NOT NULL,
@@ -41,15 +42,16 @@ CREATE TABLE tx_epevents_domain_model_traveltype (
PRIMARY KEY (uid),
KEY parent (pid),
KEY t3ver_oid (t3ver_oid,t3ver_wsid),
KEY language (l10n_parent,sys_language_uid)
KEY t3ver_oid (t3ver_oid, t3ver_wsid),
KEY language (l10n_parent, sys_language_uid)
);
#
# Table structure for table 'tx_epevents_domain_model_offer'
#
CREATE TABLE tx_epevents_domain_model_offer (
CREATE TABLE tx_epevents_domain_model_offer
(
uid int(11) NOT NULL auto_increment,
pid int(11) DEFAULT '0' NOT NULL,
@@ -104,15 +106,16 @@ CREATE TABLE tx_epevents_domain_model_offer (
PRIMARY KEY (uid),
KEY parent (pid),
KEY t3ver_oid (t3ver_oid,t3ver_wsid),
KEY language (l10n_parent,sys_language_uid)
KEY t3ver_oid (t3ver_oid, t3ver_wsid),
KEY language (l10n_parent, sys_language_uid)
);
#
# Table structure for table 'tx_epevents_domain_model_location'
#
CREATE TABLE tx_epevents_domain_model_location (
CREATE TABLE tx_epevents_domain_model_location
(
uid int(11) NOT NULL auto_increment,
pid int(11) DEFAULT '0' NOT NULL,
@@ -154,15 +157,16 @@ CREATE TABLE tx_epevents_domain_model_location (
PRIMARY KEY (uid),
KEY parent (pid),
KEY t3ver_oid (t3ver_oid,t3ver_wsid),
KEY language (l10n_parent,sys_language_uid)
KEY t3ver_oid (t3ver_oid, t3ver_wsid),
KEY language (l10n_parent, sys_language_uid)
);
#
# Table structure for table 'tx_epevents_domain_model_hotel'
#
CREATE TABLE tx_epevents_domain_model_hotel (
CREATE TABLE tx_epevents_domain_model_hotel
(
uid int(11) NOT NULL auto_increment,
pid int(11) DEFAULT '0' NOT NULL,
@@ -198,15 +202,16 @@ CREATE TABLE tx_epevents_domain_model_hotel (
PRIMARY KEY (uid),
KEY parent (pid),
KEY t3ver_oid (t3ver_oid,t3ver_wsid),
KEY language (l10n_parent,sys_language_uid)
KEY t3ver_oid (t3ver_oid, t3ver_wsid),
KEY language (l10n_parent, sys_language_uid)
);
#
# Table structure for table 'tx_epevents_domain_model_activity'
#
CREATE TABLE tx_epevents_domain_model_activity (
CREATE TABLE tx_epevents_domain_model_activity
(
uid int(11) NOT NULL auto_increment,
pid int(11) DEFAULT '0' NOT NULL,
@@ -247,15 +252,16 @@ CREATE TABLE tx_epevents_domain_model_activity (
PRIMARY KEY (uid),
KEY parent (pid),
KEY t3ver_oid (t3ver_oid,t3ver_wsid),
KEY language (l10n_parent,sys_language_uid)
KEY t3ver_oid (t3ver_oid, t3ver_wsid),
KEY language (l10n_parent, sys_language_uid)
);
#
# Table structure for table 'tx_epevents_domain_model_contact'
#
CREATE TABLE tx_epevents_domain_model_contact (
CREATE TABLE tx_epevents_domain_model_contact
(
uid int(11) NOT NULL auto_increment,
pid int(11) DEFAULT '0' NOT NULL,
@@ -291,15 +297,16 @@ CREATE TABLE tx_epevents_domain_model_contact (
PRIMARY KEY (uid),
KEY parent (pid),
KEY t3ver_oid (t3ver_oid,t3ver_wsid),
KEY language (l10n_parent,sys_language_uid)
KEY t3ver_oid (t3ver_oid, t3ver_wsid),
KEY language (l10n_parent, sys_language_uid)
);
#
# Table structure for table 'tx_epevents_domain_model_testimonial'
#
CREATE TABLE tx_epevents_domain_model_testimonial (
CREATE TABLE tx_epevents_domain_model_testimonial
(
uid int(11) NOT NULL auto_increment,
pid int(11) DEFAULT '0' NOT NULL,
@@ -332,15 +339,16 @@ CREATE TABLE tx_epevents_domain_model_testimonial (
PRIMARY KEY (uid),
KEY parent (pid),
KEY t3ver_oid (t3ver_oid,t3ver_wsid),
KEY language (l10n_parent,sys_language_uid)
KEY t3ver_oid (t3ver_oid, t3ver_wsid),
KEY language (l10n_parent, sys_language_uid)
);
#
# Table structure for table 'tx_epevents_offer_activity_mm'
#
CREATE TABLE tx_epevents_offer_activity_mm (
CREATE TABLE tx_epevents_offer_activity_mm
(
uid_local int(11) unsigned DEFAULT '0' NOT NULL,
uid_foreign int(11) unsigned DEFAULT '0' NOT NULL,
sorting int(11) unsigned DEFAULT '0' NOT NULL,
@@ -353,7 +361,8 @@ CREATE TABLE tx_epevents_offer_activity_mm (
#
# Table structure for table 'pages'
#
CREATE TABLE pages (
CREATE TABLE pages
(
tx_epevents_configurator_travel_type tinyint(4) DEFAULT '0',
tx_epevents_configurator_hotel_type tinyint(4) DEFAULT '0',
tx_epevents_configurator_destination_type tinyint(4) DEFAULT '0',
@@ -365,16 +374,19 @@ CREATE TABLE pages (
#
# Table structure for table 'tt_content'
#
CREATE TABLE tt_content (
CREATE TABLE tt_content
(
tx_epevents_configurator_travel_type tinyint(4) DEFAULT '0',
);
#
# Table structure for table 'tx_epevents_log'
#
CREATE TABLE tx_epevents_log (
CREATE TABLE tx_epevents_log
(
request_id varchar(13) DEFAULT '' NOT NULL,
time_micro double(16,4) NOT NULL default '0.0000',
time_micro double(16, 4) NOT NULL default '0.0000',
tstamp int(11) unsigned DEFAULT '0' NOT NULL,
component varchar(255) DEFAULT '' NOT NULL,
level tinyint(1) unsigned DEFAULT '0' NOT NULL,
message text,
@@ -0,0 +1,40 @@
<?php
namespace EP\EpProducts\Log;
use TYPO3\CMS\Core\Database\ConnectionPool;
use TYPO3\CMS\Core\Log\LogLevel;
use TYPO3\CMS\Core\Log\LogRecord;
use TYPO3\CMS\Core\Log\Writer\DatabaseWriter;
use TYPO3\CMS\Core\Utility\GeneralUtility;
class Writer extends DatabaseWriter
{
public function writeLog(LogRecord $record)
{
$data = '';
$recordData = $record->getData();
if (!empty($recordData)) {
if (isset($recordData['exception']) && $recordData['exception'] instanceof \Exception) {
$recordData['exception'] = (string)$recordData['exception'];
}
$data = '- ' . json_encode($recordData);
}
$fieldValues = [
'request_id' => $record->getRequestId(),
'time_micro' => $record->getCreated(),
'tstamp' => (int) $record->getCreated(),
'component' => $record->getComponent(),
'level' => LogLevel::normalizeLevel($record->getLevel()),
'message' => $record->getMessage(),
'data' => $data
];
GeneralUtility::makeInstance(ConnectionPool::class)
->getConnectionForTable($this->logTable)
->insert($this->logTable, $fieldValues);
return $this;
}
}
@@ -300,7 +300,7 @@ $boot = function () {
$GLOBALS['TYPO3_CONF_VARS']['LOG']['EP']['EpProducts']['Controller']['writerConfiguration'] = [
\TYPO3\CMS\Core\Log\LogLevel::INFO => [
TYPO3\CMS\Core\Log\Writer\DatabaseWriter::class => [
\EP\EpProducts\Log\Writer::class => [
'logTable' => 'tx_epproducts_log'
],
],
@@ -1502,6 +1502,7 @@ CREATE TABLE tx_epproducts_log
(
request_id varchar(13) DEFAULT '' NOT NULL,
time_micro double(16, 4) NOT NULL default '0.0000',
tstamp int(11) unsigned DEFAULT '0' NOT NULL,
component varchar(255) DEFAULT '' NOT NULL,
level tinyint(1) unsigned DEFAULT '0' NOT NULL,
message text,