Skip to content

Simple logging module for your typescript application

Notifications You must be signed in to change notification settings

faintastic/Logger

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Logger

A lightweight, elegant TypeScript logger with color-coded output and timestamps.

Features

  • 🎨 Color-coded log levels - Easy visual distinction between log types
  • ⏱️ High-precision timestamps - Millisecond accuracy (HH:MM:SS.mmm)
  • 📦 Multiple log levels - INFO, WARN, ERROR, DEBUG, SUCCESS, FATAL, TRACE
  • 🏷️ Area/Context tags - Organize logs by module or component
  • 🎯 Clean formatting - Tab-aligned columns for consistent readability
  • 💪 TypeScript support - Fully typed for better developer experience

Installation

bun install

Usage

Basic Logging

import log from "./src/index";

// Simple logs
log.info("Server started on port 3000");
log.warn("Memory usage is high");
log.error("Database connection failed");
log.debug("Debugging information");
log.success("Task completed successfully");
log.fatal("Critical system failure");
log.trace("Detailed trace information");

Logging with Area/Context

// Logs with categorized areas
log.info("Order confirmed: order_789", "orders");
log.warn("Stripe API slow response: 145ms", "payments");
log.error("Database connection failed", "database");
log.debug("Calling Stripe API, attempt 1", "payments");
log.success("Payment successful, charge_ch_abc", "payments");
log.fatal("Critical system failure", "system");
log.trace("Variable value: 42", "debugger");

Advanced Usage

// Using the base log method with custom level
log.log({ 
  level: "info", 
  message: "Custom log message", 
  area: "custom-module" 
});

Output Example

08:45:54.564    INFO     [orders] Order confirmed: order_789
08:45:54.566    WARN     [payments] Stripe API slow response: 145ms
08:45:54.566    DEBUG    [payments] Calling Stripe API, attempt 1
08:45:54.567    ERROR    [database] Connection timeout
08:45:54.568    SUCCESS  [payments] Payment successful, charge_ch_abc

Log Levels

Level Color Use Case
INFO Cyan General information and status updates
WARN Yellow Warning messages and potential issues
ERROR Red Error messages and failures
DEBUG Green Debug information during development
SUCCESS Green Successful operations
FATAL Red/Bold Critical errors requiring immediate attention
TRACE Magenta Detailed trace information for debugging

API Reference

Methods

log.info(message: string, area?: string): void

Log an informational message.

log.warn(message: string, area?: string): void

Log a warning message.

log.error(message: string, area?: string): void

Log an error message.

log.debug(message: string, area?: string): void

Log a debug message.

log.success(message: string, area?: string): void

Log a success message.

log.fatal(message: string, area?: string): void

Log a fatal error message with emphasized styling.

log.trace(message: string, area?: string): void

Log a trace message for detailed debugging.

log.log({ level, message, area }): void

Base logging method with custom log level.

Parameters:

  • level - The log level type (info, warn, error, debug, success, fatal, trace)
  • message - The message to log
  • area - Optional area/context to categorize the log

Development

Run Tests

bun run test/index.ts

Build

bun build src/index.ts --outdir ./dist

Dependencies

  • chalk - Terminal string styling

License

MIT

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

About

Simple logging module for your typescript application

Resources

Stars

Watchers

Forks

Packages

No packages published