mirror of
https://github.com/less/less.js.git
synced 2026-04-09 03:00:20 -04:00
Use the log method for logging errors and turn the number into an
enumeration.
This commit is contained in:
@@ -12,12 +12,18 @@ less.env = less.env || (location.hostname == '127.0.0.1' ||
|
||||
isFileProtocol ? 'development'
|
||||
: 'production');
|
||||
|
||||
var logLevel = {
|
||||
info: 2,
|
||||
errors: 1,
|
||||
none: 0
|
||||
};
|
||||
|
||||
// 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;
|
||||
less.log_level = typeof(less.log_level) != 'undefined' ? less.log_level : logLevel.info;
|
||||
|
||||
// Load styles asynchronously (default: false)
|
||||
//
|
||||
@@ -125,14 +131,14 @@ less.refresh = function (reload, newVars) {
|
||||
return error(e, sheet.href);
|
||||
}
|
||||
if (env.local) {
|
||||
log("loading " + sheet.href + " from cache.", 2);
|
||||
log("loading " + sheet.href + " from cache.", logLevel.info);
|
||||
} else {
|
||||
log("parsed " + sheet.href + " successfully.", 2);
|
||||
log("parsed " + sheet.href + " successfully.", logLevel.info);
|
||||
createCSS(root.toCSS(less), sheet, env.lastModified);
|
||||
}
|
||||
log("css for " + sheet.href + " generated in " + (new Date() - endTime) + 'ms', 2);
|
||||
log("css for " + sheet.href + " generated in " + (new Date() - endTime) + 'ms', logLevel.info);
|
||||
if (env.remaining === 0) {
|
||||
log("css generated in " + (new Date() - startTime) + 'ms', 2);
|
||||
log("css generated in " + (new Date() - startTime) + 'ms', logLevel.info);
|
||||
}
|
||||
endTime = new Date();
|
||||
}, reload, newVars);
|
||||
@@ -431,13 +437,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.', 2);
|
||||
log('saving ' + href + ' to cache.', logLevel.info);
|
||||
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', 1);
|
||||
log('failed to save', logLevel.errors);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -449,7 +455,7 @@ function doXHR(url, type, callback, errback) {
|
||||
if (typeof(xhr.overrideMimeType) === 'function') {
|
||||
xhr.overrideMimeType('text/css');
|
||||
}
|
||||
log("XHR: Getting '" + url + "'", 2);
|
||||
log("XHR: Getting '" + url + "'", logLevel.info);
|
||||
xhr.open('GET', url, async);
|
||||
xhr.setRequestHeader('Accept', type || 'text/x-less, text/css; q=0.9, */*; q=0.5');
|
||||
xhr.send(null);
|
||||
@@ -488,7 +494,7 @@ function getXMLHttpRequest() {
|
||||
/*global ActiveXObject */
|
||||
return new ActiveXObject("MSXML2.XMLHTTP.3.0");
|
||||
} catch (e) {
|
||||
log("browser doesn't support AJAX.", 1);
|
||||
log("browser doesn't support AJAX.", logLevel.errors);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -555,7 +561,7 @@ function errorConsole(e, rootHref) {
|
||||
} else if (e.stack) {
|
||||
content += e.stack;
|
||||
}
|
||||
console.log(content);
|
||||
log(content, logLevel.errors);
|
||||
}
|
||||
|
||||
function errorHTML(e, rootHref) {
|
||||
|
||||
@@ -1,2 +1,2 @@
|
||||
OperationError: Can't substract or divide a color from a number in {pathhref}console-errors/test-error.less on line null, column 0:
|
||||
less: OperationError: Can't substract or divide a color from a number in {pathhref}console-errors/test-error.less on line null, column 0:
|
||||
1 prop: (3 / #fff);
|
||||
|
||||
Reference in New Issue
Block a user