@bogeychan/elysia-logger
Advanced tools
Comparing version 0.0.19 to 0.0.20
import { Elysia } from "elysia"; | ||
import type { Logger, ElysiaLogger, StandaloneLoggerOptions, ElysiaFileLoggerOptions, ElysiaStreamLoggerOptions, _INTERNAL_ElysiaLoggerPlugin, _INTERNAL_ElysiaLoggerPluginAutoLoggingState, _INTERNAL_ElysiaLoggerPluginAutoLoggingEnabledOptions, _INTERNAL_ElysiaLoggerPluginAutoLoggingDisabledOptions } from "./types"; | ||
import type { Logger, ElysiaLogger, StandaloneLoggerOptions, ElysiaFileLoggerOptions, ElysiaStreamLoggerOptions, _INTERNAL_Writeonly, _INTERNAL_ElysiaLoggerPlugin, _INTERNAL_ElysiaLoggerPluginAutoLoggingState, _INTERNAL_ElysiaLoggerPluginAutoLoggingEnabledOptions, _INTERNAL_ElysiaLoggerPluginAutoLoggingDisabledOptions } from "./types"; | ||
export declare function logger(options?: _INTERNAL_ElysiaLoggerPluginAutoLoggingEnabledOptions<ElysiaStreamLoggerOptions>): _INTERNAL_ElysiaLoggerPlugin<_INTERNAL_ElysiaLoggerPluginAutoLoggingState>; | ||
@@ -10,6 +10,6 @@ export declare function logger(options?: _INTERNAL_ElysiaLoggerPluginAutoLoggingDisabledOptions<ElysiaStreamLoggerOptions>): _INTERNAL_ElysiaLoggerPlugin; | ||
store: {}; | ||
derive: { | ||
derive: {}; | ||
resolve: { | ||
readonly log: Logger; | ||
}; | ||
resolve: {}; | ||
}, { | ||
@@ -22,12 +22,12 @@ type: {}; | ||
}, {}, { | ||
decorator: {}; | ||
store: {}; | ||
derive: {}; | ||
resolve: {}; | ||
schema: {}; | ||
}, { | ||
derive: {}; | ||
resolve: {}; | ||
schema: {}; | ||
macro: {}; | ||
}>>; | ||
}> | _INTERNAL_ElysiaLoggerPlugin<_INTERNAL_Writeonly<_INTERNAL_ElysiaLoggerPluginAutoLoggingState>>>; | ||
export * from "./config"; | ||
export type { InferContext } from "./types"; | ||
export { pino } from "pino"; |
@@ -41,3 +41,3 @@ import pino from "pino"; | ||
if (autoLogging) { | ||
app = app | ||
return app | ||
.onRequest((ctx) => { | ||
@@ -44,0 +44,0 @@ ctx.store = { ...ctx.store, startTime: performance.now() }; |
/// <reference types="node" /> | ||
import type { pino } from "pino"; | ||
import type { Context, DefinitionBase, Elysia, RouteBase, SingletonBase } from "elysia"; | ||
import type { Context, Elysia, RouteSchema } from "elysia"; | ||
export interface StreamLoggerOptions extends BaseLoggerOptions { | ||
@@ -30,3 +30,8 @@ stream?: pino.DestinationStream; | ||
export type Logger = pino.Logger & BaseLoggerOptions; | ||
export type InferContext<T> = T extends Elysia<infer Path, infer _Scoped, infer Singleton, infer _Definitions, infer _Metadata, infer Routes, infer _EphemeralMetadata> ? Context<Routes, SingletonBase, Path> & Partial<Singleton["derive"]> & Partial<Singleton["decorator"]> : never; | ||
export type InferContext<T> = T extends Elysia<infer _Path, infer _Scoped, infer Singleton, infer _Definitions, infer _Metadata, infer _Routes, infer Ephemeral, infer Volatile> ? Context<RouteSchema, { | ||
decorator: Partial<Singleton["decorator"]>; | ||
store: Partial<Singleton["store"]>; | ||
derive: Partial<Singleton["derive"] & Ephemeral["derive"] & Volatile["derive"]>; | ||
resolve: Partial<Singleton["resolve"] & Ephemeral["resolve"] & Volatile["resolve"]>; | ||
}> : never; | ||
export type _INTERNAL_Writeonly<T> = { | ||
@@ -47,10 +52,2 @@ -readonly [P in keyof T]: T[P]; | ||
resolve: {}; | ||
}, DefinitionBase, { | ||
macro: {}; | ||
schema: {}; | ||
}, RouteBase, { | ||
store: {}; | ||
derive: {}; | ||
decorator: {}; | ||
resolve: {}; | ||
}>; | ||
@@ -57,0 +54,0 @@ export type _INTERNAL_ElysiaLoggerPluginAutoLoggingEnabledOptions<Options extends BaseLoggerOptions & ElysiaLoggerOptions> = Omit<Options, "autoLogging"> & { |
{ | ||
"name": "@bogeychan/elysia-logger", | ||
"version": "0.0.19", | ||
"version": "0.0.20", | ||
"description": "A plugin for Elysia.js for logging using the pino library", | ||
@@ -31,3 +31,4 @@ "author": { | ||
"dev": "bun run --watch examples/basic.ts", | ||
"test": "bun test", | ||
"test": "bun run test:types && bun test", | ||
"test:types": "tsc --project tsconfig.test.json", | ||
"build": "rm -fr dist && tsc --project tsconfig.esm.json", | ||
@@ -37,8 +38,9 @@ "release": "npm run build && npm run test && npm publish --access public" | ||
"peerDependencies": { | ||
"elysia": ">= 1.0.0" | ||
"elysia": ">= 1.0.9" | ||
}, | ||
"devDependencies": { | ||
"@types/bun": "1.0", | ||
"elysia": "^1.0.0", | ||
"elysia": "^1.0.9", | ||
"pino-pretty": "^10.3.1", | ||
"tsd": "^0.30.7", | ||
"typescript": "5" | ||
@@ -45,0 +47,0 @@ }, |
@@ -16,4 +16,4 @@ # @bogeychan/elysia-logger | ||
```ts | ||
import { Elysia } from 'elysia'; | ||
import { logger } from '@bogeychan/elysia-logger'; | ||
import { Elysia } from "elysia"; | ||
import { logger } from "@bogeychan/elysia-logger"; | ||
@@ -23,10 +23,10 @@ const app = new Elysia() | ||
logger({ | ||
level: 'error' | ||
level: "error", | ||
}) | ||
) | ||
.get('/', (ctx) => { | ||
ctx.log.error(ctx, 'Context'); | ||
ctx.log.info(ctx.request, 'Request'); // noop | ||
.get("/", (ctx) => { | ||
ctx.log.error(ctx, "Context"); | ||
ctx.log.info(ctx.request, "Request"); // noop | ||
return 'Hello World'; | ||
return "Hello World"; | ||
}) | ||
@@ -41,6 +41,6 @@ .listen(8080); | ||
```ts | ||
import { fileLogger } from '@bogeychan/elysia-logger'; | ||
import { fileLogger } from "@bogeychan/elysia-logger"; | ||
fileLogger({ | ||
file: './my.log' | ||
file: "./my.log", | ||
}); | ||
@@ -62,5 +62,5 @@ ``` | ||
```ts | ||
import { logger, type InferContext } from '@bogeychan/elysia-logger'; | ||
import { logger, type InferContext } from "@bogeychan/elysia-logger"; | ||
const myPlugin = () => (app: Elysia) => app.decorate('myProperty', 42); | ||
const myPlugin = () => new Elysia().decorate("myProperty", 42); | ||
@@ -75,3 +75,3 @@ // ... | ||
/** | ||
* This function will be invoked for each `log`-method called with `context` | ||
* This function will be invoked for each `log`-method called | ||
* where you can pass additional properties that need to be logged | ||
@@ -83,11 +83,11 @@ */ | ||
query: ctx.query, | ||
myProperty: ctx.myProperty | ||
myProperty: ctx.myProperty, | ||
}; | ||
} | ||
}, | ||
}) | ||
) | ||
.get('/', (ctx) => { | ||
ctx.log.info(ctx, 'Context'); | ||
.get("/", (ctx) => { | ||
ctx.log.info(ctx, "Context"); | ||
return 'with-context'; | ||
return "with-context"; | ||
}); | ||
@@ -99,3 +99,3 @@ ``` | ||
```ts | ||
import { createPinoLogger } from '@bogeychan/elysia-logger'; | ||
import { createPinoLogger } from "@bogeychan/elysia-logger"; | ||
@@ -108,8 +108,8 @@ const log = createPinoLogger(/* ... */); | ||
log.error(ctx, ctx.error.name); | ||
return 'onError'; | ||
return "onError"; | ||
}) | ||
.get('/', (ctx) => { | ||
ctx.log.info(ctx, 'Context'); | ||
.get("/", (ctx) => { | ||
ctx.log.info(ctx, "Context"); | ||
throw { message: '1234', name: 'MyError' }; | ||
throw { message: "1234", name: "MyError" }; | ||
}); | ||
@@ -121,3 +121,3 @@ ``` | ||
```ts | ||
import { logger } from '@bogeychan/elysia-logger'; | ||
import { logger } from "@bogeychan/elysia-logger"; | ||
@@ -132,7 +132,7 @@ app | ||
return true; // ignore logging for requests based on condition | ||
} | ||
} | ||
}, | ||
}, | ||
}) | ||
) | ||
.get('/', (ctx) => 'autoLogging'); | ||
.get("/", (ctx) => "autoLogging"); | ||
``` | ||
@@ -145,2 +145,1 @@ | ||
[MIT](LICENSE) | ||
@@ -64,2 +64,3 @@ import pino from "pino"; | ||
const log = createPinoLoggerInternal(options); | ||
// @ts-ignore | ||
(log as unknown as ElysiaLoggerInstance).into = into.bind(log); | ||
@@ -104,4 +105,4 @@ return log as unknown as ElysiaLoggerInstance; | ||
if (autoLogging) { | ||
app = ( | ||
app as _INTERNAL_ElysiaLoggerPlugin< | ||
return ( | ||
app as unknown as _INTERNAL_ElysiaLoggerPlugin< | ||
_INTERNAL_Writeonly<_INTERNAL_ElysiaLoggerPluginAutoLoggingState> | ||
@@ -108,0 +109,0 @@ > |
import type { pino } from "pino"; | ||
import type { | ||
Context, | ||
DefinitionBase, | ||
Elysia, | ||
RouteBase, | ||
SingletonBase, | ||
} from "elysia"; | ||
import type { Context, Elysia, RouteSchema } from "elysia"; | ||
@@ -79,3 +73,3 @@ /** | ||
export type InferContext<T> = T extends Elysia< | ||
infer Path, | ||
infer _Path, | ||
infer _Scoped, | ||
@@ -85,8 +79,19 @@ infer Singleton, | ||
infer _Metadata, | ||
infer Routes, | ||
infer _EphemeralMetadata | ||
infer _Routes, | ||
infer Ephemeral, | ||
infer Volatile | ||
> | ||
? Context<Routes, SingletonBase, Path> & | ||
Partial<Singleton["derive"]> & | ||
Partial<Singleton["decorator"]> | ||
? Context< | ||
RouteSchema, | ||
{ | ||
decorator: Partial<Singleton["decorator"]>; | ||
store: Partial<Singleton["store"]>; | ||
derive: Partial< | ||
Singleton["derive"] & Ephemeral["derive"] & Volatile["derive"] | ||
>; | ||
resolve: Partial< | ||
Singleton["resolve"] & Ephemeral["resolve"] & Volatile["resolve"] | ||
>; | ||
} | ||
> | ||
: never; | ||
@@ -119,14 +124,2 @@ | ||
resolve: {}; | ||
}, | ||
DefinitionBase, | ||
{ | ||
macro: {}; | ||
schema: {}; | ||
}, | ||
RouteBase, | ||
{ | ||
store: {}; | ||
derive: {}; | ||
decorator: {}; | ||
resolve: {}; | ||
} | ||
@@ -133,0 +126,0 @@ >; |
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
23516
19
524
5
135