netbrain
netbrain

Reputation: 9304

javascript: console.log not working in this context?

(function( $ ){ $.fn.openlayers = function( mapElementId, options ) {
        alert(console.log);
        console.log(options);
        ...
    }
});

Im trying to extend functionality in a javascript library, but much to my suprise, when i got started i realized that nothing was being logged by console.log.. I know that the code is being executed due to the alert() firing properly. However the returned response from the alert function seems to be "function(){}", is that correct? or is in fact console.log and empty function?

So any clues on what's going on here, and why console.log isn't working?


I think i might have found the culprit. Im working with a OpenLayers javascript file, and i can see that their library sets

OpenLayers.Console={log:function(){},...

However, this is uppercase Console, but maybe that doesn't make a difference? I also have to be in the OpenLayers scope, which i can't really see that i am. So i'm still a little baffled. But it would explain why i'm seeing an empty function


This is the output i get from typing "console" in the debug window of chrome after loading the application where this error occurs.

assert: function (){}
count: function (){}
debug: function (){}
dir: function (){}
dirxml: function (){}
error: function (){}
group: function (){}
groupEnd: function (){}
info: function (){}
log: function (){}
profile: function (){}
profileEnd: function (){}
time: function (){}
timeEnd: function (){}
trace: function (){}
warn: function (){}
__proto__: Object

So it would seem that something, possibly the openlayers javascript is overriding the native console.

Upvotes: 2

Views: 9792

Answers (2)

Abhishek Goel
Abhishek Goel

Reputation: 19771

Just click on ALL, you will definitely see the console.log output.

https://i.sstatic.net/peduZ.png

Hope it helps...!!!

Upvotes: 2

dragon
dragon

Reputation: 1785

Add the following line before OpenLayer script to tell it not to override the console functions.

<script type="text/javascript">
    console.firebug=true;
</script>

Upvotes: 1

Related Questions