Skip to content
This repository was archived by the owner on Apr 22, 2025. It is now read-only.

Commit 96cfd8f

Browse files
committed
[FABN-956] logger timeStamp re-order
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>
1 parent ce018fb commit 96cfd8f

File tree

2 files changed

+47
-52
lines changed

2 files changed

+47
-52
lines changed

fabric-client/lib/utils.js

Lines changed: 38 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ module.exports.newCryptoSuite = (setting) => {
9090
};
9191

9292
// Provide a Promise-based keyValueStore for couchdb, etc.
93-
module.exports.newKeyValueStore = async (options) =>{
93+
module.exports.newKeyValueStore = async (options) => {
9494
// initialize the correct KeyValueStore
9595
const kvsEnv = exports.getConfigSetting('key-value-store');
9696
const store = require(kvsEnv);
@@ -127,18 +127,18 @@ module.exports.getLogger = function (name) {
127127
}
128128
};
129129

130-
const newDefaultLogger = function () {
130+
const newDefaultLogger = () => {
131131
return new winston.Logger({
132132
transports: [
133-
new (winston.transports.Console)({colorize: true,timestamp:true})
133+
new (winston.transports.Console)({colorize: true, timestamp: true})
134134
]
135135
});
136136
};
137137

138-
const insertLoggerName = function (originalLogger, lname) {
138+
const insertLoggerName = (originalLogger, lname) => {
139139
const logger = Object.assign({}, originalLogger);
140140

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

144144
logger[method] = (function (context, loggerName, f) {
@@ -165,40 +165,36 @@ module.exports.getLogger = function (name) {
165165
const options = {};
166166
if (config_log_setting) {
167167
try {
168-
let config = null;
169-
if (typeof config_log_setting === 'string') {
170-
config = JSON.parse(config_log_setting);
171-
}
172-
else {
173-
config = config_log_setting;
174-
}
168+
const config = typeof config_log_setting === 'string' ? JSON.parse(config_log_setting) : config_log_setting;
175169
if (typeof config !== 'object') {
176170
throw new Error('Environment variable "HFC_LOGGING" must be an object conforming to the format documented.');
177-
} else {
178-
for (const level in config) {
179-
if (!config.hasOwnProperty(level)) {
180-
continue;
171+
}
172+
for (const level in config) {
173+
if (!config.hasOwnProperty(level)) {
174+
continue;
175+
}
176+
177+
if (LOGGING_LEVELS.includes(level)) {
178+
if (!options.transports) {
179+
options.transports = [];
181180
}
182181

183-
if (LOGGING_LEVELS.indexOf(level) >= 0) {
184-
if (!options.transports) {
185-
options.transports = [];
186-
}
187-
188-
if (config[level] === 'console') {
189-
options.transports.push(new (winston.transports.Console)({
190-
name: level + 'console',
191-
level: level,
192-
colorize: true
193-
}));
194-
} else {
195-
options.transports.push(new (winston.transports.File)({
196-
name: level + 'file',
197-
level: level,
198-
filename: config[level],
199-
colorize: true
200-
}));
201-
}
182+
if (config[level] === 'console') {
183+
options.transports.push(new (winston.transports.Console)({
184+
name: level + 'console',
185+
level: level,
186+
timestamp: true,
187+
colorize: true
188+
}));
189+
} else {
190+
options.transports.push(new (winston.transports.File)({
191+
name: level + 'file',
192+
level: level,
193+
filename: config[level],
194+
timestamp: true,
195+
colorize: false,
196+
json: false
197+
}));
202198
}
203199
}
204200
}
@@ -409,14 +405,13 @@ const CryptoKeyStore = function (KVSImplClass, opts) {
409405
if (self._store === null) {
410406
self.logger.debug(util.format('This class requires a CryptoKeyStore to save keys, using the store: %j', self._storeConfig));
411407

412-
CKS(self._storeConfig.superClass, self._storeConfig.opts)
413-
.then((ks) => {
414-
self.logger.debug('_getKeyStore returning ks');
415-
self._store = ks;
416-
return resolve(self._store);
417-
}).catch((err) => {
418-
reject(err);
419-
});
408+
CKS(self._storeConfig.superClass, self._storeConfig.opts).then((ks) => {
409+
self.logger.debug('_getKeyStore returning ks');
410+
self._store = ks;
411+
return resolve(self._store);
412+
}).catch((err) => {
413+
reject(err);
414+
});
420415
} else {
421416
self.logger.debug('_getKeyStore resolving store');
422417
return resolve(self._store);

package.json

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,14 @@
1414
"email": "fabric@lists.hyperledger.org"
1515
},
1616
"scripts": {
17-
"test": "gulp test-headless",
18-
"test:ca-client": "npm run coverage -- fabric-ca-client/test",
19-
"test:client": "npm run coverage -- fabric-client/test",
20-
"test:network": "npm run coverage -- fabric-network/test",
21-
"test:all": "nyc npm run unit-test:all",
22-
"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",
23-
"coverage": "nyc npm run unit-test",
24-
"unit-test": "mocha --exclude 'fabric-client/test/data/**' --recursive",
17+
"test": "gulp test-headless",
18+
"test:ca-client": "npm run coverage -- fabric-ca-client/test",
19+
"test:client": "npm run coverage -- fabric-client/test",
20+
"test:network": "npm run coverage -- fabric-network/test",
21+
"test:all": "nyc npm run unit-test:all",
22+
"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",
23+
"coverage": "nyc npm run unit-test",
24+
"unit-test": "mocha --exclude 'fabric-client/test/data/**' --recursive",
2525
"compile": "tsc --project test/typescript",
2626
"compile:w": "tsc --project test/typescript --watch"
2727
},
@@ -81,7 +81,7 @@
8181
"fabric-client/lib/**/*.js",
8282
"fabric-common/lib/**/*.js",
8383
"fabric-network/lib/**/*.js"
84-
],
84+
],
8585
"reporter": [
8686
"lcov",
8787
"json",

0 commit comments

Comments
 (0)