0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Node.jsでコンソールの色を変えることができるので試してみた!

Posted at

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("テスト");

出力した結果になります。

20251020-001.png

参考:

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?