Skip to content

Commit

Permalink
Merge pull request #904 from catalyst/tweak-logging
Browse files Browse the repository at this point in the history
Enhance logging details and verbosity
  • Loading branch information
keevan authored Oct 15, 2024
2 parents d812d96 + 0000904 commit d96331d
Show file tree
Hide file tree
Showing 98 changed files with 234 additions and 293 deletions.
1 change: 0 additions & 1 deletion classes/admin/admin_setting_configcheckbox.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

namespace tool_dataflows\admin;

use tool_dataflows\admin\readonly_trait;

/**
* A custom class applying extra readonly checks to the base implementation.
Expand Down
1 change: 0 additions & 1 deletion classes/admin/admin_setting_configexecutable.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

namespace tool_dataflows\admin;

use tool_dataflows\admin\readonly_trait;

/**
* A custom class applying extra readonly checks to the base implementation.
Expand Down
1 change: 0 additions & 1 deletion classes/admin/admin_setting_configmultiselect.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

namespace tool_dataflows\admin;

use tool_dataflows\admin\readonly_trait;

/**
* A custom class applying extra readonly checks to the base implementation.
Expand Down
1 change: 0 additions & 1 deletion classes/admin/admin_setting_configtext.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

namespace tool_dataflows\admin;

use tool_dataflows\admin\readonly_trait;

/**
* A custom class applying extra readonly checks to the base implementation.
Expand Down
8 changes: 3 additions & 5 deletions classes/admin/readonly_trait.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

namespace tool_dataflows\admin;

use tool_dataflows\manager;

/**
* Read only trait
Expand All @@ -25,11 +28,6 @@
* @copyright Catalyst IT, 2023
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

namespace tool_dataflows\admin;

use tool_dataflows\manager;

trait readonly_trait {

/**
Expand Down
4 changes: 3 additions & 1 deletion classes/dataflow.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

namespace tool_dataflows;

use Monolog\Logger;
use core\persistent;
use Symfony\Component\Yaml\Yaml;
use tool_dataflows\local\step\flow_step;
Expand Down Expand Up @@ -63,7 +64,8 @@ protected static function define_properties(): array {
'timemodified' => ['type' => PARAM_INT, 'default' => 0],
'usermodified' => ['type' => PARAM_INT, 'default' => 0],
'confighash' => ['type' => PARAM_TEXT, 'default' => ''],
'notifyonabort' => ['type' => PARAM_TEXT, 'default' => '']
'notifyonabort' => ['type' => PARAM_TEXT, 'default' => ''],
'minloglevel' => ['type' => PARAM_INT, 'default' => Logger::DEBUG],
];
}

Expand Down
2 changes: 1 addition & 1 deletion classes/dataflows_table.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ public function col_name(\stdClass $record): string {
$content[] = $extrainfo;
}
}
$html .= implode('<br/>', $content);
$html .= implode('<br>', $content);
return $html;
}

Expand Down
2 changes: 1 addition & 1 deletion classes/external/trigger_dataflow.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public static function execute_parameters() {
return new external_function_parameters([
'dataflow' => new external_single_structure([
'id' => new external_value(PARAM_INT, 'dataflow record id'),
])
]),
]);
}

Expand Down
15 changes: 14 additions & 1 deletion classes/form/dataflow_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

namespace tool_dataflows\form;

use Monolog\Logger;
use Symfony\Component\Yaml\Exception\ParseException;
use Symfony\Component\Yaml\Yaml;
use moodle_exception;
Expand Down Expand Up @@ -45,7 +46,7 @@ public function definition() {
$mform->addElement(
'html',
\html_writer::div(
get_string( 'readonly_active', 'tool_dataflows'),
get_string('readonly_active', 'tool_dataflows'),
'alert alert-warning'
)
);
Expand Down Expand Up @@ -119,6 +120,18 @@ public function definition() {
$mform->addElement('text', 'notifyonabort', get_string('notifyonabort', 'tool_dataflows'));
$mform->addElement('static', 'notifyonabort_desc', '', get_string('notifyonabort_desc', 'tool_dataflows'));

$mform->addElement('select', 'minloglevel', get_string('minloglevel', 'tool_dataflows'), [
Logger::DEBUG => 'DEBUG',
Logger::INFO => 'INFO',
Logger::NOTICE => 'NOTICE',
Logger::WARNING => 'WARNING',
Logger::ERROR => 'ERROR',
Logger::CRITICAL => 'CRITICAL',
Logger::ALERT => 'ALERT',
Logger::EMERGENCY => 'EMERGENCY',
]);
$mform->addElement('static', 'minloglevel_desc', '', get_string('minloglevel_desc', 'tool_dataflows'));

$this->add_action_buttons();
}

Expand Down
2 changes: 1 addition & 1 deletion classes/form/import_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public function definition() {
$mform->addElement(
'html',
\html_writer::div(
get_string( 'readonly_active', 'tool_dataflows'),
get_string('readonly_active', 'tool_dataflows'),
'alert alert-warning'
)
);
Expand Down
2 changes: 1 addition & 1 deletion classes/form/step_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public function definition() {
$mform->addElement(
'html',
\html_writer::div(
get_string( 'readonly_active', 'tool_dataflows'),
get_string('readonly_active', 'tool_dataflows'),
'alert alert-warning'
)
);
Expand Down
17 changes: 10 additions & 7 deletions classes/local/execution/engine.php
Original file line number Diff line number Diff line change
Expand Up @@ -679,8 +679,8 @@ public function set_status(int $status) {
$this->get_variables()->set("states.$statusstring", microtime(true));

$context = [
'isdryrun' => $this->isdryrun,
'status' => get_string('engine_status:'.self::STATUS_LABELS[$this->status], 'tool_dataflows'),
'isdryrun' => $this->isdryrun,
'status' => get_string('engine_status:'.self::STATUS_LABELS[$this->status], 'tool_dataflows'),
];

$level = Logger::INFO;
Expand Down Expand Up @@ -815,14 +815,17 @@ private function setup_logging() {
$loghandlers = $dataflowloghandlers;
}

// Minimum logging levels - will display this level and above.
$minloglevel = $this->dataflow->get('minloglevel');

// Default Moodle handler. Always on.
$mtracehandler = new mtrace_handler(Logger::DEBUG);
$mtracehandler = new mtrace_handler($minloglevel);
$mtracehandler->setFormatter($lineformatter);
$log->pushHandler($mtracehandler);

// Log to the browser's dev console for a manual run.
if (isset($loghandlers[log_handler::BROWSER_CONSOLE])) {
$log->pushHandler(new BrowserConsoleHandler(Logger::DEBUG));
$log->pushHandler(new BrowserConsoleHandler($minloglevel));
}

// Dataflow run logger.
Expand All @@ -834,7 +837,7 @@ private function setup_logging() {
$this->dataflow->id . DIRECTORY_SEPARATOR .
$rundateformat . '_' . $this->run->name . '.log';

$streamhandler = new StreamHandler($dataflowrunlogpath, Logger::DEBUG);
$streamhandler = new StreamHandler($dataflowrunlogpath, $minloglevel);
$streamhandler->setFormatter($lineformatter);
$log->pushHandler($streamhandler);
}
Expand All @@ -847,7 +850,7 @@ private function setup_logging() {
'tool_dataflows' . DIRECTORY_SEPARATOR .
$this->dataflow->id . '.log';

$rotatingfilehandler = new RotatingFileHandler($dataflowlogpath, 0, Logger::DEBUG);
$rotatingfilehandler = new RotatingFileHandler($dataflowlogpath, 0, $minloglevel);
$dateformat = 'Ymd';
$filenameformat = '{date}_{filename}';
$rotatingfilehandler->setFilenameFormat($filenameformat, $dateformat);
Expand All @@ -862,7 +865,7 @@ private function setup_logging() {
/**
* Send a notification email for abort if required.
*
* @param \Throwable $reason A throwable representing the reason for abort.
* @param ?\Throwable $reason A throwable representing the reason for abort.
*/
public function notify_on_abort(?\Throwable $reason) {
// If configured to send email, attempt to notify of the abort reason.
Expand Down
1 change: 0 additions & 1 deletion classes/local/execution/flow_engine_step.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

namespace tool_dataflows\local\execution;

use tool_dataflows\parser;

/**
* Manages the execution of a flow step.
Expand Down
1 change: 0 additions & 1 deletion classes/local/execution/iterators/dataflow_iterator.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

use tool_dataflows\local\execution\flow_engine_step;
use tool_dataflows\local\step\base_step;
use tool_dataflows\local\step\flow_cap;

/**
* A mapping iterator that takes a PHP iterator as a source.
Expand Down
2 changes: 0 additions & 2 deletions classes/local/execution/logging/mtrace_handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

namespace tool_dataflows\local\execution\logging;

use Monolog\Handler\AbstractHandler;
use Monolog\Handler\AbstractProcessingHandler;

/**
Expand Down Expand Up @@ -48,7 +47,6 @@ public function handle(array $record): bool {
* Writes the record down to the log of the implementing handler
*
* @param array $record
* @return void
*/
protected function write(array $record): void {
mtrace($record['formatted']);
Expand Down
1 change: 0 additions & 1 deletion classes/local/provider/expression_provider.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

use Symfony\Component\ExpressionLanguage\ExpressionFunction;
use Symfony\Component\ExpressionLanguage\ExpressionFunctionProviderInterface;
use tool_dataflows\parser;

/**
* Expression Provider
Expand Down
1 change: 0 additions & 1 deletion classes/local/service/step_service.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

use tool_dataflows\local\execution\engine_flow_cap;
use tool_dataflows\local\execution\engine_step;
use tool_dataflows\local\step\reader_step;
use tool_dataflows\step;

/**
Expand Down
5 changes: 2 additions & 3 deletions classes/local/step/abort_trait.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

namespace tool_dataflows\local\step;

/**
* Abort Step ..Trait
*
Expand All @@ -27,9 +29,6 @@
* @copyright Catalyst IT, 2022
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

namespace tool_dataflows\local\step;

trait abort_trait {

/**
Expand Down
1 change: 1 addition & 0 deletions classes/local/step/append_file_trait.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
trait append_file_trait {

/**
* Returns whether or not the step configured, has a side effect.
*
Expand Down
1 change: 0 additions & 1 deletion classes/local/step/base_step.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
use tool_dataflows\local\execution\engine_step;
use tool_dataflows\local\variables\var_root;
use tool_dataflows\local\variables\var_step;
use tool_dataflows\parser;
use tool_dataflows\step;

/**
Expand Down
11 changes: 5 additions & 6 deletions classes/local/step/compression_trait.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
trait compression_trait {

/**
* Returns whether or not the step configured, has a side effect.
*
Expand Down Expand Up @@ -188,10 +189,10 @@ private function get_supported_methods(): array {
return [
'gzip' => (object) [
'name' => get_string('compression:method:gzip', 'tool_dataflows'),
'isexecutable' => function() {
'isexecutable' => function () {
return self::validate_executable(get_config('tool_dataflows', 'gzip_exec_path'));
}
]
},
],
];
}

Expand All @@ -203,9 +204,7 @@ private function get_supported_methods(): array {
*/
private static function validate_executable(string $path) {
if (!is_executable($path)) {
return get_string('compression:error:invalidexecutable', 'tool_dataflows', [
'path' => $path
]);
return get_string('compression:error:invalidexecutable', 'tool_dataflows', ['path' => $path]);
}

return true;
Expand Down
1 change: 0 additions & 1 deletion classes/local/step/connector_copy_file.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

namespace tool_dataflows\local\step;

use tool_dataflows\helper;

/**
* Copy file connector step
Expand Down
2 changes: 0 additions & 2 deletions classes/local/step/connector_debug_file_display.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

namespace tool_dataflows\local\step;
use tool_dataflows\local\execution\engine_step;
use tool_dataflows\helper;

/**
Expand Down Expand Up @@ -94,4 +93,3 @@ public function form_add_custom_inputs(\MoodleQuickForm &$mform) {
}
}


1 change: 0 additions & 1 deletion classes/local/step/connector_debugging.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

namespace tool_dataflows\local\step;
use tool_dataflows\local\execution\engine_step;

/**
* Debugging connector step type
Expand Down
3 changes: 0 additions & 3 deletions classes/local/step/connector_sftp.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,7 @@

namespace tool_dataflows\local\step;

use phpseclib3\Crypt\Common\AsymmetricKey;
use phpseclib3\Crypt\PublicKeyLoader;
use phpseclib3\Net\SFTP;
use tool_dataflows\helper;

/**
* SFTP connector step type.
Expand Down
1 change: 1 addition & 0 deletions classes/local/step/copy_file_trait.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
trait copy_file_trait {

/**
* Return the definition of the fields available in this form.
*
Expand Down
1 change: 0 additions & 1 deletion classes/local/step/curl_trait.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

namespace tool_dataflows\local\step;

use Symfony\Component\Yaml\Yaml;
use tool_dataflows\helper;

defined('MOODLE_INTERNAL') || die();
Expand Down
Loading

0 comments on commit d96331d

Please sign in to comment.