Is it possible to have ngx-logger use a different object to log? Currently all logs are based on the NGXLogInterface below:
export class NGXLogInterface {
level: NgxLoggerLevel;
timestamp: string;
fileName: string;
lineNumber: string;
message: string;
additional: any[];
}
However I need to send my logs to an API which is expecting a body like the one below:
{
"application": "string",
"component": "string",
"area": "string",
"level": "string",
"details": "string",
"executingUser": "string",
}
// this service responsible to send the request is NGXLoggerHttpService so you must provide another one to change the signature of the model.
1 - add the override the service in the same module which you instantiate the LoggerModule ==> LoggerModule.forRoot() ....
2 - Write the new service in charge ton send the request by extending the original one and overriding the logOnServer method
providers: [
{provide: NGXLoggerHttpService, useClass: MyLoggerHttpService, multi: false}
]
@Injectable()
export class MyLoggerHttpService extends NGXLoggerHttpService {
public constructor(private readonly _http: HttpBackend) {
super(_http);
}
public logOnServer(url: string, log: NGXLogInterface, options: object): Observable<any> {
const value: any = JSON.parse(log.message);
return super.logOnServer(url, value as any, options );
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With