summaryrefslogtreecommitdiffstats
path: root/lib/handlebars/base.js
diff options
context:
space:
mode:
Diffstat (limited to 'lib/handlebars/base.js')
-rw-r--r--lib/handlebars/base.js23
1 files changed, 21 insertions, 2 deletions
diff --git a/lib/handlebars/base.js b/lib/handlebars/base.js
index 03f41ef..d658b3d 100644
--- a/lib/handlebars/base.js
+++ b/lib/handlebars/base.js
@@ -62,6 +62,24 @@ Handlebars.createFrame = Object.create || function(object) {
return obj;
};
+Handlebars.logger = {
+ DEBUG: 0, INFO: 1, WARN: 2, ERROR: 3, level: 3,
+
+ methodMap: {0: 'debug', 1: 'info', 2: 'warn', 3: 'error'},
+
+ // can be overridden in the host environment
+ log: function(level, obj) {
+ if (Handlebars.logger.level <= level) {
+ var method = Handlebars.logger.methodMap[level];
+ if (typeof console !== 'undefined' && console[method]) {
+ console[method].call(console, obj);
+ }
+ }
+ }
+};
+
+Handlebars.log = function(level, obj) { Handlebars.logger.log(level, obj); };
+
Handlebars.registerHelper('each', function(context, options) {
var fn = options.fn, inverse = options.inverse;
var i = 0, ret = "", data;
@@ -117,8 +135,9 @@ Handlebars.registerHelper('with', function(context, options) {
return options.fn(context);
});
-Handlebars.registerHelper('log', function(context) {
- Handlebars.log(context);
+Handlebars.registerHelper('log', function(context, options) {
+ var level = options.data && options.data.level != null ? parseInt(options.data.level, 10) : 1;
+ Handlebars.log(level, context);
});
}(this.Handlebars));