Overwriting native console.log function in JavaScript I want to override the console.log function in order to save the data other scripts log. My script executes before any other script, so I have full control over the environment. This is my current function for overwriting console.log:

+function(){
    var a = Function.prototype, b = 'toString', c = a[b], d = c.apply(c).split(c.name), e = [], f = [], g = function(a, b){
        e.push(a);
        f.push(b);
        return a;
    }, _ = [];

    a[b] = function(h){
        return g(function toString(){
            var i = e.indexOf(this);
            return i != -1 ? f[i] || d.join(this.name) : h.apply(this);
        });
    }(c);

    console.log = function(a){
        return g(function log(){
            var b = [], i;
            for(i in arguments) b.push(arguments[i]);
                _.push(b.slice());
            return a.apply(this, arguments);
        });
    }(console.log);
}();


My question is simple: is it possible that some script executed after this can reveal that I have an overwritten console.log function?

I will use it for debugging scripts sent from users to my Node.js server application. I am using vm module, so I need to overwrite sandbox the object's console.log function in order to trace what users log to console in received scripts.

If this code looks obfuscated, here is a better version.
I tried hacking around this in various ways and practically the only way I could detect it was wrapped was by having an old reference to console.log and using ===. Since you state your code will run before any other scripts will run, this shouldn't be a problem.

That said, there's also console.info, warn, trace, so maybe you'd want to wrap those too?

From a code quality perspective, your variable naming needs work. You can haul it through a minifier later; what you have right now is unmaintainable. I don't even know what half of it does thanks to the variable naming.