mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2024-11-26 19:47:20 +00:00
Better logging
This commit is contained in:
parent
37ca86ff3d
commit
3f9561dd95
@ -46,15 +46,6 @@ if($tw.node) {
|
||||
|
||||
/////////////////////////// Utility functions
|
||||
|
||||
/*
|
||||
Log a message
|
||||
*/
|
||||
$tw.utils.log = function(/* args */) {
|
||||
if(console !== undefined && console.log !== undefined) {
|
||||
return Function.apply.call(console.log, console, arguments);
|
||||
}
|
||||
};
|
||||
|
||||
/*
|
||||
Check if an object has a property
|
||||
*/
|
||||
|
@ -16,10 +16,13 @@ var widget = require("$:/core/modules/widgets/widget.js");
|
||||
|
||||
exports.startup = function() {
|
||||
var modules,n,m,f,commander;
|
||||
// Load modules
|
||||
// Load utility modules and initialise the logger
|
||||
$tw.modules.applyMethods("utils",$tw.utils);
|
||||
$tw.logger = new $tw.utils.Logger();
|
||||
$tw.log = $tw.logger.log;
|
||||
// Load other modules
|
||||
$tw.modules.applyMethods("global",$tw);
|
||||
$tw.modules.applyMethods("config",$tw.config);
|
||||
$tw.modules.applyMethods("utils",$tw.utils);
|
||||
if($tw.browser) {
|
||||
$tw.utils.getBrowserInfo($tw.browser);
|
||||
}
|
||||
|
@ -19,6 +19,8 @@ wiki: wiki to be synced
|
||||
function Syncer(options) {
|
||||
var self = this;
|
||||
this.wiki = options.wiki;
|
||||
// Make a logger
|
||||
this.log = $tw.logger.makeLog("syncer");
|
||||
// Find a working syncadaptor
|
||||
this.syncadaptor = undefined;
|
||||
$tw.modules.forEachModuleOfType("syncadaptor",function(title,module) {
|
||||
@ -37,17 +39,7 @@ Error handling
|
||||
*/
|
||||
Syncer.prototype.showError = function(error) {
|
||||
alert("Syncer error: " + error);
|
||||
$tw.utils.log("Syncer error: " + error);
|
||||
};
|
||||
|
||||
/*
|
||||
Message logging
|
||||
*/
|
||||
Syncer.prototype.log = function(/* arguments */) {
|
||||
var args = Array.prototype.slice.call(arguments,0);
|
||||
args[0] = "Syncer: " + args[0];
|
||||
// Temporarily disable logging to help the wood vs. trees situation; we need better filtering of log messages
|
||||
//$tw.utils.log.apply(null,args);
|
||||
this.log("Syncer error: " + error);
|
||||
};
|
||||
|
||||
/*
|
||||
@ -384,7 +376,7 @@ Syncer.prototype.processTaskQueue = function() {
|
||||
// Dispatch the task
|
||||
this.dispatchTask(task,function(err) {
|
||||
if(err) {
|
||||
console.log("Sync error while processing '" + task.title + "':\n" + err);
|
||||
self.showError("Sync error while processing '" + task.title + "':\n" + err);
|
||||
}
|
||||
// Mark that this task is no longer in progress
|
||||
delete self.taskInProgress[task.title];
|
||||
|
43
core/modules/utils/logger.js
Normal file
43
core/modules/utils/logger.js
Normal file
@ -0,0 +1,43 @@
|
||||
/*\
|
||||
title: $:/core/modules/utils/logger.js
|
||||
type: application/javascript
|
||||
module-type: utils
|
||||
|
||||
A basic logging implementation
|
||||
|
||||
\*/
|
||||
(function(){
|
||||
|
||||
/*jslint node: true, browser: true */
|
||||
/*global $tw: false */
|
||||
"use strict";
|
||||
|
||||
/*
|
||||
Make a new logger
|
||||
*/
|
||||
function Logger() {
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
Make a log function for a particular component
|
||||
*/
|
||||
Logger.prototype.makeLog = function(componentName) {
|
||||
var self = this;
|
||||
return function(/* args */) {
|
||||
self.log.apply(self.log,[componentName + ":"].concat(Array.prototype.slice.call(arguments,0)));
|
||||
};
|
||||
};
|
||||
|
||||
/*
|
||||
Log a message
|
||||
*/
|
||||
Logger.prototype.log = function(/* args */) {
|
||||
if(console !== undefined && console.log !== undefined) {
|
||||
return Function.apply.call(console.log, console, arguments);
|
||||
}
|
||||
};
|
||||
|
||||
exports.Logger = Logger;
|
||||
|
||||
})();
|
@ -21,12 +21,12 @@ function FileSystemAdaptor(syncer) {
|
||||
this.syncer = syncer;
|
||||
this.watchers = {};
|
||||
this.pending = {};
|
||||
|
||||
this.log = $tw.logger.makeLog("FileSystem");
|
||||
this.setwatcher = function(filename, title) {
|
||||
return undefined;
|
||||
return this.watchers[filename] = this.watchers[filename] ||
|
||||
fs.watch(filename, {persistent: false}, function(e) {
|
||||
console.log("Filesystem:", e, filename);
|
||||
self.log("Error:",e,filename);
|
||||
if(e === "change") {
|
||||
var tiddlers = $tw.loadTiddlersFromFile(filename).tiddlers;
|
||||
for(var t in tiddlers) {
|
||||
@ -161,7 +161,7 @@ FileSystemAdaptor.prototype.saveTiddler = function(tiddler,callback) {
|
||||
if(err) {
|
||||
return callback(err);
|
||||
}
|
||||
console.log("FileSystem: Saved file",fileInfo.filepath);
|
||||
self.log("Saved file",fileInfo.filepath);
|
||||
_finish();
|
||||
});
|
||||
});
|
||||
@ -173,7 +173,7 @@ console.log("FileSystem: Saved file",fileInfo.filepath);
|
||||
if(err) {
|
||||
return callback(err);
|
||||
}
|
||||
console.log("FileSystem: Saved file",fileInfo.filepath);
|
||||
self.log("Saved file",fileInfo.filepath);
|
||||
_finish();
|
||||
});
|
||||
}
|
||||
@ -211,7 +211,7 @@ FileSystemAdaptor.prototype.deleteTiddler = function(title,callback) {
|
||||
if(err) {
|
||||
return callback(err);
|
||||
}
|
||||
console.log("FileSystem: Deleted file",fileInfo.filepath);
|
||||
self.log("Deleted file",fileInfo.filepath);
|
||||
// Delete the metafile if present
|
||||
if(fileInfo.hasMetaFile) {
|
||||
fs.unlink(fileInfo.filepath + ".meta",function(err) {
|
||||
|
Loading…
Reference in New Issue
Block a user