Skip to content

Latest commit

 

History

History
150 lines (112 loc) · 2.63 KB

MIGRATION.md

File metadata and controls

150 lines (112 loc) · 2.63 KB

Migration Guide

v0.0.22 to v0.1.0

Automatic onError logging by default

Use:

import { type InferContext } from "@bogeychan/elysia-logger";

app.use(
  logger({
    customProps(ctx: InferContext<typeof app>) {
      if (ctx.isError) {
        // you can pass additional properties like `ctx.myProperty` too
        // but they might be `undefined` depending on error cause
        return {};
      }

      return {
        myProperty: ctx.myProperty,
      };
    },
  })
);

Instead of:

import { type InferContext } from "@bogeychan/elysia-logger";

app.use(
  logger({
    customProps(ctx: InferContext<typeof app>) {
      return {
        myProperty: ctx.myProperty,
      };
    },
  })
);

InferContext now contains either Context or ErrorContext

It won't work outside the plugin scope.

You can find the previous version of InferContext here. Just copy & paste it into your project with a different name :)

v0.0.11 to v0.0.12

Automatic onResponse logging by default

Use:

import { logger, createPinoLogger } from "@bogeychan/elysia-logger";

app.use(
  logger({
    autoLogging: false,
  })
);

const log = createPinoLogger();

app.use(
  log.into({
    autoLogging: false,
  })
);

Instead of:

import { logger, createPinoLogger } from "@bogeychan/elysia-logger";

app.use(logger());

const log = createPinoLogger();

app.use(log.into());

v0.0.9 to v0.0.10

Infer the Elysia Context

Use:

import { type InferContext } from "@bogeychan/elysia-logger";

app.use(
  logger({
    customProps(ctx: InferContext<typeof app>) {
      return {};
    },
  })
);

Instead of:

import {
  type ElysiaContextForInstance,
  type InferElysiaInstance,
} from "@bogeychan/elysia-logger";

app.use(
  logger({
    customProps(
      ctx: ElysiaContextForInstance<InferElysiaInstance<typeof app>>
    ) {
      return {};
    },
  })
);

The contextKeyName option is obsolete

You can learn more about this in the Elysia's 0.7 blog

Use:

app
  .use(logger().derive(({ log, ...rest }) => ({ myLogger: log, ...rest })))
  .get("/", (ctx) => {
    ctx.myLogger.info(ctx.request, "Request");
  });

Instead of:

app
  .use(
    logger({
      contextKeyName: "myLogger",
    })
  )
  .get("/", (ctx) => {
    ctx.myLogger.info(ctx.request, "Request");
  });