created less.log_level setting

This will control the amount of logging in the javascript console that
less will do while parsing.

Options are:
    2 - Information and errors
    1 - Errors
    0 - None

Defaults to 2
This commit is contained in:
Rik
2013-07-24 10:52:04 +02:00
parent 4c51ff1914
commit 3a4a2074aa

View File

@@ -11,6 +11,13 @@ less.env = less.env || (location.hostname == '127.0.0.1' ||
isFileProtocol ? 'development'
: 'production');
// The amount of logging in the javascript console.
// 2 - Information and errors
// 1 - Errors
// 0 - None
// Defaults to 2
less.log_level = typeof(less.log_level) != 'undefined' ? less.log_level : 2
// Load styles asynchronously (default: false)
//
// This is set to `false` by default, so that the body
@@ -117,13 +124,13 @@ less.refresh = function (reload, newVars) {
return error(e, sheet.href);
}
if (env.local) {
log("loading " + sheet.href + " from cache.");
log("loading " + sheet.href + " from cache.", 2);
} else {
log("parsed " + sheet.href + " successfully.");
log("parsed " + sheet.href + " successfully.", 2);
createCSS(root.toCSS(less), sheet, env.lastModified);
}
log("css for " + sheet.href + " generated in " + (new(Date) - endTime) + 'ms');
(env.remaining === 0) && log("css generated in " + (new(Date) - startTime) + 'ms');
log("css for " + sheet.href + " generated in " + (new(Date) - endTime) + 'ms', 2);
(env.remaining === 0) && log("css generated in " + (new(Date) - startTime) + 'ms', 2);
endTime = new(Date);
}, reload, newVars);
@@ -416,13 +423,13 @@ function createCSS(styles, sheet, lastModified) {
// Don't update the local store if the file wasn't modified
if (lastModified && cache) {
log('saving ' + href + ' to cache.');
log('saving ' + href + ' to cache.', 2);
try {
cache.setItem(href, styles);
cache.setItem(href + ':timestamp', lastModified);
} catch(e) {
//TODO - could do with adding more robust error handling
log('failed to save');
log('failed to save', 1);
}
}
}
@@ -434,7 +441,7 @@ function xhr(url, type, callback, errback) {
if (typeof(xhr.overrideMimeType) === 'function') {
xhr.overrideMimeType('text/css');
}
log("XHR: Getting '" + url + "'");
log("XHR: Getting '" + url + "'", 2);
xhr.open('GET', url, async);
xhr.setRequestHeader('Accept', type || 'text/x-less, text/css; q=0.9, */*; q=0.5');
xhr.send(null);
@@ -472,7 +479,7 @@ function getXMLHttpRequest() {
try {
return new(ActiveXObject)("MSXML2.XMLHTTP.3.0");
} catch (e) {
log("browser doesn't support AJAX.");
log("browser doesn't support AJAX.", 1);
return null;
}
}
@@ -482,8 +489,10 @@ function removeNode(node) {
return node && node.parentNode.removeChild(node);
}
function log(str) {
if (less.env == 'development' && typeof(console) !== "undefined") { console.log('less: ' + str) }
function log(str, level) {
if (less.env == 'development' && typeof(console) !== 'undefined' && less.log_level >= level) {
console.log('less: ' + str)
}
}
function error(e, rootHref) {