I am trying to create a log service. When I try to display just e.stack, it shows each file and line number of the file.
buildLogString() {
const e = new Error();
console.log(e.stack);
const stack = e.stack.split('\n');
for (const item of stack) {
console.log('-------');
console.log(item);
}
}
console.log(e.stack); displays:
Error
at LogEntry.buildLogString (logEntry.ts:32)
at LogService.writeToLog (log.service.ts:50)
at LogService.warn (log.service.ts:23)
at new BodyComponent (body.component.ts:70)
at createClass (core.js:21157)
at createDirectiveInstance (core.js:21026)
at createViewNodes (core.js:29386)
at createRootView (core.js:29300)
at callWithDebugContext (core.js:30308)
at Object.debugCreateRootView [as createRootView] (core.js:29818)
And with for loop, each element shows:
-------
Error
-------
at LogEntry.buildLogString (http://localhost:4200/main.js:24639:21)
-------
at LogService.writeToLog (http://localhost:4200/main.js:24576:31)
-------
at LogService.warn (http://localhost:4200/main.js:24547:14)
-------
at new BodyComponent (http://localhost:4200/app-app-module.js:30694:27)
I want to keep the first details into the array but when I split into array, it shows details from main.js or app-app-module.js
How can I keep the first details (E.g. at LogEntry.buildLogString (logEntry.ts:32)) ?