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

loggerfy

v1.1.4

Published

Loggerfy is a lightweight and customizable logging library designed to provide structured logs with rich metadata. It simplifies the process of logging errors, warnings, and information while ensuring consistency across your application.

Readme

Loggerfy

A simple and structured logging library for Node.js applications

What is Loggerfy?

Loggerfy is a lightweight library that helps you create structured logs with a consistent format. Perfect for applications that need an organized and easy-to-implement logging system.

Quick Installation

npm install loggerfy

Quick Start Guide

1. Import the library

// CommonJS
const { Loggerfy } = require('loggerfy');

// ES Modules
import { Loggerfy } from 'loggerfy';

2. Create a logger and use it

// Create an instance
const logger = new Loggerfy();

// Log an error
logger.error()
  .setCode('AUTH_001')
  .setMessage('User authentication failed')
  .setDetail('Invalid credentials provided')
  .setMetadata({ userId: 123 })
  .write();

Log Levels

Loggerfy offers three logging levels:

// Information
logger.info()
  .setCode('APP_001')
  .setMessage('Application started')
  .setDetail('Server listening on port 3000')
  .write();

// Warning
logger.warn()
  .setCode('CONFIG_001')
  .setMessage('Using default configuration')
  .setDetail('Configuration file not found')
  .write();

// Error
logger.error()
  .setCode('DB_001')
  .setMessage('Database connection error')
  .setDetail('Timeout after 30 seconds')
  .write();

Available Methods

| Method | Description | Required? | |--------|-------------|-----------| | setCode(code) | Sets a unique code for the log entry | Yes | | setMessage(message) | Sets the main message | Yes | | setDetail(detail) | Adds additional details | Yes | | setMetadata(object) | Adds contextual data | No | | write() | Writes the log to the console | Yes* | | getLog() | Returns the log as a JSON string without printing | Yes* |

*Either write() or getLog() must be called to complete the logging operation.

Getting Log as String

If you need the log as a string instead of printing it to the console:

// Get log as JSON string
const logString = logger.error()
  .setCode('AUTH_001')
  .setMessage('User authentication failed')
  .setDetail('Invalid credentials provided')
  .setMetadata({ userId: 123 })
  .getLog();

// Now you can use the string however you want
sendToExternalService(logString);

Output Format

All logs are generated in JSON format:

{
  "timestamp": "2023-11-15T14:30:45.123Z",
  "id": "550e8400-e29b-41d4-a716-446655440000",
  "code": "AUTH_001",
  "message": "User authentication failed",
  "detail": "Invalid credentials provided",
  "payload": { "userId": 123 },
  "level": "ERROR",
  "severity": "ERROR",
  "service": "my-service",
  "environment": "development"
}

Environment Customization

Loggerfy automatically detects the environment and service name:

// Configure environment variables
process.env.SERVICE_NAME = "user-api";
process.env.NODE_ENV = "production";

// Logs will include these values

Implementation with Custom Repository

You can save logs to a custom repository:

import { Loggerfy, LoggerfyRepository, LogEntry } from 'loggerfy';

// Implement your repository
class MyRepository implements LoggerfyRepository {
  async save(log: LogEntry): Promise<void> {
    // Save the log to your database
    await db.logs.insert(log);
  }
}

// Create the logger with your repository
const logger = new Loggerfy(new MyRepository());

// Use it normally
logger.info()
  .setCode('USER_001')
  .setMessage('User created')
  .setDetail('New record in database')
  .write();

Complete Example

import { Loggerfy } from 'loggerfy';

// Environment configuration
process.env.SERVICE_NAME = "payment-service";

const logger = new Loggerfy();

function processPayment(userId, amount) {
  try {
    // Payment processing logic
    
    // Success log
    logger.info()
      .setCode('PAYMENT_001')
      .setMessage('Payment processed successfully')
      .setDetail(`Payment of $${amount} processed`)
      .setMetadata({ userId, amount, timestamp: new Date() })
      .write();
      
    return true;
  } catch (error) {
    // Error log
    logger.error()
      .setCode('PAYMENT_ERR_001')
      .setMessage('Payment processing failed')
      .setDetail(error.message)
      .setMetadata({ userId, amount, errorStack: error.stack })
      .write();
      
    return false;
  }
}

Tips for Effective Use

  1. Use consistent codes - Create a coding system for your logs (e.g., AUTH_001, DB_001)
  2. Include context - Use setMetadata to add relevant information for debugging
  3. Use the appropriate level - Don't log everything as an error, use info and warn appropriately
  4. Choose the right output method - Use write() for console output or getLog() when you need the log as a string

Need Help?

Visit our GitHub repository for more information or to report issues.