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
src | ||
.gitignore | ||
biome.json | ||
bun.lock | ||
LICENSE | ||
package.json | ||
README.md | ||
tsconfig.json |
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
, andcustom
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 consolesave
(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;
};