2016-10-09 21:14:02 +02:00
|
|
|
"use strict";
|
|
|
|
|
2022-05-02 09:21:11 +02:00
|
|
|
import colors from "chalk";
|
|
|
|
import read from "read";
|
2016-04-16 13:32:38 +02:00
|
|
|
|
2017-11-22 07:39:32 +01:00
|
|
|
function timestamp() {
|
2020-03-21 21:55:36 +01:00
|
|
|
const datetime = new Date().toISOString().split(".")[0].replace("T", " ");
|
2018-09-20 13:15:05 +02:00
|
|
|
|
|
|
|
return colors.dim(datetime);
|
2016-04-16 13:32:38 +02:00
|
|
|
}
|
|
|
|
|
2022-05-03 03:32:20 +02:00
|
|
|
const log = {
|
2018-03-20 06:54:04 +01:00
|
|
|
/* eslint-disable no-console */
|
2022-05-02 09:21:11 +02:00
|
|
|
error(...args: string[]) {
|
2018-03-20 06:54:04 +01:00
|
|
|
console.error(timestamp(), colors.red("[ERROR]"), ...args);
|
|
|
|
},
|
2022-05-02 09:21:11 +02:00
|
|
|
warn(...args: string[]) {
|
2018-03-20 06:54:04 +01:00
|
|
|
console.error(timestamp(), colors.yellow("[WARN]"), ...args);
|
|
|
|
},
|
2022-05-02 09:21:11 +02:00
|
|
|
info(...args: string[]) {
|
2018-03-20 06:54:04 +01:00
|
|
|
console.log(timestamp(), colors.blue("[INFO]"), ...args);
|
|
|
|
},
|
2022-05-02 09:21:11 +02:00
|
|
|
debug(...args: string[]) {
|
2018-03-20 06:54:04 +01:00
|
|
|
console.log(timestamp(), colors.green("[DEBUG]"), ...args);
|
|
|
|
},
|
2022-05-02 09:21:11 +02:00
|
|
|
raw(...args: string[]) {
|
2018-03-20 06:54:04 +01:00
|
|
|
console.log(...args);
|
|
|
|
},
|
|
|
|
/* eslint-enable no-console */
|
|
|
|
|
2022-05-02 09:21:11 +02:00
|
|
|
prompt(
|
2022-05-02 09:50:13 +02:00
|
|
|
options: {prompt?: string; default?: string; text: string; silent?: boolean},
|
2022-05-02 09:21:11 +02:00
|
|
|
callback: (error, result, isDefault) => void
|
|
|
|
): void {
|
2018-03-20 06:54:04 +01:00
|
|
|
options.prompt = [timestamp(), colors.cyan("[PROMPT]"), options.text].join(" ");
|
|
|
|
read(options, callback);
|
|
|
|
},
|
2016-12-15 07:13:43 +01:00
|
|
|
};
|
2022-05-03 03:32:20 +02:00
|
|
|
|
|
|
|
export default log;
|