用户:
Nomen查看:1 回复:2 评论:1 创建时间:2023-05-27T04:28:05
这里是没有开场白的Nomen,EasyLog使用方法很简单,能够让创作者更容易了解到游玩端过程中的一些调试信息。
本体:
/**
* !info {Project} -来自Nomen
* @version 1.0.0
* @requires NomenFS@1.7.3
* @requires NomenSQLite@1.2.2
* EasyLog 快速添加或者读取log
*/
function EasyLog(ns) {
if (!ns || ns === undefined) throw new Error('请传入一个正确的NomenFS实例');
ns.log = async function (title, content) {
let path = `/log/${title}.log`;
await this.mkdir('/log');
if ((await this.readdir('/log')).includes(path)) await this.appendFile(path, `\n${content}`)
else await this.writeFile(path, content)
return title;
};
ns.readLog = async function (title) {
try { return await this.readFile(`/log/${title}.log`) }
catch { return null }
}
}
module.exports = {
initLog
}
使用方法很简单,传入一个NomenFS实例,然后在实例上调用log和readLog方法
log第一个参数填写的是.log文件的文件名,例如:log-of-2023-5-26。第二个参数填写的是log内容
readLog传入一个文件名即可,例如log-of-2023-5-26
附示例代码:
let ns = await (require('./NomenFS.js')).NomenFS.launch((require('./NomenSQLite.js')).NomenSQLite);
initLog(ns);
await ns.log('log114','Cause I got a crush on you who you');
await ns.log('log114','你是我的我是你的谁');
await ns.log('log114','再多一眼看一眼就会爆炸');
await ns.log('log114','再近一点靠近点快被融化');
await ns.log('log114','想要把你占为己有baby bae');
console.log(await ns.readLog('log114'));
============
requires:NomenFS@1.7.3
github.com/helloyork/Box3-Tools/blob/main/src/数据库工具/NomenFileSystem/index.js
requires:NomenSQLite@1.2.2
github.com/helloyork/Box3-Tools/blob/main/src/数据库工具/NomenSQLite/index.js
请更新以上两个依赖项,并且在对应的文件内模块导出