Ich finde das hilfreich:
function console($data, $priority, $debug)
{
if ($priority <= $debug)
{
$output = '<script>console.log("' . str_repeat(" ", $priority-1) . (is_array($data) ? implode(",", $data) : $data) . '");</script>';
echo $output;
}
}
Und verwenden Sie es wie:
<?php
$debug = 5; // All lower and equal priority logs will be displayed
console('Important', 1 , $debug);
console('Less Important', 2 , $debug);
console('Even Less Important', 5 , $debug);
console('Again Important', 1 , $debug);
?>
Die Ausgaben in der Konsole:
Important
Less Important
Even Less Important
Again Important
Und Sie können weniger wichtige Protokolle abschalten, indem Sie sie mit dem Wert $debug einschränken.