angular 中的 ngx-logger 实现

ngx-logger implementation in angular

我是 angular 的新手,我正在尝试将记录器添加到我的 angular 8 应用程序中。我一直在关注以下教程 https://medium.com/@ahmedhamedTN/enable-disable-angular-logging-based-on-production-environment-using-ngxlogger-dee531fb8374 并且能够理解大部分内容。但是我对为不同的环境启用 ngx-logger 有疑问。我的应用程序中有两个环境,即开发和生产。在 Whosebug 上找到以下解决方案来解决此问题::

但我的问题是我无法理解已接受答案的解决方案 1。谁能解释一下这个解决方案

you can set another variable isdebug for all files.

For production —————— isdebug=1

For debug —————— isdebug=2

For mock —————— isdebug=3

Your coding. (environment.isdebug === 1 || environment.isdebug === 2) ? NgxLoggerLevel.LOG :: NgxLoggerLevel.OFF

我需要在哪里为所有文件设置另一个变量 isdebug?我该怎么做?

如果你有默认的应用程序设置,你有一个名为 environments 的目录,其中包含 2 个文件 environments.tsenvironments.prod.ts。 第一个是默认值,当您使用 --environment=prod 编译时,第二个将被替换为默认值。对于不同的环境,您可以拥有任意数量的此类文件。您可以根据需要在那里定义任何变量(或环境常量中的属性)。

因此,当您执行 import { environment, .... } from '../environments.ts'; 时,您将根据您的环境在文件中定义一组变量。 比如在dev中定义:

export const environment = {
  production: false,
  debugLevel: 1
};

在产品中:

export const environment = {
  production: true,
  debugLevel: 3
};

随时随地导入和使用environment.debugLevel