diff --git a/classes/hook_listener.php b/classes/hook_listener.php index f7ad380..ee81131 100644 --- a/classes/hook_listener.php +++ b/classes/hook_listener.php @@ -2,9 +2,11 @@ namespace local_logging; +use core\di; use core\hook\di_configuration; use local_logging\local\output\log_output; use local_logging\local\output\log_output_db; +use local_logging\local\output\log_output_mtrace; use local_logging\local\output\log_output_stdout; class hook_listener { @@ -12,11 +14,13 @@ public static function inject_dependencies(di_configuration $hook): void { $hook->add_definition( id: log_output::class, definition: function (): log_output { - if (defined('CLI_SCRIPT') || defined('PHPUNIT_TEST')) { - return new log_output_stdout(); - } else { - return new log_output_db(); - } + return di::get(log_output_mtrace::class); +// if (defined('CLI_SCRIPT') || defined('PHPUNIT_TEST')) { +// return new log_output_stdout(); +// return di::get(log_output_mtrace::class); +// } else { +// return di::get(log_output_db::class); +// } } ); } diff --git a/classes/local/output/log_output_mtrace.php b/classes/local/output/log_output_mtrace.php new file mode 100644 index 0000000..64282e8 --- /dev/null +++ b/classes/local/output/log_output_mtrace.php @@ -0,0 +1,13 @@ +dirroot . '/local/logging/tests/lib/adler_testcase.php'); + +class log_output_mtrace_test extends adler_testcase { + public function test_output() { + // Create an instance of log_output_stdout. + $logOutput = new log_output_mtrace(); + + // Define test data. + $message = 'Test message'; + $level = util::LEVEL_TRACE; // Assuming 100 corresponds to TRACE level + $component = 'testcomponent'; + $title = 'testtitle'; + $time = time(); + $user_id = null; + + // Start output buffering. + ob_start(); + + // Call the output method. + $logOutput->output($message, $level, $component, $title, $time, $user_id); + + // Get the output and clean the buffer. + $output = ob_get_clean(); + + // Assert that the output contains the expected components. + $this->assertStringContainsString('[' . date('Y-m-d H:i:s', $time) . ']', $output); + $this->assertStringContainsString('TRACE', $output); + $this->assertStringContainsString($component, $output); + $this->assertStringContainsString($title . ':', $output); + $this->assertStringContainsString($message, $output); + } +} \ No newline at end of file diff --git a/tests/local/output/log_output_stdout_test.php b/tests/local/output/log_output_stdout_test.php index 5a87bed..22fdd00 100644 --- a/tests/local/output/log_output_stdout_test.php +++ b/tests/local/output/log_output_stdout_test.php @@ -1,7 +1,8 @@