bogeychan / elysia-logger Goto Github PK
View Code? Open in Web Editor NEWA plugin for Elysia.js for logging using the pino library
Home Page: https://npmjs.com/package/@bogeychan/elysia-logger
License: MIT License
A plugin for Elysia.js for logging using the pino library
Home Page: https://npmjs.com/package/@bogeychan/elysia-logger
License: MIT License
Im trying to use the plugin with the Node and Polyfills.
I getting this error:
node_modules/@bogeychan/elysia-logger/src/types.ts(3,31): error TS2307: Cannot find module 'bun' or its corresponding type declarations.
This is my first time trying this but it doesn't seems to work anymore with the new Elysia
Argument type
_INTERNAL_ElysiaLoggerPlugin<_INTERNAL_ElysiaLoggerPluginAutoLoggingState>
is not assignable to parameter type
I'm using Elysia version 1.0.0
and the latest version of this package (^0.0.17
)
const app = new Elysia({})
.use(logger({ autoLogging: true })) // -> results in a type error and logs nothing
.listen(3000)
No response
No response
No response
Error
No overload matches this call.
The last overload gave the following error.
Argument of type '_INTERNAL_ElysiaLoggerPlugin<_INTERNAL_ElysiaLoggerPluginAutoLoggingState>' is not assignable to parameter of type 'Promise<{ default: Elysia<any, any, any, any, any, any>; }>'.ts(2769)
index.d.ts(392, 5): The last overload is declared here.
(alias) logger(options?: _INTERNAL_ElysiaLoggerPluginAutoLoggingEnabledOptions | undefined): _INTERNAL_ElysiaLoggerPlugin<...> (+1 overload)
import logger
The StreamLogger is used to write log entries to a stream such as the console output (default behavior).
import { Elysia } from "elysia"
import { logger } from "@bogeychan/elysia-logger"
const app = new Elysia().use(logger()).listen(8081)
console.log(`๐ฆ Elysia is running at ${app.server?.hostname}:${app.server?.port}`)
Argument of type '_INTERNAL_ElysiaLoggerPlugin<_INTERNAL_ElysiaLoggerPluginAutoLoggingState>' is not assignable to parameter of type 'Promise<{ default: (elysia: Elysia<any, any>) => Elysia<any, ElysiaInstance>; }>'.
Type 'Elysia<"", { request: { log: pino.Logger<Options>; }; store: _INTERNAL_ElysiaLoggerPluginAutoLoggingState; }>' is missing the following properties from type 'Promise<{ default: (elysia: Elysia<any, any>) => Elysia<any, ElysiaInstance>; }>': then, catch, finally, [Symbol.toStringTag]ts(2769)
Argument of type '_INTERNAL_ElysiaLoggerPlugin<_INTERNAL_ElysiaLoggerPluginAutoLoggingState>' is not assignable to parameter of type 'Promise<{ default: (elysia: Elysia<any, any>) => Elysia<any, ElysiaInstance>; }>'.
Type 'Elysia<"", { request: { log: pino.Logger<Options>; }; store: _INTERNAL_ElysiaLoggerPluginAutoLoggingState; }>' is missing the following properties from type 'Promise<{ default: (elysia: Elysia<any, any>) => Elysia<any, ElysiaInstance>; }>': then, catch, finally, [Symbol.toStringTag]ts(2769)
bun start
$ bun run src/index.ts
error: Cannot find package "pino" from "/mnt/users/username/source/assignment1_chord/src/chord-node/node_modules/@bogeychan/elysia-logger/dist/index.js"
error: script "start" exited with code 1 (SIGHUP)
Bun version: 1.0.6
@bogeychan/elysia-logger version: 0.0.12
vscode: 1.83.1
os: AlmaLinux 9.2
Why isn't it available in onError middleware? Is it the logger or Elysia problem? Could you maybe give an advice on how to handle errors globally?
Version: 0.0.6
Property 'log' does not exist on type '{ request: Request; code: "UNKNOWN"; error: Readonly; set: { headers: { [header: string]: string; } & { "Set-Cookie"?: string | string[] | undefined; }; status?: number | undefined; redirect?: string | undefined; }; } | { ...; } | { ...; } | { ...; } | { ...; }'.
Property 'log' does not exist on type '{ request: Request; code: "UNKNOWN"; error: Readonly; set: { headers: { [header: string]: string; } & { "Set-Cookie"?: string | string[] | undefined; }; status?: number | undefined; redirect?: string | undefined; }; }'.ts(2339)
My expectation, considering this is a plugin specifically for Elysia is that this would do request and/or response logging by default. Something similar to https://github.com/pinojs/pino-http. It seems that this mostly just exposes a pino logger on the request context. Not a bad start by any means but if you do have the time / energy a nice enhancement would be to support additional options for auto logging requests and responses ideally with some configuration for suppressing variables or redacting sensitive parts of the request / response. Thanks!
this plugin is awesome thanks for making it
when implementing it into my app I get a very strange error
import { Elysia } from "elysia";
import { logger } from "@bogeychan/elysia-logger";
export const ctx = new Elysia({
name: "@app/ctx",
}).use(logger());
The inferred type of 'ctx' cannot be named without a reference to
'../../node_modules/@bogeychan/elysia-logger/dist/types'. This is likely not portable.
A type annotation is necessary. ts(2742)
Basically it wants me to manually annotate it for some reason, so I highlight what is inferred when I hover it and annotate it:
export const ctx: Elysia<
"",
{
error: {};
request: {
log: Logger<Omit<LoggerOptions<"log">, "customProps" | "contextKeyName">>;
};
store: {};
schema: {};
meta: {
schema: {};
defs: {};
exposed: {};
};
}
> = new Elysia({
name: "@app/ctx",
}).use(logger());
and I think the issue is Logger
and LoggerOptions
are used in the package, but never exposed to the end user:
Module '"@bogeychan/elysia-logger"' declares 'LoggerOptions' locally, but it is not exported.
Property 'logger' does not exist on type 'Context<{ body: unknown; params: Record<never, string>; query: undefined; headers: undefined; response: unknown; }, {}> & { jwt: { readonly sign: (morePayload: Record<string, string> & JWTPayloadSpec) => Promise<...>; readonly verify: (jwt?: string | undefined) => Promise<...>; }; unsignCookie: (value: string) => { ...'.ts(2339)
"elysia": "1.0.11",
"@bogeychan/elysia-logger": "0.0.20",
import { Elysia, t } from "elysia";
import { logger } from "@bogeychan/elysia-logger";
export const app = new Elysia()
.use(
logger({
level: "trace",
autoLogging: true,
}),
)
.post("/test", (ctx) => "ok", {
body: t.Object({
test: t.String(),
}),
});
app.listen(3000);
Send empty body to provoke the error:
curl 'http://localhost/test' --data-raw '' -H 'content-type: application/json'
The response is:
Failed to parse body as found: [object Object]%
No response
41 | return app
42 | .onRequest((ctx) => {
43 | ctx.store = { ...ctx.store, startTime: performance.now() };
44 | })
45 | .onResponse({ as: "global" }, (ctx) => {
46 | if (log.level == "silent") {
^
TypeError: undefined is not an object (evaluating 'log.level')
at /home/haakon/repos/nxtest/node_modules/.pnpm/@[email protected][email protected]/node_modules/@bogeychan/elysia-logger/dist/index.js:46:17
No response
Hey! Elysia logger doesn't seem to work with Elysia 0.7.
The last overload gave the following error.
Argument of type 'Elysia<"", { store: {}; error: {}; request: DeriveReturned; schema: {}; meta: { schema: {}; defs: {}; exposed: {}; }; }>' is not assignable to parameter of type 'Promise<{ default: Elysia<any, any, any, any, any, any>; }>'.
Type 'Elysia<"", { store: {}; error: {}; request: DeriveReturned; schema: {}; meta: { schema: {}; defs: {}; exposed: {}; }; }>' is missing the following properties from type 'Promise<{ default: Elysia<any, any, any, any, any, any>; }>': then, catch, finally, [Symbol.toStringTag]```
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.