Compare commits
1 Commits
developmen
...
dev/perf/d
Author | SHA1 | Date |
---|---|---|
Rahul Padigela | 0ec8c532c4 |
|
@ -434,26 +434,28 @@ class RequestLogger {
|
|||
});
|
||||
return;
|
||||
}
|
||||
const fields = objectCopy({}, this.fields, logFields || {});
|
||||
const endFlag = isEnd || false;
|
||||
|
||||
// removes object references
|
||||
const _logFields = logFields ?
|
||||
JSON.parse(JSON.stringify(logFields)) : {};
|
||||
/*
|
||||
* using Date.now() as it's faster than new Date(). logstash component
|
||||
* uses this field to generate ISO 8601 timestamp
|
||||
*/
|
||||
if (fields.time === undefined) {
|
||||
fields.time = Date.now();
|
||||
if (_logFields.time === undefined) {
|
||||
_logFields.time = Date.now();
|
||||
}
|
||||
|
||||
fields.req_id = serializeUids(this.uids);
|
||||
_logFields.req_id = serializeUids(this.uids);
|
||||
const endFlag = isEnd || false;
|
||||
if (endFlag) {
|
||||
this.elapsedTime = process.hrtime(this.startTime);
|
||||
fields.elapsed_ms = this.elapsedTime[0] * 1000
|
||||
_logFields.elapsed_ms = this.elapsedTime[0] * 1000
|
||||
+ this.elapsedTime[1] / 1000000;
|
||||
}
|
||||
// const fields = objectCopy({}, this.fields, _logFields || {});
|
||||
|
||||
const logEntry = {
|
||||
level,
|
||||
fields,
|
||||
fields: _logFields,
|
||||
msg,
|
||||
};
|
||||
this.entries.push(logEntry);
|
||||
|
@ -484,24 +486,25 @@ class RequestLogger {
|
|||
* @returns {undefined}
|
||||
*/
|
||||
doLogIO(logEntry) {
|
||||
const fields = objectCopy({}, this.fields, logEntry.fields);
|
||||
switch (logEntry.level) {
|
||||
case 'trace':
|
||||
this.sLogger.trace(logEntry.fields, logEntry.msg);
|
||||
this.sLogger.trace(fields, logEntry.msg);
|
||||
break;
|
||||
case 'debug':
|
||||
this.sLogger.debug(logEntry.fields, logEntry.msg);
|
||||
this.sLogger.debug(fields, logEntry.msg);
|
||||
break;
|
||||
case 'info':
|
||||
this.sLogger.info(logEntry.fields, logEntry.msg);
|
||||
this.sLogger.info(fields, logEntry.msg);
|
||||
break;
|
||||
case 'warn':
|
||||
this.sLogger.warn(logEntry.fields, logEntry.msg);
|
||||
this.sLogger.warn(fields, logEntry.msg);
|
||||
break;
|
||||
case 'error':
|
||||
this.sLogger.error(logEntry.fields, logEntry.msg);
|
||||
this.sLogger.error(fields, logEntry.msg);
|
||||
break;
|
||||
case 'fatal':
|
||||
this.sLogger.fatal(logEntry.fields, logEntry.msg);
|
||||
this.sLogger.fatal(fields, logEntry.msg);
|
||||
break;
|
||||
default:
|
||||
throw new Error(`Unexpected log level: ${logEntry.level}`);
|
||||
|
|
Loading…
Reference in New Issue