Мы сделали это с помощью Winston logger, который был внедрен как Logger Service в наш sequence.ts. Вот код для sequence.ts.
export class MySequence implements SequenceHandler {
constructor(
@inject(SequenceActions.FIND_ROUTE) protected findRoute: FindRoute,
@inject(SequenceActions.PARSE_PARAMS) protected parseParams: ParseParams,
@inject(SequenceActions.INVOKE_METHOD) protected invoke: InvokeMethod,
@inject(SequenceActions.SEND) public send: Send,
@inject(SequenceActions.REJECT) public reject: Reject,
@inject(LOGGER.LOGGER_INJECT) public logger: ILogger,
@inject(HelmetSecurityBindings.HELMET_SECURITY_ACTION)
protected helmetAction: HelmetAction,
@inject(RateLimitSecurityBindings.RATELIMIT_SECURITY_ACTION)
protected rateLimitAction: RateLimitAction,
@inject(AlivioBindings.i18n)
protected i18n: i18nAPI,
) {}
async handle(context: RequestContext) {
const requestTime = Date.now();
try {
const {request, response} = context;
this.logger.info(
`Request ${request.method} ${
request.url
} started at ${requestTime.toString()}.
Request Details
Referer = ${request.headers.referer}
User-Agent = ${request.headers['user-agent']}
Remote Address = ${request.connection.remoteAddress}
Remote Address (Proxy) = ${request.headers['x-forwarded-for']}`,
);
const route = this.findRoute(request);
const args = await this.parseParams(request, route);
await this.rateLimitAction(request, response);
await this.helmetAction(request, response);
request.body = args[args.length - 1];
const result = await this.invoke(route, args);
this.send(response, result);
} catch (err) {
this.logger.error(
`Request ${context.request.method} ${
context.request.url
} errored out. Error :: ${JSON.stringify(err)} ${err}`,
);
this.reject(context, error);
} finally {
this.logger.info(
`Request ${context.request.method} ${
context.request.url
} Completed in ${Date.now() - requestTime}ms`,
);
}
}
}
Здесь вы можете использовать любой регистратор в качестве провайдера. Вы можете создать поставщика оболочки для log4 js, а затем сделать это, как указано выше. Надеюсь это поможет. Дайте мне знать, если вы тоже хотите увидеть код провайдера. Я тоже поделюсь этим.