ngx-logger在angular中的实现

时间:2019-07-02 07:45:00

标签: angular angular7 angular8

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

How to configure logger level for ngx-logger in global config file

但是我的问题是我无法理解公认答案的解决方案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?我该怎么办?

1 个答案:

答案 0 :(得分:0)

如果您具有默认的应用设置,则您的目录名为environments,其中包含2个文件environments.tsenvironments.prod.ts。 首先是默认值,当您使用--environment = prod进行编译时,第二个将代替默认值。对于不同的环境,您可以具有任意数量的此类文件。您可以根据需要在此处定义任何变量(或环境const中的属性)。

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

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

和产品:

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

导入并在任何需要的地方使用environment.debugLevel

相关问题