forked from hyperledger-archives/composer
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of https://github.com/fabric-composer/fabric-co…
- Loading branch information
Showing
66 changed files
with
848 additions
and
252 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,7 +36,7 @@ fi | |
|
||
# are we building the docs? | ||
if [ "${DOCS}" != "" ]; then | ||
if [ -z "${TRAVIS_TAG}" ]; then | ||
if [ -z "${TRAVIS_TAG}" ]; then | ||
DOCS="full" | ||
else | ||
DOCS="unstable" | ||
|
@@ -51,8 +51,8 @@ npm config set registry https://registry.npmjs.org/ | |
npm config set //registry.npmjs.org/:_authToken ${NPM_TOKEN} | ||
|
||
# Set the GitHub deploy key we will use to publish. | ||
set-up-ssh --key "$encrypted_568b95f14ac3_key" \ | ||
--iv "$encrypted_568b95f14ac3_iv" \ | ||
set-up-ssh --key "$encrypted_8496d53a6fac_key" \ | ||
--iv "$encrypted_8496d53a6fac_iv" \ | ||
--path-encrypted-key ".travis/github_deploy_key.enc" | ||
|
||
# Change from HTTPS to SSH. | ||
|
@@ -103,6 +103,7 @@ if [ -z "${TRAVIS_TAG}" ]; then | |
cf push fabric-composer-next-unstable -c "node cli.js" -i 2 -m 128M --no-start | ||
cf set-env fabric-composer-next-unstable CLIENT_ID ${GH_NEXT_UNSTABLE_OAUTH_CLIENT_ID} | ||
cf set-env fabric-composer-next-unstable CLIENT_SECRET ${GH_NEXT_UNSTABLE_OAUTH_CLIENT_SECRET} | ||
cf set-env fabric-composer-next-unstable USABILLA_ID ${USABILLA_ID} | ||
cf start fabric-composer-next-unstable | ||
popd | ||
|
||
|
@@ -143,12 +144,13 @@ else | |
cf push fabric-composer-next -c "node cli.js" -i 2 -m 128M --no-start | ||
cf set-env fabric-composer-next CLIENT_ID ${GH_NEXT_OAUTH_CLIENT_ID} | ||
cf set-env fabric-composer-next CLIENT_SECRET ${GH_NEXT_OAUTH_CLIENT_SECRET} | ||
cf set-env fabric-composer-next USABILLA_ID ${USABILLA_ID} | ||
cf start fabric-composer-next | ||
popd | ||
|
||
# Configure the Git repository and clean any untracked and unignored build files. | ||
git config user.name "Travis CI" | ||
git config user.email "[email protected]" | ||
git config user.name "${GH_USER_NAME}" | ||
git config user.email "${GH_USER_EMAIL}" | ||
git checkout -b master | ||
git reset --hard | ||
git clean -d -f | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,14 +8,14 @@ set -o pipefail | |
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )/.." && pwd )" | ||
date | ||
# Set the GitHub deploy key we will use to publish. | ||
set-up-ssh --key "$encrypted_f19708b15817_key" \ | ||
--iv "$encrypted_f19708b15817_iv" \ | ||
--path-encrypted-key ".travis/github_deploy_docs_key.enc" | ||
set-up-ssh --key "$encrypted_8496d53a6fac_key" \ | ||
--iv "$encrypted_8496d53a6fac_iv" \ | ||
--path-encrypted-key ".travis/github_deploy_key.enc" | ||
|
||
# push the html documents | ||
# Configure the Git repository and clean any untracked and unignored build files. | ||
git config user.name "Travis CI" | ||
git config user.email "[email protected]" | ||
git config user.name "${GH_USER_NAME}" | ||
git config user.email "${GH_USER_EMAIL}" | ||
git config push.default simple | ||
|
||
echo ${DIR} | ||
|
@@ -27,15 +27,15 @@ git clone [email protected]:fabric-composer/${REPO}.git | |
git remote set-url origin ${REPO}.git | ||
|
||
cd "${DIR}/packages/composer-website/out/${REPO}" | ||
|
||
if [ "${DOCS}" == "full" ]; then | ||
rm -rf ${DIR}/packages/composer-website/out/${REPO}/* | ||
cp -rf ${DIR}/packages/composer-website/jekylldocs/_site/* . | ||
cp -rf ${DIR}/packages/composer-website/jekylldocs/_site/* . | ||
fi | ||
|
||
mkdir -p ${DIR}/packages/composer-website/out/${REPO}/unstable | ||
rm -rf ${DIR}/packages/composer-website/out/${REPO}/unstable/* | ||
cp -rf ${DIR}/packages/composer-website/jekylldocs/_site/* ./unstable | ||
cp -rf ${DIR}/packages/composer-website/jekylldocs/_site/* ./unstable | ||
|
||
git add . | ||
|
||
|
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,206 @@ | ||
# Diagnostic logging | ||
Fabric-composer has a functional logger that can be used for both informational and diagnostic log messages. It also permits customization for different logging 'back-ends'. | ||
|
||
## Log points | ||
Log points are added throughout the codebase, and should be very similar to other logging systems. The following APIs match to the standard log levels of *debug, verbose, info, warn, error* Note that *silly* isnt' being used. | ||
|
||
```javascript | ||
debug(method, msg, data); | ||
verbose(method, msg, data); | ||
info(method, msg, data); | ||
warn(method, msg, data); | ||
error(method, msg, data); | ||
``` | ||
|
||
In addition there are `entry` and `exit` APIs for use to indicate the entry and exit of functions - these are logged at the *debug* level. | ||
|
||
```javascript | ||
entry(method, data); | ||
entry(method, data); | ||
``` | ||
|
||
These methods are called on a `logger` object. To obtain one of these the following code at the top of the file should be used. | ||
|
||
```javascript | ||
\\ For the businessnetworkdefinition.js file in the composer-common module | ||
const LOG = Logger.getLog('common/BusinessNetworkDefinition'); | ||
``` | ||
|
||
## Usage within the code. | ||
|
||
Taking the `businessnetworkdefinition.js` file as an example, these are some real log statements: | ||
|
||
```javascript | ||
constructor(identifier, description, packageJson, readme) { | ||
const method = 'constructor'; | ||
LOG.entry(method, identifier, description); | ||
|
||
// ---- | ||
LOG.info(method, 'Created package.json' + JSON.stringify(packageJson)); | ||
// ---- | ||
LOG.debug(method, 'Found model file, loading it', file.name); | ||
// ---- | ||
|
||
LOG.exit(method); | ||
} | ||
``` | ||
|
||
All the log APIs can take a variable number of data arguments for logging. Any *error* object is logged will have it's stack trace located. | ||
|
||
## Enabling the logging | ||
|
||
In commong with other node.js applications the `DEBUG` environment variable is used. This takes a comma separated list of the modules that need to be logged. | ||
|
||
Examples | ||
|
||
- `DEBUG=*` Logs everything from everything (not just Fabric-Composer) | ||
- `DEBUG=composer:*` Logs everything from just Fabric-Composer | ||
- `DEBUG=*,!composer:*` Logs everything from everything with the exception of Fabric-Composer | ||
- `DEBUG=composer:common` Logs everything from the Fabric-Composer common module (the composer-common npm module) | ||
- `DEBUG=composer:client,composer:common` Logs everything from the Fabric-Composer common module (the composer-common npm module), and the client module | ||
- `DEBUG=composer:common:businessnetworkdefinition` Logs the businessnetworkdefinition ONLY | ||
|
||
## Controling the level and output | ||
|
||
The structure of the Fabric-Composer log code is that it delegates the actually logging to a back-end service. This service can swapped by using configuration (see below) but by default uses the Winston library. | ||
|
||
### Default configuration | ||
There are two streams setup in the default configuration - one to write log events to a file, the other to the console. | ||
|
||
If log is not enabled for Fabric-Composer no events are sent to the Console but info events are sent to the file | ||
If the log is enabled then info events are sent to the console and all level of events are sent to the file. | ||
|
||
The file by default is written to a directory off the current working directory called `logs` with the name `trace_<processid>.log` | ||
|
||
### Configuring the default logger | ||
|
||
Configuration is handled by using the config package - a config file called default.json is unless the code has specified something else. | ||
As an example - the default configuration of the logger would be represented in this file as | ||
|
||
``` | ||
$ cat ./config/default.json | ||
{ | ||
"fabric-composer": { | ||
"debug": { | ||
"logger": "./winstonInjector.js", | ||
"config": { | ||
'console': { | ||
'enabledLevel': 'info', | ||
'alwaysLevel': 'none' | ||
}, | ||
'file': { | ||
'filename': 'trace_PID.log', | ||
'enabledLevel': 'silly', | ||
'alwaysLevel': 'info' | ||
} | ||
} | ||
} | ||
} | ||
} | ||
``` | ||
### Modyifing the Winston logger | ||
Here are two examples of how to change the back-end logger simply using Winston's changeable transport feature. | ||
|
||
Two cloud hosted application log sites are *Loggly.com* and *Papertrailapp.com* | ||
|
||
#### Logger class | ||
Create a new js file, eg `winstonPapertrailInjector.js` | ||
|
||
```javascript | ||
'use strict'; | ||
|
||
const fs = require('fs-extra'); | ||
const winston = require('winston'); | ||
const sprintf = require('sprintf-js').sprintf; | ||
|
||
// | ||
// Requiring `winston-papertrail` will expose | ||
// `winston.transports.Papertrail` | ||
// | ||
require('winston-papertrail').Papertrail; | ||
|
||
/** The json structure that has been specified in the configuration | ||
* @private | ||
* @param {Object} config JSON structure with specific configuration information | ||
* @param {Array} configElements array with the DEBUG env variables for composer | ||
* | ||
* @returns {Object} object that is the logger to use | ||
*/ | ||
exports.getLogger = function (config,configElements){ | ||
|
||
let consoleLevel; | ||
let logglyLevel; | ||
|
||
if (configElements.debug.length === 0){ | ||
consoleLevel='error'; | ||
logglyLevel='info'; | ||
} else { | ||
papertrailLevel=config.papertrail.enabledLevel; | ||
consoleLevel=config.console.enabledLevel; | ||
} | ||
|
||
let formatterFn = function(options) { | ||
// Return string will be passed to logger. | ||
return sprintf('%s %-7s %-20s %s' | ||
,options.timestamp() | ||
,options.level.toUpperCase() | ||
,options.message | ||
,(JSON.stringify(options.meta,null,'') +'$') | ||
); | ||
|
||
}; | ||
|
||
let timestampFn = function() { | ||
return new Date(Date.now()).toISOString(); | ||
}; | ||
|
||
// this is the key part to route to Papertrail - the host and port | ||
let newWinstonLogger = { | ||
transports: [ | ||
new(winston.transports.Papertrail)( { | ||
name:'papertrail', | ||
host: 'logs5.papertrailapp.com', | ||
port: '34662', | ||
timestamp: timestampFn, | ||
formatter: formatterFn , | ||
level: papertrailLevel, | ||
json:true | ||
}) | ||
|
||
] | ||
}; | ||
|
||
winston.loggers.add('Fabric-Composer',newWinstonLogger); | ||
return winston.loggers.get('Fabric-Composer'); | ||
|
||
|
||
}; | ||
|
||
``` | ||
|
||
and in a configuration file - where the logger is a reference to the code above. | ||
|
||
``` | ||
{ | ||
"fabric-composer": { | ||
"debug": { | ||
"logger": "/home/matthew/github/waste-notes/winstonPapertrailInjector.js", | ||
"config": { | ||
"console": { | ||
"enabledLevel": "info", | ||
"alwaysLevel": "none" | ||
},"papertrail": { | ||
"enabledLevel": "silly", | ||
"alwaysLevel": "info" | ||
} | ||
} | ||
} | ||
} | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.