json-logger-service
Advanced tools
Comparing version 1.0.12 to 1.0.13
@@ -16,2 +16,7 @@ "use strict"; | ||
const nextFunction = () => { nextCalled = true; }; | ||
const responseMock = { | ||
socket: { | ||
finished: true, | ||
}, | ||
}; | ||
beforeAll(() => __awaiter(this, void 0, void 0, function* () { | ||
@@ -47,3 +52,3 @@ requestLogger = new index_1.RequestLogger(); | ||
beforeEach(() => { | ||
requestLogger.logExpressRequest({ route: { path: '/mypath' } }, undefined, nextFunction); | ||
requestLogger.logExpressRequest({ route: { path: '/mypath' } }, responseMock, nextFunction); | ||
}); | ||
@@ -54,3 +59,11 @@ it('Should return without failing', () => { | ||
}); | ||
describe('When path and method is defined', () => { | ||
beforeEach(() => { | ||
requestLogger.logExpressRequest({ route: { path: '/mypath' }, method: 'GET' }, responseMock, nextFunction); | ||
}); | ||
it('Should return without failing', () => { | ||
expect(nextCalled).toBeTruthy(); | ||
}); | ||
}); | ||
}); | ||
//# sourceMappingURL=RequestLogger.spec.js.map |
export declare class RequestLogger { | ||
private readonly logger; | ||
private static readonly LOGGER; | ||
logExpressRequest(req: any, res: any, next: any): void; | ||
} |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const LoggerFactory_1 = require("./LoggerFactory"); | ||
const onFinished = require('on-finished'); | ||
class RequestLogger { | ||
constructor() { | ||
this.logger = LoggerFactory_1.LoggerFactory.createLogger(RequestLogger.name); | ||
} | ||
logExpressRequest(req, res, next) { | ||
const requestPath = req && req.route && req.route.path; | ||
if (!requestPath) { | ||
this.logger.warn('No request path defined.'); | ||
RequestLogger.LOGGER.warn('No request path defined.'); | ||
next(); | ||
return; | ||
} | ||
this.logger.info(`Before request '${requestPath}'`); | ||
const method = req.method ? req.method : ''; | ||
RequestLogger.LOGGER.info(`Before request ${method} '${requestPath}'`); | ||
onFinished(res, (error) => { | ||
RequestLogger.LOGGER.info(`After request ${method} '${requestPath}' with ${error ? 'ERROR' : 'SUCCESS'}`); | ||
}); | ||
next(); | ||
this.logger.info(`After request '${requestPath}'`); | ||
return; | ||
} | ||
} | ||
RequestLogger.LOGGER = LoggerFactory_1.LoggerFactory.createLogger(RequestLogger.name); | ||
exports.RequestLogger = RequestLogger; | ||
//# sourceMappingURL=RequestLogger.js.map |
{ | ||
"name": "json-logger-service", | ||
"version": "1.0.12", | ||
"version": "1.0.13", | ||
"description": "Nest Json LoggerService implementation.", | ||
@@ -39,2 +39,3 @@ "main": "dist/index", | ||
"bunyan": "~1.8.12", | ||
"on-finished": "~2.3.0", | ||
"reflect-metadata": "~0.1.13", | ||
@@ -41,0 +42,0 @@ "rxjs": "~6.3.3" |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
28683
339
7
+ Addedon-finished@~2.3.0