@bogeychan/elysia-logger
Advanced tools
Comparing version 0.0.20 to 0.0.21
@@ -30,2 +30,11 @@ import pino from "pino"; | ||
let log; | ||
const getLog = (ctx) => { | ||
if (!log) { | ||
log = | ||
typeof options.customProps === "function" | ||
? this.child(options.customProps(ctx)) | ||
: this; | ||
} | ||
return log; | ||
}; | ||
let app = new Elysia({ | ||
@@ -35,7 +44,3 @@ name: "@bogeychan/elysia-logger", | ||
}).derive({ as: "global" }, (ctx) => { | ||
log = | ||
typeof options.customProps === "function" | ||
? this.child(options.customProps(ctx)) | ||
: this; | ||
return { log }; | ||
return { log: getLog(ctx) }; | ||
}); | ||
@@ -48,2 +53,3 @@ if (autoLogging) { | ||
.onResponse({ as: "global" }, (ctx) => { | ||
const log = getLog(ctx); | ||
if (log.level == "silent") { | ||
@@ -50,0 +56,0 @@ return; |
{ | ||
"name": "@bogeychan/elysia-logger", | ||
"version": "0.0.20", | ||
"version": "0.0.21", | ||
"description": "A plugin for Elysia.js for logging using the pino library", | ||
@@ -5,0 +5,0 @@ "author": { |
@@ -33,3 +33,3 @@ # @bogeychan/elysia-logger | ||
console.log(`Listening on http://${app.server!.hostname}:${app.server!.port}`); | ||
console.log(`Listening on ${app.server!.url}`); | ||
``` | ||
@@ -36,0 +36,0 @@ |
import pino from "pino"; | ||
import { Elysia } from "elysia"; | ||
import { Context, Elysia } from "elysia"; | ||
@@ -91,2 +91,12 @@ import type { | ||
const getLog = (ctx: Context) => { | ||
if (!log) { | ||
log = | ||
typeof options.customProps === "function" | ||
? this.child(options.customProps(ctx)) | ||
: this; | ||
} | ||
return log; | ||
}; | ||
let app = new Elysia({ | ||
@@ -96,8 +106,3 @@ name: "@bogeychan/elysia-logger", | ||
}).derive({ as: "global" }, (ctx) => { | ||
log = | ||
typeof options.customProps === "function" | ||
? this.child(options.customProps(ctx)) | ||
: this; | ||
return { log }; | ||
return { log: getLog(ctx) }; | ||
}); | ||
@@ -115,2 +120,4 @@ | ||
.onResponse({ as: "global" }, (ctx) => { | ||
const log = getLog(ctx); | ||
if (log.level == "silent") { | ||
@@ -117,0 +124,0 @@ return; |
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
23781
536