diff --git a/src/api/middlewares/log.ts b/src/api/middlewares/log.ts index 30837603..e9fc49e5 100644 --- a/src/api/middlewares/log.ts +++ b/src/api/middlewares/log.ts @@ -1,25 +1,26 @@ +import { container } from "tsyringe" import chalk from "chalk" import { Context, Next } from "koa" import { Logger } from "@services" -import { waitForDependency } from "@utils/functions" -export function globalLog(ctx: Context, next: Next) { - waitForDependency(Logger).then(logger => { - // don't log anything if the request has a `logIgnore` query params - if (!ctx.query.logIgnore) { - const { method, url } = ctx.request +const logger = container.resolve(Logger) - const message = `(API) ${method} - ${url}` - const chalkedMessage = `(${chalk.bold.white('API')}) ${chalk.bold.green(method)} - ${chalk.bold.blue(url)}` +export async function globalLog(ctx: Context, next: Next) { - logger.console('info', chalkedMessage) - logger.file('info', message) - - } else { - delete ctx.query.logIgnore - } + // don't log anything if the request has a `logIgnore` query params + if (!ctx.query.logIgnore) { + const { method, url } = ctx.request - return next() - }); + const message = `(API) ${method} - ${url}` + const chalkedMessage = `(${chalk.bold.white('API')}) ${chalk.bold.green(method)} - ${chalk.bold.blue(url)}` + + logger.console('info', chalkedMessage) + logger.file('info', message) + + } else { + delete ctx.query.logIgnore + } + + return next() } \ No newline at end of file