ES

Mario Rocafull / Albin

Software developer freelance in Valencia

12 October 2023 · Code

Error reporting

How do I receive notifications when there are serious errors in a project.

Many languages write an error log with syntax errors (you forgot a semicolon) or execution errors (e.g. call to a function that does not exist).

You can receive the notification by Email or Telegram, for example. In my case, I don't usually check my email when I'm not at home, and yet since my Telegram has very little activity, I do tend to check it when it rings, unlike WhatsApp, which has notifications disabled (I like to breathe easy). But you can also solve it by assigning that contact (the bot) a different sound than the rest to know that the message is an alert for a project.

Basically we create a cron task that checks from time to time if the log file has grown compared to the last check and in that case sends a warning (EngineFwk are my libraries when I do custom programming).

$tgram   = \EngineFwk\Telegram::instance();

$config = json_decode(file_get_contents('cron-logs-checker.json'));

if(file_exists('error.log')) {
	$mtime = filemtime('error.log');
	if($mtime > $config->last_exec) {
		$tgram->send_message('AcrataDom', 'myImportantProject : New PHP errors');
	}
}

$config->last_exec = time();

file_put_contents('cron-logs-checker.json', json_encode($config, JSON_PRETTY_PRINT));

Summary

There is no point in having an error log that you never review, it is better to have a cron that notifies you when the log grows.

Logically, this is only valid for programmers who make clean code and would be crazy in projects where very verbose libraries are integrated.