Skip to main content

logToConsole

Logs a message to the console with a specified log level and optionally saves it to a file.

  • import the method
import { logToConsole } from "nodelpers";
  • params
message: any;
options: ILogOptions;

TLogLevel = "default" | "info" | "warn" | "error";

ILogOptions {
level: TLogLevel;
devOnly?: boolean; // Only log in non-production environments
logPath?: string; // File path to save logs
}
  • setup

set NODE_ENV to either production or development in .env file.

NODE_ENV=development
  • usage
logToConsole("Hello World!");
logToConsole("Hello World!", { devOnly: true });
logToConsole("Hello World!", { logPath: "/path/to/logs.txt" });