console.log, console.error for PHP?

Viewed 27046

When developing web applications, at the clientside level I use console.log and console.error to help me see what's going on. I am looking for a similar feature at the serverside level to help me see what's going on. I have seen error_log which writes errors to the server's log file and wanted to know if there is a similar function for writing to the servers access logs?

Or am I going about this the wrong way, am I supposed to be using something completely different to see what's going on in the background for serverside development?

4 Answers

This worked for me: http://www.paulund.co.uk/output-php-data-in-browser-console

/**
 * Send debug code to the Javascript console
 */ 
function debug_to_console($data) {
  if(is_array($data) || is_object($data)) {
    echo("<script>console.log('PHP: ".json_encode($data)."');</script>");
  } else {
    echo("<script>console.log('PHP: $data');</script>");
  }
}
Related