neo-logger
Summary
Programmers frequently use console.log to record errors or other informational messages in their Angular applications. Although this is fine while debugging your application, it’s not a best practice for production applications. As Angular is all about services, it’s a better idea to create a logging service that you can call from other services and components. In this logging service, you can still call console.log, but you can also modify the service later to record messages to store them in local storage or a database table via the Web API.
A Simple Logging Service
To get started, create a very simple logging service that only logs to the console. The point here is to replace all of your console.log statements in your Angular application with calls to a service.
A logger has 5 different levels of logging in a specific order:
'fatal', 'error', 'warn', 'info', 'debug' Each of these log levels has its own method on the logging instance. You can set the maximum log level on a logger at runtime.
How to use neo-logger
npm install neo-logger
Add NeoLoggerModule in root module(appModule.ts)
import LogService in particular component like below
Example
import { Component } from '@angular/core';
import { LogService } from 'neo-logger';
@Component({
selector: 'al-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent {
title = 'al';
userDetails = {
'username': 'xyz',
'userEmailId': 'abc@xyz.com'
};
constructor(private logService: LogService) {
this.logService.setUserDetails(this.userDetails);
this.logService.info('Getting Logs');
}
}
Set the userdetails in this logService.setUserDetails() method before calling any logService methods like 'fatal', 'error', 'warn', 'info', 'debug'
Because pushing all the logs to SQS(AWS Simple Queue Service) through API it requires paticular userDetails of your application.