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)) { if (in_array($remoteIp, $ignoreIps)) {
return; return;
} }
/** @var $logger \TYPO3\CMS\Core\Log\Logger */
$logger = GeneralUtility::makeInstance(LogManager::class)->getLogger(__CLASS__); $logger = GeneralUtility::makeInstance(LogManager::class)->getLogger(__CLASS__);
$logger->info('Searchresult processed', [ $logger->info('Searchresult processed', [
'search' => $search->getQuery(), 'search' => $search->getQuery(),
@@ -166,7 +166,7 @@ call_user_func(function() {
$GLOBALS['TYPO3_CONF_VARS']['LOG']['EP']['EpEvents']['Controller']['writerConfiguration'] = [ $GLOBALS['TYPO3_CONF_VARS']['LOG']['EP']['EpEvents']['Controller']['writerConfiguration'] = [
\TYPO3\CMS\Core\Log\LogLevel::INFO => [ \TYPO3\CMS\Core\Log\LogLevel::INFO => [
\TYPO3\CMS\Core\Log\Writer\DatabaseWriter::class => [ \EP\EpProducts\Log\Writer::class => [
'logTable' => 'tx_epevents_log' 'logTable' => 'tx_epevents_log'
], ],
], ],
+23 -11
View File
@@ -1,7 +1,8 @@
# #
# Table structure for table 'tx_epevents_domain_model_traveltype' # 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, uid int(11) NOT NULL auto_increment,
pid int(11) DEFAULT '0' NOT NULL, pid int(11) DEFAULT '0' NOT NULL,
@@ -49,7 +50,8 @@ CREATE TABLE tx_epevents_domain_model_traveltype (
# #
# Table structure for table 'tx_epevents_domain_model_offer' # 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, uid int(11) NOT NULL auto_increment,
pid int(11) DEFAULT '0' NOT NULL, pid int(11) DEFAULT '0' NOT NULL,
@@ -112,7 +114,8 @@ CREATE TABLE tx_epevents_domain_model_offer (
# #
# Table structure for table 'tx_epevents_domain_model_location' # 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, uid int(11) NOT NULL auto_increment,
pid int(11) DEFAULT '0' NOT NULL, pid int(11) DEFAULT '0' NOT NULL,
@@ -162,7 +165,8 @@ CREATE TABLE tx_epevents_domain_model_location (
# #
# Table structure for table 'tx_epevents_domain_model_hotel' # 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, uid int(11) NOT NULL auto_increment,
pid int(11) DEFAULT '0' NOT NULL, pid int(11) DEFAULT '0' NOT NULL,
@@ -206,7 +210,8 @@ CREATE TABLE tx_epevents_domain_model_hotel (
# #
# Table structure for table 'tx_epevents_domain_model_activity' # 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, uid int(11) NOT NULL auto_increment,
pid int(11) DEFAULT '0' NOT NULL, pid int(11) DEFAULT '0' NOT NULL,
@@ -255,7 +260,8 @@ CREATE TABLE tx_epevents_domain_model_activity (
# #
# Table structure for table 'tx_epevents_domain_model_contact' # 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, uid int(11) NOT NULL auto_increment,
pid int(11) DEFAULT '0' NOT NULL, pid int(11) DEFAULT '0' NOT NULL,
@@ -299,7 +305,8 @@ CREATE TABLE tx_epevents_domain_model_contact (
# #
# Table structure for table 'tx_epevents_domain_model_testimonial' # 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, uid int(11) NOT NULL auto_increment,
pid int(11) DEFAULT '0' NOT NULL, pid int(11) DEFAULT '0' NOT NULL,
@@ -340,7 +347,8 @@ CREATE TABLE tx_epevents_domain_model_testimonial (
# #
# Table structure for table 'tx_epevents_offer_activity_mm' # 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_local int(11) unsigned DEFAULT '0' NOT NULL,
uid_foreign int(11) unsigned DEFAULT '0' NOT NULL, uid_foreign int(11) unsigned DEFAULT '0' NOT NULL,
sorting 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' # Table structure for table 'pages'
# #
CREATE TABLE pages ( CREATE TABLE pages
(
tx_epevents_configurator_travel_type tinyint(4) DEFAULT '0', tx_epevents_configurator_travel_type tinyint(4) DEFAULT '0',
tx_epevents_configurator_hotel_type tinyint(4) DEFAULT '0', tx_epevents_configurator_hotel_type tinyint(4) DEFAULT '0',
tx_epevents_configurator_destination_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' # Table structure for table 'tt_content'
# #
CREATE TABLE tt_content ( CREATE TABLE tt_content
(
tx_epevents_configurator_travel_type tinyint(4) DEFAULT '0', tx_epevents_configurator_travel_type tinyint(4) DEFAULT '0',
); );
# #
# Table structure for table 'tx_epevents_log' # Table structure for table 'tx_epevents_log'
# #
CREATE TABLE tx_epevents_log ( CREATE TABLE tx_epevents_log
(
request_id varchar(13) DEFAULT '' NOT NULL, 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, component varchar(255) DEFAULT '' NOT NULL,
level tinyint(1) unsigned DEFAULT '0' NOT NULL, level tinyint(1) unsigned DEFAULT '0' NOT NULL,
message text, 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'] = [ $GLOBALS['TYPO3_CONF_VARS']['LOG']['EP']['EpProducts']['Controller']['writerConfiguration'] = [
\TYPO3\CMS\Core\Log\LogLevel::INFO => [ \TYPO3\CMS\Core\Log\LogLevel::INFO => [
TYPO3\CMS\Core\Log\Writer\DatabaseWriter::class => [ \EP\EpProducts\Log\Writer::class => [
'logTable' => 'tx_epproducts_log' 'logTable' => 'tx_epproducts_log'
], ],
], ],
@@ -1502,6 +1502,7 @@ CREATE TABLE tx_epproducts_log
( (
request_id varchar(13) DEFAULT '' NOT NULL, 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, component varchar(255) DEFAULT '' NOT NULL,
level tinyint(1) unsigned DEFAULT '0' NOT NULL, level tinyint(1) unsigned DEFAULT '0' NOT NULL,
message text, message text,