Ai
41 Star 153 Fork 27

CC呀/Exp通勤班车预约小程序

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
log_util.js 2.28 KB
一键复制 编辑 原始数据 按行查看 历史
778333@outlook.com 提交于 2025-07-10 07:08 +08:00 . Initial Commit
/**
* Notes: 日志操作函数
* Ver : CCMiniCloud Framework 2.0.1 ALL RIGHTS RESERVED BY cclinux@qq.com
* Date: 06-12 04:00:00
*/
const timeUtil = require('./time_util.js');
class LogUtil {
constructor(level = 'info') {
this.logOut = ''; // 输出日志内容
level = level.toLowerCase();
if (level == 'err') level = 'error';
switch (level) {
case 'debug':
level = LogUtil.LEVEL.DEBUG;
break;
case 'info':
level = LogUtil.LEVEL.INFO;
break;
case 'warn':
level = LogUtil.LEVEL.WARN;
break;
case 'error':
level = LogUtil.LEVEL.ERROR;
break;
case 'fatal':
level = LogUtil.LEVEL.FATAL;
break;
case 'none':
level = LogUtil.LEVEL.NONE;
break;
default:
level = LogUtil.LEVEL.INFO;
}
this.level = level;
}
debug(str, ex = '') {
if (this.level > LogUtil.LEVEL.DEBUG) return;
console.debug('[' + this._getTime() + '] DEBUG: ' + str, ex);
this.logOut += "######" + '[' + this._getTime() + '] DEBUG: ' + str + (ex ? JSON.stringify(ex) : '');
}
info(str, ex = '') {
if (this.level > LogUtil.LEVEL.INFO) return;
console.log('[' + this._getTime() + '] INFO: ' + str, ex);
this.logOut += "######" + '[' + this._getTime() + '] INFO: ' + str + (ex ? JSON.stringify(ex) : '');
}
warn(str, ex = '') {
if (this.level > LogUtil.LEVEL.WARN) return;
console.warn('[' + this._getTime() + '] WARN: ' + str, ex);
this.logOut += "######" + '[' + this._getTime() + '] WARN: ' + str + (ex ? JSON.stringify(ex) : '');
}
error(str, ex = '') {
if (this.level > LogUtil.LEVEL.ERROR) return;
console.error('[' + this._getTime() + '] ERROR: ' + str, ex);
this.logOut += "######" + '[' + this._getTime() + '] ERROR: ' + str + (ex ? JSON.stringify(ex) : '');
}
fatal(str, ex = '') {
if (this.level > LogUtil.LEVEL.FATAL) return;
console.error('[' + this._getTime() + '] FATAL: ' + str, ex);
this.logOut += "######" + '[' + this._getTime() + '] FATAL: ' + str + (ex ? JSON.stringify(ex) : '');
}
_getTime() {
return timeUtil.time('Y-M-D h:m:s');
}
err(str) {
error(str);
}
getLogOut() {
return this.logOut;
}
}
LogUtil.LEVEL = {
DEBUG: 10,
INFO: 20,
WARN: 30,
ERROR: 40,
FATAL: 50,
NONE: 100,
};
module.exports = LogUtil;
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
JavaScript
1
https://gitee.com/hao-juan/ExWorkAppt.git
git@gitee.com:hao-juan/ExWorkAppt.git
hao-juan
ExWorkAppt
Exp通勤班车预约小程序
master

搜索帮助