A lightweight console and file logger with color-coded output and timestamped entries. Automatically includes the calling file and supports hourly log separation in saved files. https://www.npmjs.com/package/@creations.works/logger
Find a file
2025-05-24 07:22:06 -04:00
src first commit 2025-04-22 20:01:08 -04:00
.gitignore didnt add the ignore? 2025-04-22 20:02:01 -04:00
biome.json some changes 2025-05-24 07:22:06 -04:00
bun.lock first commit 2025-04-22 20:01:08 -04:00
LICENSE some changes 2025-05-24 07:22:06 -04:00
package.json some changes 2025-05-24 07:22:06 -04:00
README.md some changes 2025-05-24 07:22:06 -04:00
tsconfig.json first commit 2025-04-22 20:01:08 -04:00

logger

A lightweight console and file logger with color-coded output and timestamped entries. Automatically includes the calling file and supports hourly log separation in saved files.

Features

  • Singleton logger instance
  • Colored console output
  • Log to file with date-based filenames
  • Hourly separators in saved logs
  • TypeScript-friendly with exported types
  • Supports info, warn, error, and custom log levels

Installation

npm install @creations.works/logger

Or with Bun:

bun add @creations.works/logger

Usage

import { logger } from "@creations.works/logger";

logger.info("This is an info message");
logger.warn("This is a warning", { breakLine: true });
logger.error(new Error("Something went wrong"), { save: true });

logger.custom("[DEBUG]", "main.ts", "Detailed debug message", "34", {
	save: true,
	breakLine: true,
});

API

logger.info(message, options?)

Log an informational message.

logger.warn(message, options?)

Log a warning message.

logger.error(message, options?)

Log an error message or exception.

logger.custom(label, source, message, color, options?)

Log a custom message with a custom tag, source, and ANSI color code.

logger.space()

Prints an empty line to the console.

Options

All logging methods accept an optional object:

  • breakLine (boolean): whether to add a newline after the message in the console
  • save (boolean): whether to write the message to the file log /

Types

type ILogMessagePart = { value: string; color: string };

type ILogMessageParts = {
	level: ILogMessagePart;
	filename: ILogMessagePart;
	readableTimestamp: ILogMessagePart;
	message: ILogMessagePart;
	[key: string]: ILogMessagePart;
};

License

BSD 3-Clause