我想使用debug
能够在每次调用时打印方法/函数名称和参数。
实现此目的的最佳方法是什么,而不是像这样在每个函数中放置自定义的 debug
语句:
async function getFilePaths(path, id) {
debug(`async function getFilePaths(path = ${path}, id = ${id})`);
// ...
}
最佳答案
你可以这样做:
function logDebug(fn, args) {
debug(fn.name + args.toString());
}
并在你的函数中调用它
function getFilePaths(path, id) {
logDebug(getFilePaths, arguments);
}
注意:Function.name
是ES6中支持的一项新技术。
关于javascript - 使用 debug 在 Node.js 中打印函数名称和参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31445852/