0

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 i.e 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?

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

5 Comments

Thanks , I got it. Just one more question, while running how application will come to know this variable debugLevel value?
As I wrote in the answer - import it. import { environment } from '../path/to/environments.ts';
one more question I am following above link in my question to implement ngx-logger in my application. As per this link changes related to needed to be done on component side. Do I need to make some logging related changes in html pages of my application or method metioned in link will be suffficcient?
Sorry, I dont understand you.
In any angular application we have two parts html and corresponding component. As per link I just need to implement ngx-logger in app.module.ts and use it in any component in my application. My question is do I need to make any change in html file to implement logger or method mentioned in link is sufficient?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.