hardlounge/server/log.ts

39 lines
980 B
TypeScript
Raw Permalink Normal View History

import colors from "chalk";
import read from "read";
2016-04-16 11:32:38 +00:00
function timestamp() {
const datetime = new Date().toISOString().split(".")[0].replace("T", " ");
2018-09-20 11:15:05 +00:00
return colors.dim(datetime);
2016-04-16 11:32:38 +00:00
}
const log = {
/* eslint-disable no-console */
error(...args: string[]) {
console.error(timestamp(), colors.red("[ERROR]"), ...args);
},
warn(...args: string[]) {
console.error(timestamp(), colors.yellow("[WARN]"), ...args);
},
info(...args: string[]) {
console.log(timestamp(), colors.blue("[INFO]"), ...args);
},
debug(...args: string[]) {
console.log(timestamp(), colors.green("[DEBUG]"), ...args);
},
raw(...args: string[]) {
console.log(...args);
},
/* eslint-enable no-console */
prompt(
options: {prompt?: string; default?: string; text: string; silent?: boolean},
callback: (error, result, isDefault) => void
): void {
options.prompt = [timestamp(), colors.cyan("[PROMPT]"), options.text].join(" ");
read(options, callback);
},
};
export default log;