diff --git a/core/modules/commands/fetch.js b/core/modules/commands/fetch.js index 07cda691c..5518277f6 100644 --- a/core/modules/commands/fetch.js +++ b/core/modules/commands/fetch.js @@ -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); }); }); diff --git a/core/modules/commands/render.js b/core/modules/commands/render.js index b396deef9..1ae28dd11 100644 --- a/core/modules/commands/render.js +++ b/core/modules/commands/render.js @@ -47,7 +47,7 @@ Render individual tiddlers and save the results to the specified files $tw.utils.each(tiddlers,function(title) { var 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 + "\""); } var parser = wiki.parseTiddler(template || title), widgetNode = wiki.makeWidget(parser,{variables: $tw.utils.extend({},variables,{currentTiddler: title,storyTiddler: title})}), @@ -63,4 +63,4 @@ Render individual tiddlers and save the results to the specified files exports.Command = Command; })(); - \ No newline at end of file + diff --git a/core/modules/commands/save.js b/core/modules/commands/save.js index 3cb7ef08c..cf9ff7883 100644 --- a/core/modules/commands/save.js +++ b/core/modules/commands/save.js @@ -48,7 +48,7 @@ Saves individual tiddlers in their raw text or binary format to the specified fi } }); if(self.commander.verbose) { - console.log("Saving \"" + title + "\" to \"" + fileInfo.filepath + "\""); + self.commander.log("Saving \"" + title + "\" to \"" + filepath + "\""); } try { $tw.utils.saveTiddlerToFileSync(tiddler,fileInfo); diff --git a/core/modules/server/server.js b/core/modules/server/server.js index d3c98f8fc..324976f1d 100644 --- a/core/modules/server/server.js +++ b/core/modules/server/server.js @@ -33,7 +33,13 @@ function Server(options) { this.routes = options.routes || []; this.authenticators = options.authenticators || []; this.wiki = options.wiki; + this.logger = new $tw.utils.Logger("server",{colour: "cyan"}); + this.logger.setPrefix(":" + process.pid + "-" + (Number(new Date()) - 1095776640000)); this.boot = options.boot || $tw.boot; + // Name the server and init the boot state + this.servername = $tw.utils.transliterateToSafeASCII(this.get("server-name") || this.wiki.getTiddlerText("$:/SiteTitle") || "TiddlyWiki5"); + this.boot.origin = this.get("origin")? this.get("origin"): this.protocol+"://"+this.get("host")+":"+this.get("port"); + this.boot.pathPrefix = this.get("path-prefix") || ""; // Initialise the variables this.variables = $tw.utils.extend({},this.defaultVariables); if(options.variables) { @@ -92,10 +98,6 @@ function Server(options) { this.protocol = "https"; } this.transport = require(this.protocol); - // Name the server and init the boot state - this.servername = $tw.utils.transliterateToSafeASCII(this.get("server-name") || this.wiki.getTiddlerText("$:/SiteTitle") || "TiddlyWiki5"); - this.boot.origin = this.get("origin")? this.get("origin"): this.protocol+"://"+this.get("host")+":"+this.get("port"); - this.boot.pathPrefix = this.get("path-prefix") || ""; } /* @@ -287,9 +289,9 @@ Server.prototype.requestHandler = function(request,response,options) { 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) { diff --git a/core/modules/utils/logger.js b/core/modules/utils/logger.js index 1bee04646..2e5a9a115 100644 --- a/core/modules/utils/logger.js +++ b/core/modules/utils/logger.js @@ -21,6 +21,7 @@ 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; this.save = "save" in options ? options.save : true; this.saveLimit = options.saveLimit || 100 * 1024; @@ -33,6 +34,20 @@ Logger.prototype.setSaveBuffer = function(logger) { this.saveBufferLogger = logger; }; +/* +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 */