// A safer console object - see github.com/nathanl/consolation
safe_console = {
  enabled: false,
  original_console: (function(){
    // If the browser has no usable one, define a no-op.
    // TODO: metaprogram to add all supported methods, not just log, to this dummy console
    return (typeof(window.console === 'object') && typeof(window.console.log) === 'function') ? window.console : {log: function(){}};
  })(),
  __args_to_array: function(args) { return Array.prototype.slice.call(args); },
  __caller_location: function() {
    var call_locations, current_position, caller, file_and_line;
    try {
    call_locations   = (new Error).stack.split("\n");
    current_position = call_locations[0].match(/Error/) ? 3 : 2;
    caller           = call_locations[current_position];
    // Match from either the last '/' or from '<anonymous>' to the end
    file_and_line    = caller.match(/(\/([^\/]*)|\<anonymous\>.*)$/)[0];

    } catch (err) {
      file_and_line = 'location not supported by browser';
    }
    return file_and_line;
  }
};

(function(){
  // Metaprogramming in JS! Wooooooooooooooo
  logging_methods = ['log', 'debug', 'info', 'error', 'warn'];
  methods         = ['dir', 'group', 'groupCollapsed', 'groupEnd', 'time', 'timeEnd', 'trace'].concat(logging_methods);
  for (i = 0; i < methods.length; i++) {
    method_name = methods[i];
    (function(method_name){
      safe_console[method_name] = function() {
        if (!this.enabled) { return; }
        var args = arguments;
        // Tack on the caller location if this is a logging method
        if (logging_methods.indexOf(method_name) !== -1) {
          var called_from = this.__caller_location();
          args            = this.__args_to_array(arguments).concat("(" + called_from + ")");
        }
        this.original_console[method_name].apply(this.original_console, args);
      };
    }
    )(method_name);
  }
})();

// In case we missed any methods: inherit, regardless of `enabled` switch
safe_console.__proto__ = safe_console.original_console;

// Recklessly cautious!
window.console = safe_console;

@@ -56,16 +56,17 @@
 olation%0A
+%0A
 safe_con
@@ -1044,31 +1044,16 @@
   %7D%0A%7D;%0A%0A
-(function()%7B%0A  
 // Metap
@@ -1087,16 +1087,72 @@
 ooooooo%0A
+function add_console_methods(console_object, definer) %7B%0A
   loggin
@@ -1405,50 +1405,142 @@
     
-(function(method_name)%7B%0A      safe_console
+definer(console_object, method_name);%0A  %7D%0A%7D%0A%0Aadd_console_methods(safe_console, function(console_object, method_name)%7B%0A  console_object
 %5Bmet
@@ -1564,28 +1564,24 @@
 ion() %7B%0A    
-  
-  
 if (!this.en
@@ -1599,20 +1599,16 @@
 turn; %7D%0A
-    
     var 
@@ -1625,20 +1625,16 @@
 uments;%0A
-    
     // T
@@ -1692,20 +1692,16 @@
 hod%0A    
- 
-   
 if (logg
@@ -1749,20 +1749,16 @@
 %7B%0A      
-    
 var call
@@ -1793,20 +1793,16 @@
 tion();%0A
-    
       ar
@@ -1886,26 +1886,18 @@
 %22);%0A    
-    %7D%0A    
+%7D%0A
     this
@@ -1969,48 +1969,12 @@
 ;%0A  
-    %7D;%0A    %7D%0A    )(method_name);%0A  %7D%0A%7D)(
+%7D;%0A%7D
 );%0A%0A

Move metaprogramming to a function