@bogeychan/elysia-logger
Advanced tools
Comparing version 0.1.2 to 0.1.3
import pino from "pino"; | ||
import { Elysia } from "elysia"; | ||
import type { ElysiaLogger, StandaloneLoggerOptions, ElysiaFileLoggerOptions, ElysiaStreamLoggerOptions, _INTERNAL_Writeonly, _INTERNAL_ElysiaLoggerPlugin, _INTERNAL_ElysiaLoggerPluginAutoLoggingState, _INTERNAL_ElysiaLoggerPluginAutoLoggingEnabledOptions, _INTERNAL_ElysiaLoggerPluginAutoLoggingDisabledOptions } from "./types"; | ||
/** | ||
* The StreamLogger is used to write log entries to a stream such as the console output (default behavior). | ||
*/ | ||
export declare function logger(options?: _INTERNAL_ElysiaLoggerPluginAutoLoggingEnabledOptions<ElysiaStreamLoggerOptions>): _INTERNAL_ElysiaLoggerPlugin<_INTERNAL_ElysiaLoggerPluginAutoLoggingState>; | ||
export declare function logger(options?: _INTERNAL_ElysiaLoggerPluginAutoLoggingDisabledOptions<ElysiaStreamLoggerOptions>): _INTERNAL_ElysiaLoggerPlugin; | ||
/** | ||
* A FileLogger lets you store log entries in a file. | ||
*/ | ||
export declare function fileLogger(options: _INTERNAL_ElysiaLoggerPluginAutoLoggingEnabledOptions<ElysiaFileLoggerOptions>): _INTERNAL_ElysiaLoggerPlugin<_INTERNAL_ElysiaLoggerPluginAutoLoggingState>; | ||
export declare function fileLogger(options: _INTERNAL_ElysiaLoggerPluginAutoLoggingDisabledOptions<ElysiaFileLoggerOptions>): _INTERNAL_ElysiaLoggerPlugin; | ||
/** | ||
* Create a logger instance like the plugin. | ||
*/ | ||
export declare function createPinoLogger(options?: StandaloneLoggerOptions): ElysiaLogger<Elysia<"", false, { | ||
@@ -9,0 +18,0 @@ decorator: {}; |
import pino from "pino"; | ||
import { Elysia } from "elysia"; | ||
/** | ||
* If you call one of the derived methods of this plugin (such as: ctx.log.info(object)) with a request or context object, | ||
* these formatters and serializers ensure that not everything ends up in the log output. | ||
* | ||
* You can replace them altogether by providing your own via the plugin-options to manipulate the output. | ||
* | ||
* I highly recommend to read the [Pino documentation](https://getpino.io/#/docs/api?id=options) yourself to learn about additional options. | ||
*/ | ||
import { formatters, serializers } from "./config"; | ||
@@ -10,4 +18,8 @@ export function logger(options = {}) { | ||
} | ||
/** | ||
* Create a logger instance like the plugin. | ||
*/ | ||
export function createPinoLogger(options = {}) { | ||
const log = createPinoLoggerInternal(options); | ||
// @ts-ignore | ||
log.into = into.bind(log); | ||
@@ -14,0 +26,0 @@ return log; |
import type { pino } from "pino"; | ||
import type { Context, Elysia, RouteSchema, ErrorHandler, SingletonBase, EphemeralType } from "elysia"; | ||
/** | ||
* The StreamLogger is used to write log entries to a stream such as the console output. | ||
*/ | ||
export interface StreamLoggerOptions extends BaseLoggerOptions { | ||
@@ -8,2 +11,5 @@ stream?: pino.DestinationStream; | ||
} | ||
/** | ||
* A FileLogger lets you store log entries in a file. | ||
*/ | ||
export interface FileLoggerOptions extends BaseLoggerOptions { | ||
@@ -23,3 +29,12 @@ file: string | number | pino.DestinationStream | NodeJS.WritableStream; | ||
export type ElysiaLoggerOptions = { | ||
/** | ||
* This function will be invoked for each `log`-method called with `context` | ||
* where you can pass additional properties that need to be logged | ||
*/ | ||
customProps?: (ctx: ElysiaLoggerContext) => object; | ||
/** | ||
* Disable the automatic "onAfterResponse" & "onError" logging | ||
* | ||
* @default true | ||
*/ | ||
autoLogging?: boolean | { | ||
@@ -30,2 +45,18 @@ ignore: (ctx: ElysiaLoggerContext) => boolean; | ||
export interface ElysiaLogger<E = Elysia> extends Logger { | ||
/** | ||
* Call `into` to use the logger instance in both `ctx` and standalone | ||
* | ||
* @example | ||
* const log = createPinoLogger(...); | ||
* app | ||
* .use(log.into()) | ||
* .onError((ctx) => { | ||
* log.error(ctx, ctx.error.name); | ||
* return 'onError'; | ||
* }) | ||
* .get('/', (ctx) => { | ||
* ctx.log.info(ctx, 'Context'); | ||
* throw { message: '1234', name: 'MyError' }; | ||
* }) | ||
*/ | ||
into(options?: _INTERNAL_ElysiaLoggerPluginAutoLoggingEnabledOptions<ElysiaLoggerOptions>): _INTERNAL_ElysiaLoggerPlugin<_INTERNAL_ElysiaLoggerPluginAutoLoggingState>; | ||
@@ -53,2 +84,7 @@ into(options?: _INTERNAL_ElysiaLoggerPluginAutoLoggingDisabledOptions<ElysiaLoggerOptions>): _INTERNAL_ElysiaLoggerPlugin; | ||
}>) : never; | ||
/** | ||
* Make all properties in T NOT readonly | ||
* | ||
* based on @see Readonly | ||
*/ | ||
export type _INTERNAL_Writeonly<T> = { | ||
@@ -55,0 +91,0 @@ -readonly [P in keyof T]: T[P]; |
{ | ||
"name": "@bogeychan/elysia-logger", | ||
"version": "0.1.2", | ||
"version": "0.1.3", | ||
"description": "A plugin for Elysia.js for logging using the pino library", | ||
@@ -28,3 +28,3 @@ "author": { | ||
}, | ||
"types": "./src/index.ts", | ||
"types": "./dist/types.d.ts", | ||
"scripts": { | ||
@@ -31,0 +31,0 @@ "dev": "bun run --watch examples/basic.ts", |
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
18253
14
352