Skip to content

Commit

Permalink
Merge branch 'master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
Jakeeyturner authored Mar 15, 2017
2 parents 1e3ab8a + 3054a0f commit 3981df6
Show file tree
Hide file tree
Showing 26 changed files with 453 additions and 162 deletions.
2 changes: 1 addition & 1 deletion packages/composer-cli/lib/cmds/archive/createCommand.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ module.exports.handler = (argv) => {
process.exit(0);
})
.catch((error) => {

console.log(error.stack);
console.log(error+ '\nCommand failed.');
process.exit(1);
});
Expand Down
1 change: 1 addition & 0 deletions packages/composer-cli/lib/cmds/archive/lib/create.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ class Create {
);

}).catch(function(e) {
console.log(e.stack);
console.log(e); // "oh, no!"
});

Expand Down
1 change: 1 addition & 0 deletions packages/composer-client/composer-client
21 changes: 16 additions & 5 deletions packages/composer-common/lib/codegen/jsonwriter.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class JSONWriter extends Writer {
*/
writeKey(key) {
this.writeComma();
this.write(`"${key}":`);
this.write(JSON.stringify(key) + ':');
this.log('writeKey', key );
}

Expand All @@ -89,7 +89,7 @@ class JSONWriter extends Writer {
* @param {string} value - the value
*/
writeStringValue(value) {
this.write(`"${value}"`);
this.write(JSON.stringify(value));
this.firstItem = false;
this.log('writeStringValue', value);
}
Expand All @@ -113,7 +113,8 @@ class JSONWriter extends Writer {
*/
writeKeyStringValue(key,value) {
this.writeComma();
this.write(`"${key}":"${value}"`);
this.writeKey(key);
this.writeStringValue(value);
this.firstItem = false;
this.log('writeKeyStringValue', (key + ':' + value));
}
Expand All @@ -126,7 +127,8 @@ class JSONWriter extends Writer {
*/
writeKeyValue(key,value) {
this.writeComma();
this.write(`"${key}": ${value}`);
this.writeKey(key);
this.writeValue(value);
this.firstItem = false;
this.log('writeKeyValue', key + '=' + value);
}
Expand All @@ -138,7 +140,7 @@ class JSONWriter extends Writer {
*/
writeArrayStringValue(value) {
this.writeComma();
this.write(`"${value}"`);
this.writeStringValue(value);
this.firstItem = false;
this.log('writeArrayStringValue', value);
}
Expand Down Expand Up @@ -201,6 +203,15 @@ class JSONWriter extends Writer {
console.log(spaces + ' ' + message + ' ' + callSite );
}
}

/**
* Empties the underyling buffer and resets the line count.
*/
clearBuffer() {
super.clearBuffer();
this.indent = 0;
this.firstItem = true;
}
}

module.exports = JSONWriter;
88 changes: 49 additions & 39 deletions packages/composer-common/lib/log/logger.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,18 @@
*/

'use strict';
// const beautify = require('json-beautify');
// TODO: Will need to do improvement of the formatting with some module.
//

const sprintf = require('sprintf-js').sprintf;
// const config = require('config');
// Moving config to some other location
const Node = require('./node.js');
const Tree = require('./tree.js');


// Root node of the selection tree
let _root = null;
let _tree = null;

// Core logger that is in use (user configurable)
let _logger = null;

// Set of instances of this logger class that acts as a proxy to the core logger
let _clInstances = {};

/**
Expand All @@ -44,21 +45,20 @@ let _clInstances = {};
* Standard log levels are in use. In order these are
* - silly, debug, verbose, info, warn, error
* In addition, there are functions that record method entry and method exit. these
* map down to the debug level.
* map down to the debug level. [Silly level isn't being used]
*
* Examples of using each function are included for each API below.
*
* At the top of the class (or file if not object style). issue.
* At the top of the class (or file if not object style) issue.
*
* ```
* const log = require('./log/logger.js').getLog(<CLASSNAME>);
* log.info(.....)
* ```
* The classname is in a fully qualified format eg common/BusinessNetworkDefinition or
* cli/archiveCreate.
*
* @todo Confirm the format via iterative use
* @todo Precrtiptive on how data is uploaded to logmet etc. ??
*
*
* Comming Soon: Aliases
*
* @private
* @class
Expand Down Expand Up @@ -99,15 +99,22 @@ class Logger {

/**
* @description Main internal logging method
* Required fn here is to form up the arguements into a suitable string, and
* process any errors to capture the stack trace. The core logger is then CALLED
*
* The assumption is that this logger has a method called `log`. with this prototype
* `log(String loglevel, String codeunit, String message, Array[optional] data)`
*
* @param {String} loglevel log loglevel
* @param {String} method method name
* @param {String} msg to log
*/
_intLogMain(loglevel,method,msg){
if (typeof arguments[3] ==='undefined'){
// this is the case where there are no additional arguements; data for example
_logger.log(loglevel,sprintf('%-25s:%-25s', this.className,method+'()'),msg);
} else {
// loop over the aguements - if any are Errors make sure that the stack trace is captured
let args = [];
for(let i = 3; i < arguments.length; i++) {
if (arguments[i] instanceof Error){
Expand Down Expand Up @@ -265,10 +272,9 @@ class Logger {


/**
* @descrption what is the debug environment variable set to
* Note that the _envDebug property of this object is for debugging and
* emergency use ONLY
*
* @description what is the debug environment variable set to
* Note that the _envDebug property of this object is for debugging the debugging log
* and emergency use ONLY
*
* @return {String} String of the DEBUG env variable
*
Expand All @@ -277,7 +283,18 @@ class Logger {
return process.env.DEBUG || this._envDebug || '';
}

/** get the configuration for the logging
/**
* @description Get the configuration for the logging.
* This uses the config module to look for a configuration block under the
* fabric-composer.debug property.
*
* The 'logger' property is required to specify the core logger to use. By
* default this is the 'winstonInjector' that creates and returns a Winston backed
* console and file logger.
*
* The 'config' property is required - but the contents of this property are passed
* as is to the class defined in the logger property.
*
* @return {Object} with the config iformation
*
**/
Expand All @@ -288,8 +305,8 @@ class Logger {
const mod = 'config';
const req = require;
const config = req(mod);
if (config.has('ConcertoConfig.debug')){
return config.get('ConcertoConfig.debug');
if (config.has('fabric-composer.debug')){
return config.get('fabric-composer.debug');
}
} catch (e) {
// We don't care if we can't find the config module, it won't be
Expand Down Expand Up @@ -340,34 +357,31 @@ class Logger {

let concertoConfigElements = [];

if (_root === null){
if (_tree === null){
// need to do the filtering to see if this shold be enabled or not
let string = this.getDebugEnv();
let details = string.split(/[\s,]+/);
_root = new Node('root',false);
// _root = new Node('root',false);
_tree = new Tree();

const regex = /(-?)concerto:(.*)?/;
// now we have an array of the elements that we might need to be enabled
//
for (let i=0; i< details.length;i++){
let e = details[i];
if (e === '*' || e ==='concerto:*'){
_root.include = true;
if (e === '*' || e ==='composer:*'){
_tree.setRootInclusion();
}
// determine if the element is for concerto or not
let machResult = e.match(regex);
if (machResult!==null){
// got a result that we need to trace therefore setup the child node correctly

let newNode = new Node(machResult[2] ,(machResult[1]==='') );
_root.addChildNodeAtStart(newNode);
// got a result that we need to trace therefore setup the child node correctly
_tree.addNode(machResult[2] ,(machResult[1]==='') );

// make a note of the debug settings that permit the config elements
concertoConfigElements.push(machResult[2]);
}

}

}


Expand All @@ -381,18 +395,14 @@ class Logger {
let loggerToUse = localConfig.logger;
let myLogger = require(loggerToUse);

_logger = myLogger.getLogger(localConfig.config,concertoConfigElements);
// primary used to determine what has been abled to allow the logger to
// go into a default mode.. NOT MEANT TO BE USED FOR FILTERTING.
_logger = myLogger.getLogger(localConfig.config,{ 'debug' : concertoConfigElements } );

}

// now we need to check if the name that has come in and should be traced
let n = _root.findChild(concertoLogger.classname);

if ( typeof n ==='undefined'){
concertoLogger.include = _root.isIncluded();
} else {
concertoLogger.include = n.isIncluded();
}
concertoLogger.include = _tree.getInclusion(concertoLogger.className);

return ;
}
Expand All @@ -401,7 +411,7 @@ class Logger {
* @description clean up the logger; required if anything is dynamically changed
*/
static reset(){
_root=null;
_tree=null;
_logger=null;
_clInstances=[];
}
Expand Down
7 changes: 7 additions & 0 deletions packages/composer-common/lib/log/node.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,13 @@ class Node {
}


/**
* @description Set the node to be an inclusion
*/
setIncluded(){
this.include = true;
}

/** Find the node in the children that matches the array
*
* @param {String} nameToFind which node to try and locate in the children
Expand Down
Loading

0 comments on commit 3981df6

Please sign in to comment.