Node.jsでコンソールの色を変えることができるので試してみました。
文字色や背景色、太字などの装飾ができます。
変更可能リスト: https://nodejs.org/api/util.html#modifiers
コードは以下になります。
import { styleText } from "node:util";
class Logger {
static info(message: string): void {
console.log(styleText("white", message));
}
static success(message: string): void {
console.log(styleText("green", message));
}
static warning(message: string): void {
console.log(styleText("yellow", message));
}
static error(message: string): void {
console.log(styleText("red", message));
}
static debug(message: string): void {
console.log(styleText(["gray", "italic"], `DEBUG: ${message}`));
}
}
Logger.info("テスト");
Logger.success("テスト");
Logger.warning("テスト");
Logger.error("テスト");
Logger.debug("テスト");
出力した結果になります。
参考:
