Fail over to console.log if lacking console method

This improves logger resiliency under older browsers.
This commit is contained in:
kpdecker
2015-02-07 13:22:31 -06:00
parent 95421271e3
commit cfbef2585d
2 changed files with 7 additions and 5 deletions
+2 -4
View File
@@ -225,11 +225,9 @@ export var logger = {
// Can be overridden in the host environment
log: function(level, message) {
if (logger.level <= level) {
if (typeof console !== 'undefined' && logger.level <= level) {
var method = logger.methodMap[level];
if (typeof console !== 'undefined' && console[method]) {
console[method].call(console, message);
}
(console[method] || console.log).call(console, message);
}
}
};
+5 -1
View File
@@ -276,7 +276,7 @@ describe('builtin helpers', function() {
equals(3, levelArg);
equals("whee", logArg);
});
it('should not output to info', function() {
it('should output to info', function() {
var string = "{{log blah}}";
var hash = { blah: "whee" };
@@ -284,6 +284,10 @@ describe('builtin helpers', function() {
equals("whee", log);
called = true;
};
console.log = function(log) {
equals("whee", log);
called = true;
};
shouldCompileTo(string, hash, "");
equals(true, called);