diff --git a/classes/dataflow.php b/classes/dataflow.php index 97578275..6035db3a 100644 --- a/classes/dataflow.php +++ b/classes/dataflow.php @@ -57,6 +57,7 @@ protected static function define_properties(): array { 'enabled' => ['type' => PARAM_BOOL, 'default' => false], 'concurrencyenabled' => ['type' => PARAM_BOOL, 'default' => false], 'vars' => ['type' => PARAM_TEXT, 'default' => ''], + 'loghandlers' => ['type' => PARAM_TEXT, 'default' => ''], 'timecreated' => ['type' => PARAM_INT, 'default' => 0], 'userid' => ['type' => PARAM_INT, 'default' => 0], 'timemodified' => ['type' => PARAM_INT, 'default' => 0], @@ -711,4 +712,17 @@ public function has_trigger_step(string $classname): bool { } return false; } + + /** + * Hook to execute before the persistent validation. + * + * e.g. loghandlers are set as a multiselect (array), and stored as a CSV string. + */ + protected function before_validate() { + // Get the loghandlers value and convert the raw value to a CSV as required. + $loghandlers = $this->raw_get('loghandlers'); + if (!empty($loghandlers) && is_array($loghandlers)) { + $this->raw_set('loghandlers', implode(',', $loghandlers)); + } + } } diff --git a/classes/form/dataflow_form.php b/classes/form/dataflow_form.php index 7fa8e568..38a2585f 100644 --- a/classes/form/dataflow_form.php +++ b/classes/form/dataflow_form.php @@ -19,6 +19,7 @@ use Symfony\Component\Yaml\Exception\ParseException; use Symfony\Component\Yaml\Yaml; use moodle_exception; +use tool_dataflows\local\execution\logging\log_handler; use tool_dataflows\manager; /** @@ -101,6 +102,20 @@ public function definition() { $outputsexample['example'] = \html_writer::tag('pre', $examplestring); $mform->addElement('static', 'vars_help', '', get_string('field_vars_help', 'tool_dataflows', $outputsexample)); + // Multi-select element used to enable different logging handlers. + $select = $mform->addElement( + 'select', + 'loghandlers', + get_string('log_handlers', 'tool_dataflows'), + [ + log_handler::BROWSER_CONSOLE => get_string('log_handler_browser_console', 'tool_dataflows'), + log_handler::FILE_PER_DATAFLOW => get_string('log_handler_file_per_dataflow', 'tool_dataflows'), + log_handler::FILE_PER_RUN => get_string('log_handler_file_per_run', 'tool_dataflows'), + ], + ); + $select->setMultiple(true); + $mform->addElement('static', 'log_handlers_desc', '', get_string('log_handlers_desc', 'tool_dataflows')); + $this->add_action_buttons(); } diff --git a/classes/local/execution/engine.php b/classes/local/execution/engine.php index 933239b9..7585ba70 100644 --- a/classes/local/execution/engine.php +++ b/classes/local/execution/engine.php @@ -755,8 +755,12 @@ private function setup_logging() { // Tweak the default datetime output to include microseconds. $lineformatter = new LineFormatter(null, 'Y-m-d H:i:s.u'); - // Log handlers. + // Log handler settings (prefer dataflow if set, otherwise site level settings). $loghandlers = array_flip(explode(',', get_config('tool_dataflows', 'log_handlers'))); + $dataflowloghandlers = array_flip(explode(',', $this->dataflow->get('loghandlers'))); + if (!empty($dataflowloghandlers)) { + $loghandlers = $dataflowloghandlers; + } // Default Moodle handler. Always on. $mtracehandler = new mtrace_handler(Logger::DEBUG); diff --git a/db/install.xml b/db/install.xml index 019c5e0c..b072c1b7 100644 --- a/db/install.xml +++ b/db/install.xml @@ -1,5 +1,5 @@ - @@ -12,6 +12,7 @@ + diff --git a/db/upgrade.php b/db/upgrade.php index 1a5f1c75..169e405c 100644 --- a/db/upgrade.php +++ b/db/upgrade.php @@ -272,5 +272,21 @@ function xmldb_tool_dataflows_upgrade($oldversion) { upgrade_plugin_savepoint(true, 2023050100, 'tool', 'dataflows'); } + + if ($oldversion < 2023072100) { + + // Define field loghandlers to be added to tool_dataflows. + $table = new xmldb_table('tool_dataflows'); + $field = new xmldb_field('loghandlers', XMLDB_TYPE_CHAR, '100', null, null, null, null, 'vars'); + + // Conditionally launch add field loghandlers. + if (!$dbman->field_exists($table, $field)) { + $dbman->add_field($table, $field); + } + + // Dataflows savepoint reached. + upgrade_plugin_savepoint(true, 2023072100, 'tool', 'dataflows'); + } + return true; } diff --git a/lang/en/tool_dataflows.php b/lang/en/tool_dataflows.php index ca392577..dbe4af9c 100644 --- a/lang/en/tool_dataflows.php +++ b/lang/en/tool_dataflows.php @@ -44,9 +44,9 @@ $string['gpg_key_dir'] = 'Path to keyring directory'; $string['gpg_key_dir_desc'] = 'Path to keyring directory'; $string['log_handlers'] = 'Log handlers'; -$string['log_handlers_desc'] = 'Additional log handlers to output dataflow logs to more destinations. The handler for mtrace is always active and cannot be disabled.'; -$string['log_handler_file_per_dataflow'] = 'File per dataflow - [dataroot]/tool_dataflows/-Y-m-d.log'; -$string['log_handler_file_per_run'] = 'File per run - [dataroot]/tool_dataflows//.log'; +$string['log_handlers_desc'] = 'Additional log handlers to output dataflow logs to more destinations. The handler for mtrace is always active and cannot be disabled. Applying the settings at the dataflow level will override settings applied at the site admin level.'; +$string['log_handler_file_per_dataflow'] = 'File per dataflow - [dataroot]/tool_dataflows/{id}-Y-m-d.log'; +$string['log_handler_file_per_run'] = 'File per run - [dataroot]/tool_dataflows/{dataflowid}/{id}.log'; $string['log_handler_browser_console'] = 'Browser Console'; $string['permitted_dirs'] = 'Permitted directories'; $string['permitted_dirs_desc'] = "List directories here to allow them to be read from/written to by dataflow steps. diff --git a/version.php b/version.php index eb7c03cf..160f7ea8 100644 --- a/version.php +++ b/version.php @@ -25,8 +25,8 @@ defined('MOODLE_INTERNAL') || die(); -$plugin->version = 2023072000; -$plugin->release = 2023072000; +$plugin->version = 2023072100; +$plugin->release = 2023072100; $plugin->requires = 2017051500; // Our lowest supported Moodle (3.3.0). $plugin->supported = [35, 401]; // Available as of Moodle 3.9.0 or later. // TODO $plugin->incompatible = ; // Available as of Moodle 3.9.0 or later.