English 中文(简体)
• 如何根据遗嘱对 Nest公司进行洗手?
原标题:How to disable NestJS Logger, based on env?

I m 在中采用记录方法 用于控制 Nest鱼()的方法 生产模式中的微薄计分量,但并未使用<条码>ENV=生产,仍在显示<条码> 记录记录仪表。

const bootstrap = async () => {
  const app = await NestFactory.create<NestExpressApplication>(AppModule, {
    logger:
      env.ENV ==  development 
        ? [ debug ,  error ,  log ,  verbose ,  warn ]
        : [ error ,  warn ],
  });

  app.enableCors();

  app.use(helmet());
  app.set( trust proxy , 1);
问题回答
  1. I create my custom logger
  2. Inject it in the root module.

在习惯记录仪的构造中,即我使用set式记录仪功能来说明我的情况。 我定下了空洞的等级,这样它就能够忽视任何ole。

import { ConsoleLogger, Injectable, LoggerService } from  @nestjs/common ;

@Injectable()
export class AppLogger extends ConsoleLogger implements LoggerService {
  constructor(
    context: string,
    options?: {
      timestamp?: boolean;
    },
  ) {
    super(context, options);
    /***
     * @condition to check if it is in testing mode
     */
    if (condition) {
      this.setLogLevels([]);
    }
  }
}

可在Node.js中查阅>>process.env Global Object。

The following example is working as expected, Read process.env.ENV:

async function bootstrap() {
  const app = await NestFactory.create(AppModule, {
    logger: process.env.ENV ===  production  ? [ warn ,  error ] : [ debug ,  log ,  verbose ]
  });
  await app.listen(3000);
}

bootstrap();





相关问题
store data in memory with nestjs

I am trying to persist some data in my nestjs server so I can then use that data in my client app through http requests. I have created a products.service.ts file with the function getAllData() that ...

React Hook Form Error on custom Input component

I am having a problem when I use react hook form + zod in my application, in short the inputs never change value and I get the following error in the console: Warning: Function components cannot be ...

Updatable promises using proxy in JavaScript

EDIT: I ve updated this question, and the old question is moved here. A POC can be found on this jsfiddle or the snippet below GOAL: The goal here is to make or rather simulate a promise that can be ...

热门标签