diff --git a/core/modules/utils/logger.js b/core/modules/utils/logger.js index f89e40304..babb322b5 100644 --- a/core/modules/utils/logger.js +++ b/core/modules/utils/logger.js @@ -36,37 +36,43 @@ Alert a message Logger.prototype.alert = function(/* args */) { // Prepare the text of the alert var text = Array.prototype.join.call(arguments," "); - // Check if there is an existing alert with the same text and the same component - var existingAlerts = $tw.wiki.getTiddlersWithTag(ALERT_TAG), - alertFields, - existingCount, - self = this; - $tw.utils.each(existingAlerts,function(title) { - var tiddler = $tw.wiki.getTiddler(title); - if(tiddler.fields.text === text && tiddler.fields.component === self.componentName && tiddler.fields.modified && (!alertFields || tiddler.fields.modified < alertFields.modified)) { - alertFields = $tw.utils.extend({},tiddler.fields); + // Create alert tiddlers in the browser + if($tw.browser) { + // Check if there is an existing alert with the same text and the same component + var existingAlerts = $tw.wiki.getTiddlersWithTag(ALERT_TAG), + alertFields, + existingCount, + self = this; + $tw.utils.each(existingAlerts,function(title) { + var tiddler = $tw.wiki.getTiddler(title); + if(tiddler.fields.text === text && tiddler.fields.component === self.componentName && tiddler.fields.modified && (!alertFields || tiddler.fields.modified < alertFields.modified)) { + alertFields = $tw.utils.extend({},tiddler.fields); + } + }); + if(alertFields) { + existingCount = alertFields.count || 1; + } else { + alertFields = { + title: $tw.wiki.generateNewTitle("$:/temp/alerts/alert",{prefix: ""}), + text: text, + tags: [ALERT_TAG], + component: this.componentName + }; + existingCount = 0; } - }); - if(alertFields) { - existingCount = alertFields.count || 1; + alertFields.modified = new Date(); + if(++existingCount > 1) { + alertFields.count = existingCount; + } else { + alertFields.count = undefined; + } + $tw.wiki.addTiddler(new $tw.Tiddler(alertFields)); + // Log the alert as well + this.log.apply(this,Array.prototype.slice.call(arguments,0)); } else { - alertFields = { - title: $tw.wiki.generateNewTitle("$:/temp/alerts/alert",{prefix: ""}), - text: text, - tags: [ALERT_TAG], - component: this.componentName - }; - existingCount = 0; + // Print an orange message to the console if not in the browser + console.error("\x1b[1;33m" + text + "\x1b[0m"); } - alertFields.modified = new Date(); - if(++existingCount > 1) { - alertFields.count = existingCount; - } else { - alertFields.count = undefined; - } - $tw.wiki.addTiddler(new $tw.Tiddler(alertFields)); - // Log it too - this.log.apply(this,Array.prototype.slice.call(arguments,0)); }; exports.Logger = Logger;