@bogeychan/elysia-logger
Advanced tools
Comparing version 0.1.0 to 0.1.1
@@ -21,2 +21,3 @@ import pino from "pino"; | ||
macro: {}; | ||
macroFn: {}; | ||
}, {}, { | ||
@@ -23,0 +24,0 @@ derive: {}; |
@@ -47,3 +47,3 @@ import pino from "pino"; | ||
}) | ||
.onResponse({ as: "global" }, (ctx) => { | ||
.onAfterResponse({ as: "global" }, (ctx) => { | ||
const loggerCtx = ctx; | ||
@@ -50,0 +50,0 @@ loggerCtx.isError = false; |
{ | ||
"name": "@bogeychan/elysia-logger", | ||
"version": "0.1.0", | ||
"version": "0.1.1", | ||
"description": "A plugin for Elysia.js for logging using the pino library", | ||
@@ -37,7 +37,7 @@ "author": { | ||
"peerDependencies": { | ||
"elysia": ">= 1.0.27" | ||
"elysia": ">= 1.1.0" | ||
}, | ||
"devDependencies": { | ||
"@types/bun": "1.0", | ||
"elysia": "1.0.27", | ||
"elysia": "1.1.0", | ||
"pino-pretty": "^11.2.1", | ||
@@ -44,0 +44,0 @@ "tsd": "^0.30.7", |
@@ -56,3 +56,3 @@ # @bogeychan/elysia-logger | ||
### Include additional request context info for debugging tools | ||
### Include additional request context info | ||
@@ -66,4 +66,10 @@ ```ts | ||
app = app.use(myPlugin()); | ||
class MyError extends Error { | ||
constructor(message: string, public myValue: string) { | ||
super(message); | ||
} | ||
} | ||
app = app.error("myError", MyError).use(myPlugin()); | ||
app | ||
@@ -77,2 +83,8 @@ .use( | ||
customProps(ctx: InferContext<typeof app>) { | ||
if (ctx.isError && ctx.code === "myError") { | ||
return { | ||
myValue: ctx.error.myValue, | ||
}; | ||
} | ||
return { | ||
@@ -90,2 +102,5 @@ params: ctx.params, | ||
return "with-context"; | ||
}) | ||
.get("/error", () => { | ||
throw new MyError("whelp", "yay"); | ||
}); | ||
@@ -110,7 +125,7 @@ ``` | ||
throw { message: "1234", name: "MyError" }; | ||
throw new Error("whelp"); | ||
}); | ||
``` | ||
### Automatic `onResponse` logging by `default`; based on [pino-http](https://github.com/pinojs/pino-http) | ||
### Automatic `onAfterResponse` & `onError` logging by `default`; based on [pino-http](https://github.com/pinojs/pino-http) | ||
@@ -117,0 +132,0 @@ ```ts |
@@ -114,3 +114,3 @@ import pino from "pino"; | ||
}) | ||
.onResponse({ as: "global" }, (ctx) => { | ||
.onAfterResponse({ as: "global" }, (ctx) => { | ||
const loggerCtx = ctx as unknown as ElysiaLoggerContext; | ||
@@ -117,0 +117,0 @@ loggerCtx.isError = false; |
@@ -57,3 +57,3 @@ import type { pino } from "pino"; | ||
/** | ||
* Disable the automatic "onResponse" logging | ||
* Disable the automatic "onAfterResponse" & "onError" logging | ||
* | ||
@@ -60,0 +60,0 @@ * @default true |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
28361
660
150