Categorized: Django, JavaScript

How to Log Something

With The Django Debug Toolbar

Somewhere in your Python code (not a template):

import logging
logging.debug(something_you_want_to_log)

With Firebug

Somewhere in your JavaScript or the Firebug Console:

console.log(something_you_want_to_log);

That was easy.

Sources

Comments

Benjamin Wohlwend → November 10th, 2009 at 1:52 am

Don’t forget to check if the console.log object is available before using it or your code will break if firebug isn’t running. I usually add this at the top of my javascript code:

if (typeof console == "undefined" || typeof console.log == "undefined") var console = { log: function() {} }; 

There are also fancier solutions for this problem.

Attila → November 10th, 2009 at 2:09 am

Or you can use firebug LITE that is a javascript rewrite of firebug, so console.log will work in every browser.

http://getfirebug.com/lite.html

What do you think about that?

Elsewhere in the empire: Home, Blog, APOD