A logging interface with pluggable transports.
Find a file
2025-12-03 15:31:19 -05:00
src Format and readme udpates 2025-12-03 15:30:44 -05:00
.gitignore Initial commit 2025-11-15 09:51:07 -05:00
biome.json Initial commit 2025-11-15 09:51:07 -05:00
bun.lock Initial commit 2025-11-15 09:51:07 -05:00
LICENSE 2.0.0 2025-12-03 15:15:59 -05:00
Makefile Format and readme udpates 2025-12-03 15:30:44 -05:00
package.json Remove extraneous import directives 2025-12-03 15:31:19 -05:00
README.md Format and readme udpates 2025-12-03 15:30:44 -05:00
tsconfig.json Initial commit 2025-11-15 09:51:07 -05:00

Logger

A logging interface with pluggable transports.

Usage

import { Logger, JSONTransport } from "@endeavorance/logger";

// A logger that prints JSON to the console
const logger = new Logger("MyLogger", {
  transports: [new JSONTransport()],
});

// Log a normal message
logger.log("Hello");

// Log a warning
logger.warn("Step on the crack...");

// Log a unique event (any logging function can also be given a properties hash)
logger.event("New User", {
  name: "Someone",
  age: 200,
});

// Log an error
try {
  throw new Error("oop");
} catch (error) {
  logger.error(error);
}

// Log a fatal error (provide `true` as a third param)
logger.error(new Error("Sun dang ol went and exploded"), {}, true);

// Log a debug message
logger.debug("Debug message!");

// Log a trace message
logger.trace("I'm almost never used!");

Log Options

There are three log types and six log levels, exposed as enums

import { LogLevel, LogType } from "@endeavorance/logger";

Log Types

Type Enum Value Description
Log "log" A stdout log
Event "event" A unique event occurance
Error "error" A stderr log

Log Levels

Level Enum Value Description
Fatal 0 Highest priority - a fatal error
Error 1 A non-fatal error
Warn 2 Not quite an error, but not great
Log 3 A normal informational log
Debug 4 A development-only informational log
Trace 5 Lowest priority - verbose logging

Log Levels by Type

Log Type Possible Levels
Log Warn, Log, Debug, Trace
Error Error, Fatal
Event Log

Transports

The logger can be given any number of transports that imlement the following interface:

interface LoggerTransport {
  log: (log: StdLogInstance) => void;
  error: (err: ErrLogInstance) => void;
  event?: (event: EventLogInstance) => void;
}

The following default transport options are exported from the module:

  • BasicTransport (default)
  • BasicTerminalTransport
  • FancyTerminalTransport
  • JSONTransport