Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Log stream #103

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open

Log stream #103

wants to merge 4 commits into from

Conversation

brendanheywood
Copy link
Contributor

No description provided.

lib.php Outdated
function tool_heartbeat_status_checks() {
return [new \tool_heartbeat\check\authcheck()];
}

tool_heartbeat\logger::register_shutdown_handler();
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think lib.php is always guaranteed to be loaded, I think this needs to be inside a callback such tool_heartbeat_after_config but this only landed in 3.8. We might not need older support, if we do there are other callbacks we can use

https://tracker.moodle.org/browse/MDL-66340

// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

/**
* MFA management class.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo

lib.php Outdated
}

function tool_heartbeat_after_config() {
stream_wrapper_register('syslog', 'tool_heartbeat\wrapper\syslog')
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can this be conditional so if it's not configured we don't add the wrapper

lib.php Outdated
}

function tool_heartbeat_after_config() {
stream_wrapper_register('syslog', 'tool_heartbeat\wrapper\syslog')
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this doesn't even install:

Error
Exception - syntax error, unexpected 'throw' (T_THROW)
Debug info:
Error code: generalexceptionmessage
Stack trace:
line 35 of /admin/tool/heartbeat/lib.php: ParseError thrown
line 7833 of /lib/moodlelib.php: call to core_component::get_plugin_list_with_file()
line 1084 of /lib/setup.php: call to get_plugins_with_function()
line 651 of /config.php: call to require_once()
line 88 of /admin/index.php: call to require()

$summary = get_string('logstreamerror', 'tool_heartbeat', "$logstream ".$e->getMessage());
}
} else {
$status = result::WARNING;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we should check that config is in a certain state here, it is normal that you might not want to use this and it shouldn't be a warning.

*/
public static function log(): void {
$defaultstream = self::default_log_stream();
$statcallbacks = self::$statcallbacks;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It isn't very clear what all the lines from here to line 80 are doing. All of the $statcallbacks stuff seems very complicated, I believe it is all to allow injection for the unit tests? Is so could this just be tucked away into a getter?

if ($fh = fopen($stream, 'a')) {
foreach ($lines as $l) {
if (fwrite($fh, "{$PAGE->pagetype} - $l") === false) {
throw new moodle_exception("tool_heartbeat\\logger::log_to_stream: Cannot write to $stream");
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would like to avoid exceptions where we are adding instrumentation to a page and now the page has the possibility of failing due to the instrumentation. I think a debugging() call is a better option here

$plugin->requires = 2012120311; // Deep support going back to 2.4.
$plugin->version = 2021122200;
$plugin->release = 2021122200; // Match release exactly to version.
$plugin->requires = 2018051718; // Deep support going back to 3.5.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This support cannot change


if ($fh = fopen($stream, 'a')) {
foreach ($lines as $l) {
if (fwrite($fh, "{$PAGE->pagetype} - $l") === false) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure that $PAGE is always setup. Will comment in the wr we might want something else here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants