forked from mirrors/Scribe.js
Add custom colors options for context part
This commit is contained in:
parent
fb1f58cb57
commit
30d39b8232
1 changed files with 42 additions and 17 deletions
|
@ -184,7 +184,13 @@
|
||||||
* @param {int} opt.contextMediumSize Medium size of the context part of a log message.
|
* @param {int} opt.contextMediumSize Medium size of the context part of a log message.
|
||||||
* Used when calculating indent. Default to 45.
|
* Used when calculating indent. Default to 45.
|
||||||
* @param {int} opt.spaceSize Space between context part and log part. Default to 4.
|
* @param {int} opt.spaceSize Space between context part and log part. Default to 4.
|
||||||
|
*
|
||||||
* @param {Array|String} opt.colors Default colors output for all loggers. Default ['cyan'].
|
* @param {Array|String} opt.colors Default colors output for all loggers. Default ['cyan'].
|
||||||
|
* @param {Array|String} opt.tagsColors Default colors output for tags. Default undefined.
|
||||||
|
* @param {Array|String} opt.timeColors Default colors output for time. Default undefined.
|
||||||
|
* @param {Array|String} opt.dateColors Default colors output for date. Default undefined.
|
||||||
|
* @param {Array|String} opt.fileColors Default colors output for filename. Default undefined.
|
||||||
|
* @param {Array|String} opt.lineColors Default colors output for line number. Default undefined.
|
||||||
*
|
*
|
||||||
* @param {Boolean} opt.alwaysTags Always print tags (even without tag() ). Default false.
|
* @param {Boolean} opt.alwaysTags Always print tags (even without tag() ). Default false.
|
||||||
* @param {Boolean} opt.alwaysLocation Always print location (even without file() ). Default false.
|
* @param {Boolean} opt.alwaysLocation Always print location (even without file() ). Default false.
|
||||||
|
@ -211,6 +217,11 @@
|
||||||
spaceSize : opt.spaceSize || 4,
|
spaceSize : opt.spaceSize || 4,
|
||||||
|
|
||||||
colors : opt.colors || "cyan",
|
colors : opt.colors || "cyan",
|
||||||
|
tagsColors : opt.tagsColors,
|
||||||
|
timeColors : opt.timeColors,
|
||||||
|
dateColors : opt.dateColors,
|
||||||
|
lineColors : opt.lineColors,
|
||||||
|
fileColors : opt.fileColors,
|
||||||
|
|
||||||
alwaysTags : opt.alwaysTags === true,
|
alwaysTags : opt.alwaysTags === true,
|
||||||
alwaysLocation : opt.alwaysLocation === true,
|
alwaysLocation : opt.alwaysLocation === true,
|
||||||
|
@ -357,25 +368,25 @@
|
||||||
|
|
||||||
if (opt.tags && log.context.tags) {
|
if (opt.tags && log.context.tags) {
|
||||||
var tags = buildTags(log.context.tags);
|
var tags = buildTags(log.context.tags);
|
||||||
result += tags.msg + space;
|
result += applyColors(tags.msg, log.opt.tagsColors) + space;
|
||||||
length += tags.msgLength + space.length;
|
length += tags.msgLength + space.length;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (opt.location && log.context.location.filename && log.context.location.line) {
|
if (opt.location && log.context.location.filename && log.context.location.line) {
|
||||||
var infos = buildFileInfos(log.context.location);
|
var infos = buildFileInfos(log.context.location, log.opt.fileColors, log.opt.lineColors);
|
||||||
result += infos.msg + space;
|
result += infos.msg + space;
|
||||||
length += infos.msgLength + space.length;
|
length += infos.msgLength + space.length;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (opt.time && log.context.time) {
|
if (opt.time && log.context.time) {
|
||||||
var time = buildTime(log.context.time);
|
var time = buildTime(log.context.time);
|
||||||
result += time.msg + space;
|
result += applyColors(time.msg, log.opt.timeColors) + space;
|
||||||
length += time.msgLength + space.length;
|
length += time.msgLength + space.length;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (opt.date && log.context.time) {
|
if (opt.date && log.context.time) {
|
||||||
var date = buildDate(log.context.time);
|
var date = buildDate(log.context.time);
|
||||||
result += date.msg + space;
|
result += applyColors(date.msg, log.opt.dateColors) + space;
|
||||||
length += date.msgLength + space.length;
|
length += date.msgLength + space.length;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -449,10 +460,18 @@
|
||||||
* You can then use it with console.myNewLogger
|
* You can then use it with console.myNewLogger
|
||||||
*
|
*
|
||||||
* @param {String} name The name of the logger.
|
* @param {String} name The name of the logger.
|
||||||
* @param {String} colors Optional. Colors of the console output. Default cyan.
|
* @param {Array|String} colors Optional colorsjs colors of the console output.
|
||||||
|
* Override constructor default.
|
||||||
* See text colors from https://github.com/Marak/colors.js
|
* See text colors from https://github.com/Marak/colors.js
|
||||||
*
|
*
|
||||||
* @param {Object} opt Optional options object. @see Console2 opt for default values.
|
* @param {Object} opt Optional options object. @see Console2 opt for default values.
|
||||||
|
*
|
||||||
|
* @param {Array|String} opt.tagsColors Default colors output for tags. Default undefined.
|
||||||
|
* @param {Array|String} opt.timeColors Default colors output for time. Default undefined.
|
||||||
|
* @param {Array|String} opt.dateColors Default colors output for date. Default undefined.
|
||||||
|
* @param {Array|String} opt.fileColors Default colors output for filename. Default undefined.
|
||||||
|
* @param {Array|String} opt.lineColors Default colors output for line number. Default undefined.
|
||||||
|
*
|
||||||
* @param {Boolean} opt.logInConsole Should the logger print to the console ?
|
* @param {Boolean} opt.logInConsole Should the logger print to the console ?
|
||||||
* @param {Boolean} opt.logInFile If the log should be save in file.
|
* @param {Boolean} opt.logInFile If the log should be save in file.
|
||||||
* @param {Boolean} opt.alwaysTags Always print tags (even without tag() )
|
* @param {Boolean} opt.alwaysTags Always print tags (even without tag() )
|
||||||
|
@ -471,8 +490,15 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
opt.name = name;
|
opt.name = name;
|
||||||
opt.colors = colors || this.opt.colors;
|
|
||||||
opt.type = opt.type || opt.name;
|
opt.type = opt.type || opt.name;
|
||||||
|
|
||||||
|
opt.colors = colors || this.opt.colors;
|
||||||
|
opt.tagsColors = opt.tagsColors || this.opt.tagsColors;
|
||||||
|
opt.timeColors = opt.timeColors || this.opt.timeColors;
|
||||||
|
opt.dateColors = opt.dateColors || this.opt.dateColors;
|
||||||
|
opt.fileColors = opt.fileColors || this.opt.fileColors;
|
||||||
|
opt.lineColors = opt.lineColors || this.opt.lineColors;
|
||||||
|
|
||||||
opt.logInConsole = opt.logInConsole || this.opt.logInConsole;
|
opt.logInConsole = opt.logInConsole || this.opt.logInConsole;
|
||||||
opt.logInFile = opt.logInFile || this.opt.logInFile;
|
opt.logInFile = opt.logInFile || this.opt.logInFile;
|
||||||
opt.alwaysTags = opt.alwaysTags || this.opt.alwaysTags;
|
opt.alwaysTags = opt.alwaysTags || this.opt.alwaysTags;
|
||||||
|
@ -480,7 +506,6 @@
|
||||||
opt.alwaysTime = opt.alwaysTime || this.opt.alwaysTime;
|
opt.alwaysTime = opt.alwaysTime || this.opt.alwaysTime;
|
||||||
opt.alwaysDate = opt.alwaysDate || this.opt.alwaysDate;
|
opt.alwaysDate = opt.alwaysDate || this.opt.alwaysDate;
|
||||||
|
|
||||||
|
|
||||||
this[name] = function () {
|
this[name] = function () {
|
||||||
|
|
||||||
var location = getLocation();
|
var location = getLocation();
|
||||||
|
|
Loading…
Add table
Reference in a new issue