feat: support logger destination (#2896)
* add-pino-destination-stream-support * destinationStream => loggerDestination
This commit is contained in:
@@ -140,6 +140,10 @@ A boolean that when set to `true` tells Payload to start in local-only mode whic
|
||||
|
||||
Specify options for the built-in Pino logger that Payload uses for internal logging. See [Pino Docs](https://getpino.io/#/docs/api?id=options) for more info on what is available.
|
||||
|
||||
##### `loggerDestination`
|
||||
|
||||
Specify destination stream for the built-in Pino logger that Payload uses for internal logging. See [Pino Docs](https://getpino.io/#/docs/api?id=pino-destination) for more info on what is available.
|
||||
|
||||
##### `onInit`
|
||||
|
||||
A function that is called immediately following startup that receives the Payload instance as it's only argument.
|
||||
|
||||
@@ -7,7 +7,7 @@ import SMTPConnection from 'nodemailer/lib/smtp-connection';
|
||||
import GraphQL from 'graphql';
|
||||
import { ConnectOptions } from 'mongoose';
|
||||
import React from 'react';
|
||||
import { LoggerOptions } from 'pino';
|
||||
import { DestinationStream, LoggerOptions } from 'pino';
|
||||
import type { InitOptions as i18nInitOptions } from 'i18next';
|
||||
import { Payload } from '../payload';
|
||||
import {
|
||||
@@ -116,6 +116,7 @@ export type InitOptions = {
|
||||
* See Pino Docs for options: https://getpino.io/#/docs/api?id=options
|
||||
*/
|
||||
loggerOptions?: LoggerOptions;
|
||||
loggerDestination?: DestinationStream;
|
||||
|
||||
/**
|
||||
* Sometimes, with the local API, you might need to pass a config file directly, for example, serverless on Vercel
|
||||
|
||||
@@ -146,7 +146,7 @@ export class BasePayload<TGeneratedTypes extends GeneratedTypes> {
|
||||
* @param options
|
||||
*/
|
||||
async init(options: InitOptions): Promise<Payload> {
|
||||
this.logger = Logger('payload', options.loggerOptions);
|
||||
this.logger = Logger('payload', options.loggerOptions, options.loggerDestination);
|
||||
this.mongoURL = options.mongoURL;
|
||||
this.mongoOptions = options.mongoOptions;
|
||||
|
||||
|
||||
@@ -9,10 +9,10 @@ const defaultLoggerOptions = {
|
||||
},
|
||||
};
|
||||
|
||||
const getLogger = (name = 'payload', options?: pino.LoggerOptions): PayloadLogger => pino({
|
||||
const getLogger = (name = 'payload', options?: pino.LoggerOptions, destination?: pino.DestinationStream): PayloadLogger => pino({
|
||||
name: options?.name || name,
|
||||
enabled: process.env.DISABLE_LOGGING !== 'true',
|
||||
...(options || defaultLoggerOptions),
|
||||
});
|
||||
}, destination);
|
||||
|
||||
export default getLogger;
|
||||
|
||||
Reference in New Issue
Block a user