Я считаю это полезным:
function console($data, $priority, $debug)
{
if ($priority <= $debug)
{
if (is_array($data))
$output = '<script>console.log("' . str_repeat(" ", $priority-1) . implode( ",", $data) . '");</script>';
else
$output = '<script>console.log("' . str_repeat(" ", $priority-1) . $data . '");</script>';
echo $output;
}
}
И используйте его как:
<?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);
?>
Какие выходы в консоли:
Important
Less Important
Even Less Important
Again Important
И вы можете отключить менее важные журналы, ограничив их с помощью значения $ debug