当我运行此代码时,日志文件名将为'undefined'。检查文件返回正确的文件名,但filename变量与此不相等。
const logger = async () => {
filename = await checkFile();
openFile();
}
const checkFile = async () => {
originfn = "xyservice_" + await datetime.date() + ".log";
fs.access(`logs/${originfn}`, fs.constants.F_OK, (err) => {
//console.log(`logs/${origfn} ${err ? 'does not exist' : 'exists'}`);
if (err) {
return originfn;
} else {
return originfn + ".2";
}
});
}
const openFile = async () => {
fs.appendFile(`logs/${filename}`, await time() + `Logging system
started...in file logs/${filename}`, function(err) {
if (err) console.log(err);
console.log('Log file created...');
});
return;
}
然后该代码如何工作?我不明白。有什么区别吗?
const permParser = async (perms) => {
let permissions = {}
//general code
return permissions;
}
我这样打电话
await permParser(permtopars)