I have an Angular 18 application now built on standalone component concepts. I want to use ngx-logger for logging errors, warnings and Inf to server. I have seen multiple articles about ng-logger in modular patterns and there are no references to how to use them in Standalone components.
Please guide me on how I can do it.
The code I had written is giving compilation issues when I added LoggerModule.forRoort({....}).
For resolving errors I commented the .forRoot({..}) part.
import { Component } from '@angular/core';
import { RouterOutlet } from '@angular/router';
import { LoggerModule, NGXLogger } from 'ngx-logger';
@Component({
selector: 'app-root',
standalone: true,
imports: [
RouterOutlet,
LoggerModule
// .forRoot({
// serverLoggingUrl: '/api/logs',
// level: NgxLoggerLevel.DEBUG,
// serverLogLevel: NgxLoggerLevel.ERROR
// })
],
providers: [
],
templateUrl: './app.component.html',
styleUrl: './app.component.css'
})
export class AppComponent {
title = 'Hello';
constructor(
private logger: NGXLogger) {
this.logger.debug("Debug message");
this.logger.info("Info message");
this.logger.log("Default log message");
this.logger.warn("Warning message");
this.logger.error("Error message");
}
}
Output:
R3InjectorError(Standalone[_AppComponent])[NGXLogger -> NGXLogger -> TOKEN_LOGGER_CONFIG -> TOKEN_LOGGER_CONFIG]:
NullInjectorError: No provider for TOKEN_LOGGER_CONFIG!
at NullInjector.get (eval at instantiateModule (file:///aaaaa/node_modules/vite/dist/node/chunks/dep-DyBnyoVI.js:52905:24), <anonymous>:13862:21)
at R3Injector.get (eval at instantiateModule (file://aaaaa/node_modules/vite/dist/node/chunks/dep-DyBnyoVI.js:52905:24), <anonymous>:14755:27)
at R3Injector.get (eval at instantiateModule (file://aaaaa/node_modules/vite/dist/node/chunks/dep-DyBnyoVI.js:52905:24), <anonymous>:14755:27)
at injectInjectorOnly (eval at instantiateModule (file://aaaaa/node_modules/vite/dist/node/chunks/dep-DyBnyoVI.js:52905:24), <anonymous>:13595:36)
at Module.ɵɵinject (eval at instantiateModule (file://aaaaa/node_modules/vite/dist/node/chunks/dep-DyBnyoVI.js:52905:24), <anonymous>:13601:59)
at Object.NGXLogger_Factory [as factory] (eval at instantiateModule