代码拉取完成,页面将自动刷新
/**
* 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;
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。