Skip to content

Commit

Permalink
[FABN-956] logger timeStamp re-order
Browse files Browse the repository at this point in the history
Via setting winston file logger{json :false},
then we can see debug.log format starting with timeStamp

Alongside:
- disable colorize for file logger (useless and introduce garbled text)

Change-Id: I1d393b9f164bef47d4726b77280fee782614f101
Signed-off-by: davidliu <david-khala@hotmail.com>
  • Loading branch information
davidkhala committed Oct 22, 2018
1 parent ce018fb commit 96cfd8f
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 52 deletions.
81 changes: 38 additions & 43 deletions fabric-client/lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ module.exports.newCryptoSuite = (setting) => {
};

// Provide a Promise-based keyValueStore for couchdb, etc.
module.exports.newKeyValueStore = async (options) =>{
module.exports.newKeyValueStore = async (options) => {
// initialize the correct KeyValueStore
const kvsEnv = exports.getConfigSetting('key-value-store');
const store = require(kvsEnv);
Expand Down Expand Up @@ -127,18 +127,18 @@ module.exports.getLogger = function (name) {
}
};

const newDefaultLogger = function () {
const newDefaultLogger = () => {
return new winston.Logger({
transports: [
new (winston.transports.Console)({colorize: true,timestamp:true})
new (winston.transports.Console)({colorize: true, timestamp: true})
]
});
};

const insertLoggerName = function (originalLogger, lname) {
const insertLoggerName = (originalLogger, lname) => {
const logger = Object.assign({}, originalLogger);

['debug', 'info', 'warn', 'error'].forEach((method) => {
LOGGING_LEVELS.forEach((method) => {
const func = originalLogger[method];

logger[method] = (function (context, loggerName, f) {
Expand All @@ -165,40 +165,36 @@ module.exports.getLogger = function (name) {
const options = {};
if (config_log_setting) {
try {
let config = null;
if (typeof config_log_setting === 'string') {
config = JSON.parse(config_log_setting);
}
else {
config = config_log_setting;
}
const config = typeof config_log_setting === 'string' ? JSON.parse(config_log_setting) : config_log_setting;
if (typeof config !== 'object') {
throw new Error('Environment variable "HFC_LOGGING" must be an object conforming to the format documented.');
} else {
for (const level in config) {
if (!config.hasOwnProperty(level)) {
continue;
}
for (const level in config) {
if (!config.hasOwnProperty(level)) {
continue;
}

if (LOGGING_LEVELS.includes(level)) {
if (!options.transports) {
options.transports = [];
}

if (LOGGING_LEVELS.indexOf(level) >= 0) {
if (!options.transports) {
options.transports = [];
}

if (config[level] === 'console') {
options.transports.push(new (winston.transports.Console)({
name: level + 'console',
level: level,
colorize: true
}));
} else {
options.transports.push(new (winston.transports.File)({
name: level + 'file',
level: level,
filename: config[level],
colorize: true
}));
}
if (config[level] === 'console') {
options.transports.push(new (winston.transports.Console)({
name: level + 'console',
level: level,
timestamp: true,
colorize: true
}));
} else {
options.transports.push(new (winston.transports.File)({
name: level + 'file',
level: level,
filename: config[level],
timestamp: true,
colorize: false,
json: false
}));
}
}
}
Expand Down Expand Up @@ -409,14 +405,13 @@ const CryptoKeyStore = function (KVSImplClass, opts) {
if (self._store === null) {
self.logger.debug(util.format('This class requires a CryptoKeyStore to save keys, using the store: %j', self._storeConfig));

CKS(self._storeConfig.superClass, self._storeConfig.opts)
.then((ks) => {
self.logger.debug('_getKeyStore returning ks');
self._store = ks;
return resolve(self._store);
}).catch((err) => {
reject(err);
});
CKS(self._storeConfig.superClass, self._storeConfig.opts).then((ks) => {
self.logger.debug('_getKeyStore returning ks');
self._store = ks;
return resolve(self._store);
}).catch((err) => {
reject(err);
});
} else {
self.logger.debug('_getKeyStore resolving store');
return resolve(self._store);
Expand Down
18 changes: 9 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@
"email": "fabric@lists.hyperledger.org"
},
"scripts": {
"test": "gulp test-headless",
"test:ca-client": "npm run coverage -- fabric-ca-client/test",
"test:client": "npm run coverage -- fabric-client/test",
"test:network": "npm run coverage -- fabric-network/test",
"test:all": "nyc npm run unit-test:all",
"unit-test:all": "npm run unit-test -- fabric-ca-client/test && npm run unit-test -- fabric-client/test && npm run unit-test -- fabric-network/test",
"coverage": "nyc npm run unit-test",
"unit-test": "mocha --exclude 'fabric-client/test/data/**' --recursive",
"test": "gulp test-headless",
"test:ca-client": "npm run coverage -- fabric-ca-client/test",
"test:client": "npm run coverage -- fabric-client/test",
"test:network": "npm run coverage -- fabric-network/test",
"test:all": "nyc npm run unit-test:all",
"unit-test:all": "npm run unit-test -- fabric-ca-client/test && npm run unit-test -- fabric-client/test && npm run unit-test -- fabric-network/test",
"coverage": "nyc npm run unit-test",
"unit-test": "mocha --exclude 'fabric-client/test/data/**' --recursive",
"compile": "tsc --project test/typescript",
"compile:w": "tsc --project test/typescript --watch"
},
Expand Down Expand Up @@ -81,7 +81,7 @@
"fabric-client/lib/**/*.js",
"fabric-common/lib/**/*.js",
"fabric-network/lib/**/*.js"
],
],
"reporter": [
"lcov",
"json",
Expand Down

0 comments on commit 96cfd8f

Please sign in to comment.