Learn about Toolkitify Logger.
What is Logger?
Toolkitify Logger is a lightweight, flexible logging utility designed to help developers debug and monitor their code efficiently. It improves the default logging of programming languages by adding features like frequency control, maximum uses, colored output, and log levels, all while keeping resource usage low.
Toolkitify is an open-source project, meaning itβs free to use and doesnβt require an account.
Logger Features
- Log Levels:
DEBUG, INFO, WARN, ERROR.
- Colored Output: Supports standard colors (
red, green, yellow, blue, magenta, cyan, white) or custom hex colors.
- Frequency: Log messages only every N occurrences.
- Max Uses: Limit how many times a message can be logged globally or per message.
- Easy Integration: Works out-of-the-box with any JavaScript/TypeScript project.
Usage Example
import { Logger } from "toolkitify/logger";
const logger = new Logger({
level: "DEBUG",
frequency: 1,
maxUses: Infinity
});
logger.debug("Debug message");
logger.info("Info message");
for (let i = 1; i <= 6; i++) {
logger.info("Freq message", { frequency: 3 });
}
logger.warn("Warning in red", { color: "red" });
logger.info("Info in green", { color: "green" });
const limitedLogger = new Logger({ maxUses: 2 });
limitedLogger.info("Limited message");
limitedLogger.info("Limited message");
limitedLogger.info("Limited message");
limitedLogger.info("Single-use message", { maxUses: 1 });
limitedLogger.info("Single-use message", { maxUses: 1 });
How It Works
- Level Filtering: Messages below the configured log level are ignored.
- Frequency Control: Only logs every Nth occurrence of a message.
- Max Uses: Ensures that logs are not repeatedly spammed.
- Color Formatting: Adds colored output to make logs easier to read in the console.
Toolkitify Logger is perfect for developers looking for a clean, configurable, and colorful logging system without adding heavy dependencies to their projects.
Interfaces
Logger Methods
Logging Function
| Parameter | Type | Required | Description |
|---|
message | String | β
| Message to log |
options | LogOptions | β | Options for the log message |
LogOptions
| Parameter | Type | Required | Description |
|---|
frequency | Number | β | Log only every N occurrences (default 1) |
color | Color | β | Color of the log message (named or hex) |
maxUses | Number | β | Maximum times this message should be logged |
Logger Constructor Options
| Parameter | Type | Required | Description |
|---|
level | LogLevel | β | Minimum log level (DEBUG | INFO | WARN | ERROR) |
frequency | Number | β | Default log frequency (logs every N messages) |
maxUses | Number | β | Default maximum uses for all messages |
flushInterval | Number | β | Default flush interval in milliseconds |
asyncFlush | Boolean | β | Default async flush |
LogLevel
| Value | Description |
|---|
DEBUG | Used for detailed debug messages |
INFO | General information messages |
WARN | Warnings that require attention |
ERROR | Error messages indicating failures |
Color
| Value | Description |
|---|
green | Standard green text |
red | Standard red text |
yellow | Standard yellow text |
blue | Standard blue text |
magenta | Standard magenta text |
cyan | Standard cyan text |
white | Standard white text |
#RRGGBB | Any hex color, e.g., #ff00ff |