I want to log an errors to know from which method/function of class i got error. To log this i want a generic code, by that i can know the method/function name from method it self. below is my code.
In below code, each catch block i want particular method name like SaveData and GetData.
I tried arguments.callee but it's not working in strict mode.
I also tried Object.values(this) but it gives me all methods array so i can't decide at what element my current method name exist.
I want any generic solution because i have hundreds of function in a class and i not want to write each function name in each method.
class MyClass {
/**
* Class default constructor
*/
constructor() {
this.file_path = path.join(__dirname, path.basename(__filename));
}
SaveData = async (req, res) => {
try {
//doing some operation to store data
} catch (err) {
//in catch block i want "SaveData"(method name) so i can pass as parameter in below generic method which i have created somewhere in common file.
log.error(res, err, this.file_path);
}
}
GetData = async (req,res) => {
try {
//doing some operation to get records from db
} catch (err) {
//in catch block i want "GetData"(method name) so i can pass as parameter in below generic method which i have created somewhere in common file.
log.error(res, err, this.file_path);
}
}
}
module.exports = new MyClass();