Nebulous Puffy Marshmallows
    Have ideas to improve npm?Join in the discussion! »

    @ailo/koa-logger-middleware
    TypeScript icon, indicating that this package has built-in type declarations

    1.2.2 • Public • Published

    @ailo/koa-logger-middleware

    A logger middleware for koa2 with color and customizable logger as winstonjs.

    Koa logger middleware

    Usage example

    yarn add koa-logger-middleware
    import { koaLoggerMiddleware } from "koa-logger-middleware";
    
    app.use(
      koaLoggerMiddleware({
        logger: Logger.logAs("koa"),
      })
    );

    Options

    To see all option refer to src/index.ts file.

    • logger: [Object] - eg: winstonjs, by default is console with coloration.

      const winstonLogger = winston.createLogger({
        level: "info",
        format: winston.format.json(),
        transports: [
          new winston.transports.Console({
            format: winston.format.simple(),
            colorize: true,
          }),
        ],
      });
      
      koaLoggerMiddleware({ logger: winstonLogger });
    • onStartFormat: [Function] - format the string to log on request start:

      koaLoggerMiddleware({
        onStartFormat(ctx) {
          const { start } = ctx.__logger;
          return `START: ${this.dateFormat(start)} - ${ctx.method} ${ctx.url}`;
        },
      });
    • onErrorFormat: [Function] - same as onStartFormat but when error occurred

    • onEndFormat: [Function] - same as onStartFormat but on response end

    Development

    yarn
    yarn start

    Testing

    yarn lint # prettier and eslint
    yarn test # unit tests
    yarn test:watch # unit tests in watch mode

    Releasing

    Note: Releasing is done manually (CI isn't configured yet). Linters, tests, build and so on are run during each git push / yarn release.

    yarn release # will automatically ask you about version bump, run tests and build, and push new version to git & npm

    Install

    npm i @ailo/koa-logger-middleware

    DownloadsWeekly Downloads

    39

    Version

    1.2.2

    License

    MIT

    Unpacked Size

    118 kB

    Total Files

    20

    Last publish

    Collaborators

    • avatar