-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.ts
22 lines (17 loc) · 1.05 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import chalk from 'chalk';
const { debug, error, info, log, warn } = require('console');
const getDebugInfo = () => {
const dateObject = new Date();
// Date in the Format: MM/DD/YY
const date = dateObject.toLocaleDateString('en-GB', { month: '2-digit', day: '2-digit', year: '2-digit' });
// Time in the Format: HH:MM:SS AM/PM
const time = dateObject.toLocaleTimeString('en-US', { hour: '2-digit', minute: '2-digit', second: '2-digit', fractionalSecondDigits: 3 });
// Unix Timestamp
const timestamp = dateObject.getTime();
return chalk.gray(`[${date} ${time} ${timestamp}]`);
};
console.debug = (...args) => debug(getDebugInfo(), ...args.map((arg) => chalk.blue(arg)));
console.error = (...args) => error(getDebugInfo(), ...args.map((arg) => chalk.red(arg instanceof Error ? arg.stack : arg)));
console.info = (...args) => info(getDebugInfo(), ...args);
console.log = (...args) => log(getDebugInfo(), ...args);
console.warn = (...args) => warn(getDebugInfo(), ...args.map((arg) => chalk.yellow(arg instanceof Error ? arg.stack : arg)));