kopia lustrzana https://github.com/miklobit/TiddlyWiki5
Syncer: allow logging to be disabled
We don't want the syncer used by the savetrail plugin to be loggingprint-window-tiddler
rodzic
1dcc8c99e5
commit
05a3d9a302
|
@ -42,8 +42,12 @@ function Syncer(options) {
|
||||||
this.throttleInterval = options.throttleInterval || this.throttleInterval;
|
this.throttleInterval = options.throttleInterval || this.throttleInterval;
|
||||||
this.fallbackInterval = options.fallbackInterval || this.fallbackInterval;
|
this.fallbackInterval = options.fallbackInterval || this.fallbackInterval;
|
||||||
this.pollTimerInterval = options.pollTimerInterval || this.pollTimerInterval;
|
this.pollTimerInterval = options.pollTimerInterval || this.pollTimerInterval;
|
||||||
|
this.logging = "logging" in options ? options.logging : true;
|
||||||
// Make a logger
|
// Make a logger
|
||||||
this.logger = new $tw.utils.Logger("syncer" + ($tw.browser ? "-browser" : "") + ($tw.node ? "-server" : "") + (this.syncadaptor.name ? ("-" + this.syncadaptor.name) : ""),{colour: "cyan"});
|
this.logger = new $tw.utils.Logger("syncer" + ($tw.browser ? "-browser" : "") + ($tw.node ? "-server" : "") + (this.syncadaptor.name ? ("-" + this.syncadaptor.name) : ""),{
|
||||||
|
colour: "cyan",
|
||||||
|
enable: this.logging
|
||||||
|
});
|
||||||
// Compile the dirty tiddler filter
|
// Compile the dirty tiddler filter
|
||||||
this.filterFn = this.wiki.compileFilter(this.wiki.getTiddlerText(this.titleSyncFilter));
|
this.filterFn = this.wiki.compileFilter(this.wiki.getTiddlerText(this.titleSyncFilter));
|
||||||
// Record information for known tiddlers
|
// Record information for known tiddlers
|
||||||
|
|
|
@ -21,13 +21,14 @@ function Logger(componentName,options) {
|
||||||
options = options || {};
|
options = options || {};
|
||||||
this.componentName = componentName || "";
|
this.componentName = componentName || "";
|
||||||
this.colour = options.colour || "white";
|
this.colour = options.colour || "white";
|
||||||
|
this.enable = "enable" in options ? options.enable : true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Log a message
|
Log a message
|
||||||
*/
|
*/
|
||||||
Logger.prototype.log = function(/* args */) {
|
Logger.prototype.log = function(/* args */) {
|
||||||
if(console !== undefined && console.log !== undefined) {
|
if(this.enable && console !== undefined && console.log !== undefined) {
|
||||||
return Function.apply.call(console.log, console, [$tw.utils.terminalColour(this.colour),this.componentName + ":"].concat(Array.prototype.slice.call(arguments,0)).concat($tw.utils.terminalColour()));
|
return Function.apply.call(console.log, console, [$tw.utils.terminalColour(this.colour),this.componentName + ":"].concat(Array.prototype.slice.call(arguments,0)).concat($tw.utils.terminalColour()));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -36,44 +37,46 @@ Logger.prototype.log = function(/* args */) {
|
||||||
Alert a message
|
Alert a message
|
||||||
*/
|
*/
|
||||||
Logger.prototype.alert = function(/* args */) {
|
Logger.prototype.alert = function(/* args */) {
|
||||||
// Prepare the text of the alert
|
if(this.enable) {
|
||||||
var text = Array.prototype.join.call(arguments," ");
|
// Prepare the text of the alert
|
||||||
// Create alert tiddlers in the browser
|
var text = Array.prototype.join.call(arguments," ");
|
||||||
if($tw.browser) {
|
// Create alert tiddlers in the browser
|
||||||
// Check if there is an existing alert with the same text and the same component
|
if($tw.browser) {
|
||||||
var existingAlerts = $tw.wiki.getTiddlersWithTag(ALERT_TAG),
|
// Check if there is an existing alert with the same text and the same component
|
||||||
alertFields,
|
var existingAlerts = $tw.wiki.getTiddlersWithTag(ALERT_TAG),
|
||||||
existingCount,
|
alertFields,
|
||||||
self = this;
|
existingCount,
|
||||||
$tw.utils.each(existingAlerts,function(title) {
|
self = this;
|
||||||
var tiddler = $tw.wiki.getTiddler(title);
|
$tw.utils.each(existingAlerts,function(title) {
|
||||||
if(tiddler.fields.text === text && tiddler.fields.component === self.componentName && tiddler.fields.modified && (!alertFields || tiddler.fields.modified < alertFields.modified)) {
|
var tiddler = $tw.wiki.getTiddler(title);
|
||||||
alertFields = $tw.utils.extend({},tiddler.fields);
|
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;
|
||||||
}
|
}
|
||||||
});
|
alertFields.modified = new Date();
|
||||||
if(alertFields) {
|
if(++existingCount > 1) {
|
||||||
existingCount = alertFields.count || 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 {
|
} else {
|
||||||
alertFields = {
|
// Print an orange message to the console if not in the browser
|
||||||
title: $tw.wiki.generateNewTitle("$:/temp/alerts/alert",{prefix: ""}),
|
console.error("\x1b[1;33m" + text + "\x1b[0m");
|
||||||
text: text,
|
}
|
||||||
tags: [ALERT_TAG],
|
|
||||||
component: this.componentName
|
|
||||||
};
|
|
||||||
existingCount = 0;
|
|
||||||
}
|
|
||||||
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 {
|
|
||||||
// Print an orange message to the console if not in the browser
|
|
||||||
console.error("\x1b[1;33m" + text + "\x1b[0m");
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Ładowanie…
Reference in New Issue