2017-10-08 05:46:57 +07:00
|
|
|
import { IRequestLogger } from "../../src/lib/logging/IRequestLogger";
|
|
|
|
import Sinon = require("sinon");
|
2017-10-22 22:42:05 +07:00
|
|
|
import { RequestLogger } from "../../src/lib/logging/RequestLogger";
|
|
|
|
import Winston = require("winston");
|
|
|
|
import Express = require("express");
|
2017-10-08 05:46:57 +07:00
|
|
|
|
|
|
|
export class RequestLoggerStub implements IRequestLogger {
|
|
|
|
infoStub: Sinon.SinonStub;
|
|
|
|
debugStub: Sinon.SinonStub;
|
|
|
|
errorStub: Sinon.SinonStub;
|
2017-10-22 22:42:05 +07:00
|
|
|
private requestLogger: RequestLogger;
|
2017-10-08 05:46:57 +07:00
|
|
|
|
2017-10-22 22:42:05 +07:00
|
|
|
constructor(enableLogging?: boolean) {
|
2017-10-08 05:46:57 +07:00
|
|
|
this.infoStub = Sinon.stub();
|
|
|
|
this.debugStub = Sinon.stub();
|
|
|
|
this.errorStub = Sinon.stub();
|
2017-10-22 22:42:05 +07:00
|
|
|
if (enableLogging)
|
|
|
|
this.requestLogger = new RequestLogger(Winston);
|
2017-10-08 05:46:57 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
info(req: Express.Request, message: string, ...args: any[]): void {
|
2017-10-22 22:42:05 +07:00
|
|
|
if (this.requestLogger)
|
|
|
|
this.requestLogger.info(req, message, ...args);
|
|
|
|
this.infoStub(req, message, ...args);
|
2017-10-08 05:46:57 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
debug(req: Express.Request, message: string, ...args: any[]): void {
|
2017-10-22 22:42:05 +07:00
|
|
|
if (this.requestLogger)
|
|
|
|
this.requestLogger.info(req, message, ...args);
|
|
|
|
this.debugStub(req, message, ...args);
|
2017-10-08 05:46:57 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
error(req: Express.Request, message: string, ...args: any[]): void {
|
2017-10-22 22:42:05 +07:00
|
|
|
if (this.requestLogger)
|
|
|
|
this.requestLogger.info(req, message, ...args);
|
|
|
|
this.errorStub(req, message, ...args);
|
2017-10-08 05:46:57 +07:00
|
|
|
}
|
|
|
|
}
|