重构 更规范性的文件组织
This commit is contained in:
1 parent
59abbf30d9
commit
ea6c87ad25
53 files changed
+3274
-2110
No files matched your search
@@ -0,0 +1,31 @@
|
||||
/**
|
||||
* 简单的日志工具
|
||||
*/
|
||||
|
||||
const LOG_LEVELS = {
|
||||
DEBUG: 0,
|
||||
INFO: 1,
|
||||
WARN: 2,
|
||||
ERROR: 3
|
||||
};
|
||||
|
||||
const currentLevel = process.env.LOG_LEVEL
|
||||
? LOG_LEVELS[process.env.LOG_LEVEL.toUpperCase()]
|
||||
: LOG_LEVELS.INFO;
|
||||
|
||||
function log(level, message, ...args) {
|
||||
if (LOG_LEVELS[level] >= currentLevel) {
|
||||
const timestamp = new Date().toISOString();
|
||||
const prefix = `[${timestamp}] [${level}]`;
|
||||
console.log(prefix, message, ...args);
|
||||
}
|
||||
}
|
||||
|
||||
const logger = {
|
||||
debug: (message, ...args) => log('DEBUG', message, ...args),
|
||||
info: (message, ...args) => log('INFO', message, ...args),
|
||||
warn: (message, ...args) => log('WARN', message, ...args),
|
||||
error: (message, ...args) => log('ERROR', message, ...args)
|
||||
};
|
||||
|
||||
module.exports = logger;
|
||||
Reference in new issue
Block a user