Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Handlebars logging - tips for debugging templates!
/*
* 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
*/
@travcunn
Copy link

travcunn commented Sep 28, 2015

Thanks a bunch for this

@jarodsmk
Copy link

jarodsmk commented Mar 28, 2017

Been looking for something like this & happened to come across this gist, thanks for sharing. Still pretty relevant now

@SandeepVattapparambil
Copy link

SandeepVattapparambil commented Oct 8, 2018

Thank you so much

@MasterSergius
Copy link

MasterSergius commented Apr 1, 2021

Thanks from 2021, it works still )

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment