{"version":3,"file":"koa.mjs","names":[],"sources":["../src/koa.ts"],"sourcesContent":["import type { Context, Next } from 'koa';\nimport type { Logger } from './core/types';\nimport type { HttpLoggerParams, HttpLogLevels } from './http';\nimport { createHttpLogger } from './http';\n\ndeclare module 'koa' {\n  export interface ExtendableContext {\n    log: Logger<HttpLogLevels>;\n  }\n  export interface Request {\n    log: Logger<HttpLogLevels>;\n  }\n  export interface Response {\n    log: Logger<HttpLogLevels>;\n  }\n}\n\nexport function createKoaLogger(params?: HttpLoggerParams) {\n  const http = createHttpLogger(params);\n\n  return async function koaLogger(ctx: Context, next: Next) {\n    ctx.log = ctx.request.log = ctx.response.log = ctx.req.log;\n    http(ctx.req, ctx.res);\n    return next().catch(error => {\n      ctx.res.err = error;\n      throw error;\n    });\n  };\n}\n"],"mappings":";;AAiBA,SAAgB,gBAAgB,QAA2B;CACzD,MAAM,OAAO,iBAAiB,MAAM;CAEpC,OAAO,eAAe,UAAU,KAAc,MAAY;EACxD,IAAI,MAAM,IAAI,QAAQ,MAAM,IAAI,SAAS,MAAM,IAAI,IAAI;EACvD,KAAK,IAAI,KAAK,IAAI,GAAG;EACrB,OAAO,KAAK,CAAC,CAAC,OAAM,UAAS;GAC3B,IAAI,IAAI,MAAM;GACd,MAAM;EACR,CAAC;CACH;AACF"}