Created
August 27, 2012 12:17
-
-
Save karlwestin/3487951 to your computer and use it in GitHub Desktop.
Handlebars logging - tips for debugging templates!
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Use this to turn on logging: (in your local extensions file) | |
*/ | |
Handlebars.logger.log = function(level) { | |
if(level >= Handlebars.logger.level) { | |
console.log.apply(console, [].concat(["Handlebars: "], _.toArray(arguments))); | |
} | |
}; | |
// DEBUG: 0, INFO: 1, WARN: 2, ERROR: 3, | |
Handlebars.registerHelper('log', Handlebars.logger.log); | |
// Std level is 3, when set to 0, handlebars will log all compilation results | |
Handlebars.logger.level = 3; | |
/* | |
* Log can also be used in templates: '{{log 0 this "myString" accountName}}' | |
* Logs all the passed data when logger.level = 0 | |
*/ |
Been looking for something like this & happened to come across this gist, thanks for sharing. Still pretty relevant now
Thank you so much
Thanks from 2021, it works still )
hmm i get "cannot read properties of undefined (reading 'log')" on Handlebars.logger.log
looks like i was missing
Handlerbars.logger = {
methodMap: { 0: 'debug', 1: 'info', 2: 'warn', 3: 'error' },
// State enum
DEBUG: 0,
INFO: 1,
WARN: 2,
ERROR: 3,
};
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks a bunch for this