I am trying to make it possible to log errors, and save/log it to a file on the front end side.
I have a module that handles a window.onError method,
It is called myModule.onError() on the React side. From here if their is an error, it shows up in the console.log() like this
How would i go about logging this error into a file ?
I've tried bundling multiple logging libraries(like winston, buyan, log4js, etc) with my module, and im getting errors from fs is not found, to much more errors.
Here is my window on error method, what should i do so it would be possible to log the window.onError errors into a file. How would i bundle it within my module ?
function onError(){
const data = {};
return window.onerror = ( msg, url,lineNo,columnNo, error) => {
let string = msg.toLowerCase();
let substring = 'script error';
if (string.indexOf(substring) > -1) {
alert('Script Error: See Browser Console for Detail');
}
else {
let message = [
'Message: ' + msg,
'URL: ' + url,
'Line: ' + lineNo,
'Column: ' + columnNo,
'Error object: ' + JSON.stringify(error)
].join(' - ');
const messageObj = {
Message: msg,
URL: url,
Line: lineNo,
Column: columnNo,
ErrorObject: JSON.stringify(error)
};
const messObj = JSON.stringify(messageObj)
console.log(messObj);
// ourLogger.log('info',messObj);
// maybe call an axios post passing in the error
// axios.post('/clinet-log',{messObj} )
// .then( res => {
// res
// })
console.log(messageObj);
return messObj;
}
};
}
export function onErrorMain(){
let onErrorinit = onError();
return onErrorinit;
}
