Angular Logging: Difference between revisions

From bibbleWiki
Jump to navigation Jump to search
Created page with "=Introduction= This is just an approach to logging not the approach =ngx-logger= ==Install== <syntaxhighlight lang="bash"> npm install ngx-logger --save </syntaxhighlight> ==C..."
 
Line 32: Line 32:


</syntaxhighlight>
</syntaxhighlight>
*LoggerModule.forRoot
We have added the logger module at the root of our application. Now, every exported class, components, services, etc. are available throughout the application.
*serverLoggingUrl
This is needed to specify the endpoint where we need to post the logs from the Angular application. It can be a URL, or if you are using a proxy, then it can be the endpoint as well.
*level
The level defines the logs configuration level we need to print on the browser's console. This level can be DEBUG, ERROR, WARN, INFO, etc. If the value is set as OFF, it will disable the browser's console logs.
*serverLogLevel
This level defines the log configuration level which we need to post to the backend service or any API which is consuming the logging information. This level can be DEBUG, ERROR, WARN, INFO, etc. If the value is set as OFF, it will disable the server level logs.

Revision as of 23:38, 22 April 2021

Introduction

This is just an approach to logging not the approach

ngx-logger

Install

npm install ngx-logger --save

Configure

import { HttpClientModule } from '@angular/common/http';
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { LoggerModule, NgxLoggerLevel } from 'ngx-logger';

import { AppComponent } from './app.component';

@NgModule({
  declarations: [AppComponent],
  imports: [
    BrowserModule,
    HttpClientModule,
    LoggerModule.forRoot({
      serverLoggingUrl: '/api/logs',
      level: NgxLoggerLevel.DEBUG,
      serverLogLevel: NgxLoggerLevel.ERROR,
    }),
  ],
  providers: [],
  bootstrap: [AppComponent],
})
export class AppModule {}
  • LoggerModule.forRoot

We have added the logger module at the root of our application. Now, every exported class, components, services, etc. are available throughout the application.

  • serverLoggingUrl

This is needed to specify the endpoint where we need to post the logs from the Angular application. It can be a URL, or if you are using a proxy, then it can be the endpoint as well.

  • level

The level defines the logs configuration level we need to print on the browser's console. This level can be DEBUG, ERROR, WARN, INFO, etc. If the value is set as OFF, it will disable the browser's console logs.

  • serverLogLevel

This level defines the log configuration level which we need to post to the backend service or any API which is consuming the logging information. This level can be DEBUG, ERROR, WARN, INFO, etc. If the value is set as OFF, it will disable the server level logs.