Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Javascript: Write Console.debug() output to browser?

I need to be able to take any JSON data and print the key/value pairs.

(something similar to print_r() in PHP)

Is this even possible with javascript?

like image 882
simonwjackson Avatar asked Nov 19 '09 21:11

simonwjackson


People also ask

How do I add console log to my browser?

Adding a console log is something Google recently add. In the selected row instead of left click,click right click and select 'add logpoint', a small text box will pop up, enter the variable you want you console log.

How do I get my browser console output?

Google Chrome: Console Logs in Chrome: In Google Chrome, the Console Logs are available as a part of Chrome Dev Tools. To open the dedicated Console panel, either: Press Ctrl + Shift + J (Windows / Linux) or Cmd + Opt + J (Mac).


1 Answers

I usually just quickly create a log function that allows you change the logging method. Write enablers/disablers or comment out to choose the options.

function log(msg){
  if (window.console && console.log) {
    console.log(msg); //for firebug
  }
  document.write(msg); //write to screen
  $("#logBox").append(msg); //log to container
}

Update: Info on Firebug's Console API

Update: Added check for non firebug browsers.

like image 163
Glennular Avatar answered Sep 26 '22 14:09

Glennular