1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-11-16 14:54:51 +00:00

Initial improvements

This commit is contained in:
Jermolene 2019-01-17 15:20:24 +00:00
parent 3afb251b3a
commit 22a85e8fc7
5 changed files with 29 additions and 9 deletions

View File

@ -120,7 +120,7 @@ Command.prototype.fetchFile = function(url,options,callback,redirectCount) {
}
});
response.on("error",function(e) {
console.log("Error on GET request: " + e);
self.commander.log("Error on GET request: " + e);
callback(e);
});
});

View File

@ -52,7 +52,7 @@ Command.prototype.execute = function() {
var text = type === "text/html" ? container.innerHTML : container.textContent,
filepath = path.resolve(self.commander.outputPath,wiki.filterTiddlers(filenameFilter,$tw.rootWidget,wiki.makeTiddlerIterator([title]))[0]);
if(self.commander.verbose) {
console.log("Rendering \"" + title + "\" to \"" + filepath + "\"");
self.commander.log("Rendering \"" + title + "\" to \"" + filepath + "\"");
}
$tw.utils.createFileDirectories(filepath);
fs.writeFileSync(filepath,text,"utf8");

View File

@ -40,7 +40,7 @@ Command.prototype.execute = function() {
contentTypeInfo = $tw.config.contentTypeInfo[type] || {encoding: "utf8"},
filepath = path.resolve(self.commander.outputPath,wiki.filterTiddlers(filenameFilter,$tw.rootWidget,wiki.makeTiddlerIterator([title]))[0]);
if(self.commander.verbose) {
console.log("Saving \"" + title + "\" to \"" + filepath + "\"");
self.commander.log("Saving \"" + title + "\" to \"" + filepath + "\"");
}
$tw.utils.createFileDirectories(filepath);
fs.writeFileSync(filepath,tiddler.fields.text,contentTypeInfo.encoding);

View File

@ -31,6 +31,8 @@ function Server(options) {
this.authenticators = options.authenticators || [];
this.wiki = options.wiki;
this.servername = $tw.utils.transliterateToSafeASCII(this.wiki.getTiddlerText("$:/SiteTitle") || "TiddlyWiki5");
this.logger = new $tw.utils.Logger("server",{colour: "cyan"});
this.logger.setPrefix(":" + process.pid + "-" + (Number(new Date()) - 1095776640000));
// Initialise the variables
this.variables = $tw.utils.extend({},this.defaultVariables);
if(options.variables) {
@ -186,9 +188,9 @@ Server.prototype.requestHandler = function(request,response) {
var route = self.findMatchingRoute(request,state);
// Optionally output debug info
if(self.get("debug-level") !== "none") {
console.log("Request path:",JSON.stringify(state.urlInfo));
console.log("Request headers:",JSON.stringify(request.headers));
console.log("authenticatedUsername:",state.authenticatedUsername);
self.logger.log("Request path:",JSON.stringify(state.urlInfo.href));
self.logger.log("Request headers:",JSON.stringify(request.headers));
self.logger.log("authenticatedUsername:",state.authenticatedUsername);
}
// Return a 404 if we didn't find a route
if(!route) {
@ -239,8 +241,7 @@ Server.prototype.listen = function(port,host) {
if(parseInt(port,10).toString() !== port) {
port = process.env[port] || 8080;
}
$tw.utils.log("Serving on " + this.protocol + "://" + host + ":" + port,"brown/orange");
$tw.utils.log("(press ctrl-C to exit)","red");
this.logger.log("Serving on " + this.protocol + "://" + host + ":" + port,"(press ctrl-C to exit)");
// Warn if required plugins are missing
if(!$tw.wiki.getTiddler("$:/plugins/tiddlywiki/tiddlyweb") || !$tw.wiki.getTiddler("$:/plugins/tiddlywiki/filesystem")) {
$tw.utils.warning("Warning: Plugins required for client-server operation (\"tiddlywiki/filesystem\" and \"tiddlywiki/tiddlyweb\") are missing from tiddlywiki.info file");

View File

@ -21,15 +21,34 @@ function Logger(componentName,options) {
options = options || {};
this.componentName = componentName || "";
this.colour = options.colour || "white";
this.prefix = options.prefix || "";
this.enable = "enable" in options ? options.enable : true;
}
/*
Change the output colour
*/
Logger.prototype.setColour = function(colour) {
this.colour = colour || "white";
};
/*
Change the prefix
*/
Logger.prototype.setPrefix = function(prefix) {
this.prefix = prefix || "";
};
/*
Log a message
*/
Logger.prototype.log = function(/* args */) {
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,[
(new Date()).toISOString() + " [" +
this.componentName + this.prefix + "]" +
$tw.utils.terminalColour(this.colour)
].concat(Array.prototype.slice.call(arguments,0)).concat($tw.utils.terminalColour()));
}
};