Same log message keeps on printing to debug.log file thousand of times

OK, as far as I understand, you’ve put this code:

$debug_log = "DEBUG-debug log";
trigger_error($debug_log);
//OR
error_log($debug_log);

directly in your functionsphp` file.

It means, that this code will be executed (so new log item will be added to log file) every time the functions.php file is loaded – so during every request to your WP.

It means, that every time someone views your page, there will be new log item added.

But… That’s not all… If you’re logged in, then WP sends Heartbeat requests. They will also result in new log items.

There are not so many log items logged with the same time in your log, so IMHO it’s unlikely that they are printed in the same request.

PS. JS won’t be executed during AJAX calls, so you won’t see them multiple times.