简体   繁体   中英

ngx-logger implementation in angular

I am new to angular and I am trying to add loggers to my angular 8 application. I have been following following tutorial https://medium.com/@ahmedhamedTN/enable-disable-angular-logging-based-on-production-environment-using-ngxlogger-dee531fb8374 and able to understand most of the part. But I have doubt regarding enable ngx-logger for different environment. I have two environment in my application ie development and production. Found following solution on stackoverflow to resolve this::

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

But problem with me is I am not able to understand solution 1 of accepted answer. Can anyone explain this solution

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

where I need to set another variable isdebug for all files? How can I do that?

If you have the default app setup you have the directory named environments with 2 files environments.ts and environments.prod.ts . First is the default, second will be substituted in place of default when you compile with --environment=prod. You can have any number of such files for different environments. You can define any variables there (or properties in environment const) as you wish.

So when you do import { environment, .... } from '../environments.ts'; you will have the set of variables defined in file according to your environment. For example, define in dev:

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

and in prod:

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

import and use environment.debugLevel wherever you want

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM