@1blckhrt/logger
v1.0.1
Published
Simple logger written in TypeScript
Readme
Logger
A simple logger class for Node.js that supports different log levels, optional colors, and file logging.
Installation
npm install @1blckhrt/loggerUsage
import { Logger } from "@1blckhrt/logger";
const logger = new Logger({
enableColors: true,
logFilePath: "./logs/app.log",
logToFile: true,
prefix: "MyApp",
useTimestamps: true,
});Logger Options
enableColors(boolean): Enable or disable colored output in the terminal. Default isfalse.logFilePath(string): Path to the log file. Default isnull.logToFile(boolean): Enable or disable logging to a file. Default isfalse.prefix(string): A prefix to add to each log message. Default is an empty string.useTimestamps(boolean): Enable or disable timestamps in log messages. Default isfalse.
Methods
debug(message: string): void
Logs a debug message.
info(message: string): void
Logs an info message.
success(message: string): void
Logs a success message.
warn(message: string): void
Logs a warning message.
error(message: Error | string): void
Logs an error message.
Example
const logger = new Logger({
enableColors: true,
logFilePath: "./logs/app.log",
logToFile: true,
prefix: "MyApp",
useTimestamps: true,
});
logger.debug("Debugging...");
logger.info("Information...");
logger.success("Success!");
logger.warn("Warning!");
logger.error("An error occurred!");