ng-env-logger
— Angular Logging Service Package
How many times have you left a rogue console.log
in your production code? That's the worst, right? This package will help keep that from occurring.
This package logs to the console by giving you multiple levels to write:
- error
- warn
- info
- debug
- log
When the service is initialized, you provide a level for it to write. So, for example, if you provide the WARN
level (number 2), this.logService.info()
, .debug()
, and .log()
calls are ignored; only the .warn()
and .error()
functions continue to work. This will allow you to log certain messages or objects in development without worrying about removing them for your production version of the app. Whichever level you choose, the service logs that number and lower to the console.
To use the service, add the following to your AppModule
's imports array:
NgLogModule.forRoot({ level: LogLevels.WARN }),
To update the logging level, call the updateLogLevel
function on the service and pass it a one of the above levels. The provided number does have to be between 1 and 5, which are the values that the enum LogLevels provides.