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,
};
},
})
);
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 :)
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());
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 {};
},
})
);
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");
});