diff --git a/npm/lib/config.js b/npm/lib/config.js index 103f6ee..9c0a422 100644 --- a/npm/lib/config.js +++ b/npm/lib/config.js @@ -27,6 +27,8 @@ const PATTERN_NAME = new RegExp("^[a-zA-Z0-9_-]+$"); const PATTERN_ARTIFACT_ID = new RegExp("^[a-zA-Z0-9-_.]*$"); const CONFIG_FILE = "config.js"; +const logId = require('../package.json').name + " : config"; + Config.prototype.isValid = function () { let value = this.appName; if (!value || !PATTERN_NAME.test(value) || (value.length > 50)) return false; @@ -159,7 +161,6 @@ function Config(defaults) { this.processProject = function (paths) { for (let i = 0; i < paths.length; i++) { let file = fspath.resolve(paths[i], CONFIG_FILE); - logger.writeToLog('Processing config file ' + file + ' with config', this); if (fs.existsSync(file)) { this.configFiles.push(file); } @@ -187,8 +188,8 @@ function Config(defaults) { } } } catch (err) { - console.error('Error reading ' + this.configFiles[i] + ' : ' + err); - console.error('code : ' + output); + logger.writeToLog(`${logId} : Error reading ` + this.configFiles[i] + ' : ' + err); + logger.writeToLog(`${logId} : code : ` + output); throw err; } } diff --git a/npm/lib/context.js b/npm/lib/context.js index 1954762..3d4b4ff 100644 --- a/npm/lib/context.js +++ b/npm/lib/context.js @@ -24,6 +24,7 @@ const extend = require('extend'); const Config = require("./config"); const Handlebars = require('./helpers').handlebars; +const logId = require('../package.json').name + " : context"; function Context(id, config) { this.id = id; @@ -54,17 +55,15 @@ function Context(id, config) { if(!this.paths.length) { return; //not being written by us } - this.logger.writeToLog("Destination path", generator.destinationRoot()); - this.logger.writeToLog("Processor", this.processor); + this.logger.writeToLog(`${logId} : Destination path`, generator.destinationRoot()); return this.processor.scan(this.conf, (relativePath, template) => { let outFile = generator.destinationPath(relativePath); - this.logger.writeToLog("CB : writing to", outFile); try { let compiledTemplate = Handlebars.compile(template); let output = compiledTemplate(this.conf); generator.fs.write(outFile, output); } catch (err) { - this.logger.writeToLog("Template error : " + relativePath, err.message); + this.logger.writeToLog(`${logId} : Template error : ` + relativePath, err.message); } }, this.paths); } diff --git a/npm/lib/control.js b/npm/lib/control.js index 9e7088c..3a85db8 100644 --- a/npm/lib/control.js +++ b/npm/lib/control.js @@ -22,6 +22,8 @@ const fspath = require('path'); const Handlebars = require('./helpers').handlebars; const logger = require('./log'); +const logId = require('../package.json').name + " : control"; + //determines if the passed relative path is a control file or not const CONTROL_FILE = "control.js"; //determines if the passed relative path is a config file or not @@ -68,7 +70,6 @@ Control.prototype.processProject = function() { //it does, so parse it in and run it through Handlebars let template = fs.readFileSync(file, 'utf8'); - logger.writeToLog("Config data for controlBlock " + file, this.config); let compiledTemplate = Handlebars.compile(template); let output = compiledTemplate(this.config); try { @@ -96,11 +97,10 @@ Control.prototype.processProject = function() { } } } catch (err) { - console.log("Error : " + this.path + ":" + output); - logger.writeToLog("Control block error : template", template); + logger.writeToLog(`${logId} : Control block error : template`, template); throw err; } - logger.writeToLog("Control data", this.controlBlock); + logger.writeToLog(`${logId} : Control data`, this.controlBlock); } //controls whether or not a file should be included in a generation diff --git a/npm/lib/fsprocessor.js b/npm/lib/fsprocessor.js index 95d9b69..6ea6d1d 100644 --- a/npm/lib/fsprocessor.js +++ b/npm/lib/fsprocessor.js @@ -24,6 +24,8 @@ const fspath = require('path'); const Control = require('./control'); const logger = require('./log'); +const logId = require('../package.json').name + " : fsprocessor"; + let id = 0; //recursively walk the file tree starting from the specified root @@ -33,7 +35,7 @@ const dirwalk = function (root, tracker, resolver) { if (err) { //TODO : appscan for Java does not like you putting too much info in the error messages, need to check for JS console.error("There was an error reading the template directory"); - logger.writeToLog("Folder error", err); + logger.writeToLog(`${logId} : Folder error`, err); resolver.reject(err); return; } @@ -51,7 +53,7 @@ const dirwalk = function (root, tracker, resolver) { //console.log("Found file " + file + " : " + relativePath); if (err) { console.error("Error reading file "); - logger.writeToLog("File error", err); + logger.writeToLog(`${logId} : File error`, err); resolver.reject(err); return; } @@ -139,12 +141,12 @@ const startWalk = function (config, cb, paths) { const getContentsSync = function (value) { let file = fspath.resolve(value); if (!fs.existsSync(file)) { - logger.writeToLog("Error : specified file does not exist", file); + logger.writeToLog(`${logId} : Error : specified file does not exist`, file); throw "Error : specified file does not exist"; } let stats = fs.statSync(file); if (stats.isDirectory()) { - logger.writeToLog("Error : specified path is a directory", file); + logger.writeToLog(`${logId} : Error : specified path is a directory`, file); throw "Error : specified path is a directory"; } try { @@ -157,7 +159,7 @@ const getContentsSync = function (value) { } } catch (err) { /* istanbul ignore next */ //file error reading checked in other tests - logger.writeToLog("Error : reading : " + file, err); + logger.writeToLog(`${logId} : Error : reading : ` + file, err); /* istanbul ignore next */ throw err; }