npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@supercat1337/logger

v1.0.0

Published

A simple logging utility for Node.js applications.

Downloads

56

Readme

Logger

A lightweight and flexible logging library for Node.js applications, providing file-based logging with timestamp formatting and timezone support.

Installation

npm install @supercat1337/logger

Features

  • 📝 Simple file-based logging with different log levels
  • 🕒 Configurable timestamp formatting with timezone support
  • 📁 Automatic log file path conversion utilities
  • 🚀 Promise-based async logging operations
  • 🔧 Customizable output directory and file extensions
  • ✅ TypeScript support with full type definitions

Quick Start

import { Logger } from '@supercat1337/logger';

// Create a logger instance
const logger = new Logger('./app.log');

// Log messages at different levels
await logger.info('Application started');
await logger.warn('Low disk space');
await logger.error('Failed to connect to database');

// Close the logger when done
await logger.close();

API Reference

Logger Class

The main Logger class for writing log messages to files.

Constructor

new Logger(filePath: string, options?: {
    useDate?: boolean;
    timeZone?: any;
})
  • filePath: Path to the log file
  • options.useDate: Whether to include timestamps in log messages (default: true)
  • options.timeZone: Timezone for timestamps

Methods

  • log(message: string, level?: string): Promise<void> - Write a log message with specified level
  • error(message: string): Promise<void> - Write an error message
  • warn(message: string): Promise<void> - Write a warning message
  • info(message: string): Promise<void> - Write an info message
  • close(): Promise<boolean> - Close the logger and wait for pending writes

Utility Functions

convertFilePathToLogFilePath()

Convert a file path to a log file path by appending .log extension.

convertFilePathToLogFilePath(
    filePath: string, 
    suffix?: string, 
    options?: {
        outputDir?: string;
        extension?: string;
    }
): string

Date Formatting Functions

  • formatDate(date: Date, format?: string, timeZone?: string): string - Format a date with custom format and timezone
  • getDateString(timeZone?: string): string - Get current date as YYYY-MM-DD
  • getDateTimeString(timeZone?: string): string - Get current datetime as YYYY-MM-DD HH:MM:SS
  • getDateTimeStringForFileName(timeZone?: string): string - Get datetime for filenames as YYYY-MM-DD_HH-MM-SS
  • getCurrentTimeZone(): string - Get current system timezone

Usage Examples

Basic Logging

import { Logger } from '@supercat1337/logger';

const logger = new Logger('./logs/app.log');

// Log with different levels
await logger.info('User logged in');
await logger.warn('API response slow');
await logger.error('Database connection failed');

// Custom log level
await logger.log('Debug message', 'debug');

With Timezone Configuration

import { Logger } from '@supercat1337/logger';

// Logger with specific timezone
const logger = new Logger('./app.log', {
    useDate: true,
    timeZone: 'America/New_York'
});

await logger.info('Log with New York timezone');

File Path Conversion

import { convertFilePathToLogFilePath } from '@supercat1337/logger';

// Convert source file path to log file path
const logPath = convertFilePathToLogFilePath('/src/app.js');
// Returns: /src/app.js.log

// With custom output directory and suffix
const customLogPath = convertFilePathToLogFilePath(
    '/src/app.js',
    'errors',
    { outputDir: '/logs', extension: '.txt' }
);
// Returns: /logs/app.errors.txt

Date Formatting

import { 
    getDateString, 
    getDateTimeString,
    formatDate 
} from '@supercat1337/logger';

// Get formatted dates
const today = getDateString(); // "2024-01-15"
const now = getDateTimeString(); // "2024-01-15 14:30:45"

// Custom formatting
const customDate = formatDate(
    new Date(), 
    'YYYY/MM/DD HH:mm:ss',
    'Europe/London'
);

Error Handling

The logger handles write errors gracefully:

try {
    await logger.error('Something went wrong');
} catch (err) {
    console.error('Failed to write log:', err);
}

Closing the Logger

Always close the logger to ensure all pending writes are completed:

// In an async context
await logger.close();

// Or with then/catch
logger.close()
    .then(() => console.log('Logger closed'))
    .catch(err => console.error('Error closing logger:', err));

License

MIT