From 031125517e11a3af85eeeb2ea7514b648a0176b8 Mon Sep 17 00:00:00 2001 From: Pavel Dohnal Date: Mon, 27 Aug 2018 16:58:33 +0200 Subject: [PATCH] Add rudimentary logger [MAILPOET-570] --- lib/Config/Database.php | 2 ++ lib/Config/Migrator.php | 4 +++- lib/Logging/LogHandler.php | 22 ++++++++++++++++++++++ lib/Logging/Logger.php | 38 ++++++++++++++++++++++++++++++++++++++ lib/Models/Log.php | 8 ++++++++ 5 files changed, 73 insertions(+), 1 deletion(-) create mode 100644 lib/Logging/LogHandler.php create mode 100644 lib/Logging/Logger.php create mode 100644 lib/Models/Log.php diff --git a/lib/Config/Database.php b/lib/Config/Database.php index b34195e530..152885ee91 100644 --- a/lib/Config/Database.php +++ b/lib/Config/Database.php @@ -85,6 +85,7 @@ class Database { $statistics_unsubscribes = Env::$db_prefix . 'statistics_unsubscribes'; $statistics_forms = Env::$db_prefix . 'statistics_forms'; $mapping_to_external_entities = Env::$db_prefix . 'mapping_to_external_entities'; + $log = Env::$db_prefix . 'log'; define('MP_SETTINGS_TABLE', $settings); define('MP_SEGMENTS_TABLE', $segments); @@ -110,6 +111,7 @@ class Database { define('MP_STATISTICS_UNSUBSCRIBES_TABLE', $statistics_unsubscribes); define('MP_STATISTICS_FORMS_TABLE', $statistics_forms); define('MP_MAPPING_TO_EXTERNAL_ENTITIES_TABLE', $mapping_to_external_entities); + define('MP_LOG_TABLE', $log); } } } diff --git a/lib/Config/Migrator.php b/lib/Config/Migrator.php index 7e6b5dd8ea..59edf6982f 100644 --- a/lib/Config/Migrator.php +++ b/lib/Config/Migrator.php @@ -435,10 +435,12 @@ class Migrator { function log() { $attributes = [ + 'id BIGINT unsigned NOT NULL AUTO_INCREMENT,', 'name VARCHAR(255),', 'level INTEGER,', 'message LONGTEXT,', - 'time TIMESTAMP DEFAULT CURRENT_TIMESTAMP', + 'created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP', + 'PRIMARY KEY (id),', ]; return $this->sqlify(__FUNCTION__, $attributes); } diff --git a/lib/Logging/LogHandler.php b/lib/Logging/LogHandler.php new file mode 100644 index 0000000000..292a90099a --- /dev/null +++ b/lib/Logging/LogHandler.php @@ -0,0 +1,22 @@ +hydrate([ + 'name' => $record['channel'], + 'level' => $record['level'], + 'message' => $record['formatted'], + 'created_at' => $record['datetime']->format('Y-m-d H:i:s'), + ]); + $model->save(); + } + +} \ No newline at end of file diff --git a/lib/Logging/Logger.php b/lib/Logging/Logger.php new file mode 100644 index 0000000000..9f6d8e03e8 --- /dev/null +++ b/lib/Logging/Logger.php @@ -0,0 +1,38 @@ +pushProcessor(new IntrospectionProcessor()); + // Adds the current request URI, request method and client IP to a log record + self::$instance[$name]->pushProcessor(new WebProcessor()); + // Adds the current memory usage to a log record + self::$instance[$name]->pushProcessor(new MemoryUsageProcessor()); + } + + self::$instance[$name]->pushHandler(new LogHandler()); + } + return self::$instance[$name]; + } + +} \ No newline at end of file diff --git a/lib/Models/Log.php b/lib/Models/Log.php new file mode 100644 index 0000000000..80a805f8a0 --- /dev/null +++ b/lib/Models/Log.php @@ -0,0 +1,8 @@ +