1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253 |
- const chalk = require('chalk');
-
- LOG_TYPES = {
- NONE: 0,
- ERROR: 1,
- NORMAL: 2,
- DEBUG: 3,
- FFDEBUG: 4
- };
-
- let logType = LOG_TYPES.NORMAL;
-
- const setLogType = (type) => {
- if (typeof type !== 'number') return;
-
- logType = type;
- };
-
- const logTime = () => {
- let nowDate = new Date();
- return nowDate.toLocaleDateString() + ' ' + nowDate.toLocaleTimeString([], { hour12: false });
- };
-
- const log = (...args) => {
- if (logType < LOG_TYPES.NORMAL) return;
-
- console.log(logTime(), process.pid, chalk.bold.green('[INFO]'), ...args);
- };
-
- const error = (...args) => {
- if (logType < LOG_TYPES.ERROR) return;
-
- console.log(logTime(), process.pid, chalk.bold.red('[ERROR]'), ...args);
- };
-
- const debug = (...args) => {
- if (logType < LOG_TYPES.DEBUG) return;
-
- console.log(logTime(), process.pid, chalk.bold.blue('[DEBUG]'), ...args);
- };
-
- const ffdebug = (...args) => {
- if (logType < LOG_TYPES.FFDEBUG) return;
-
- console.log(logTime(), process.pid, chalk.bold.blue('[FFDEBUG]'), ...args);
- };
-
- module.exports = {
- LOG_TYPES,
- setLogType,
-
- log, error, debug, ffdebug
- }
|