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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@xenral/logpro

v0.4.1

Published

A minimal, structured logging utility for TypeScript projects

Downloads

4

Readme

LogPro

A minimalistic, structured logging utility for TypeScript projects.

Features

  • 🔍 Structured logging - JSON output format for easy parsing and analysis
  • 🔄 Multiple log levels - debug, info, warn, error, and fatal
  • 🧩 Context support - Attach consistent metadata to your logs
  • 🌍 Environment-aware - Automatically adjusts configuration based on environment
  • 🎨 Pretty formatting - Human-readable output with optional colors for development
  • 🔧 Customizable - Easily configurable to match your needs
  • 🌱 Zero dependencies - Core logging with no external dependencies
  • 📲 Optional transports - Extend with transports like Telegram (opt-in only)

Installation

npm install @xenral/logpro

or

yarn add @xenral/logpro

Quick Start

import { logger } from '@xenral/logpro';

// Basic logging
logger.info('Application started');
logger.warn('Connection timeout, retrying...');
logger.error('Failed to connect to database');

// Adding context
logger.info('User logged in', { userId: '123', role: 'admin' });

// Logging errors with stack traces
try {
  throw new Error('Something went wrong');
} catch (error) {
  logger.error('Operation failed', { operation: 'data-import' }, error);
}

Advanced Usage

Creating Named Loggers

import { getLogger } from '@xenral/logpro';

const dbLogger = getLogger('database');
const authLogger = getLogger('auth');

dbLogger.info('Connected to database');
authLogger.warn('Invalid login attempt', { username: 'user123', ip: '192.168.1.1' });

Customizing Log Level

import { getLogger, LogLevel } from '@xenral/logpro';

const logger = getLogger('app')
  .setLevel(LogLevel.DEBUG);

// This will output in development, but not in production
logger.debug('Debugging information');

Changing Output Format

import { getLogger } from '@xenral/logpro';

// JSON format (default in production)
const jsonLogger = getLogger('api')
  .useJsonFormat();

// Pretty format with colors (default in development)
const prettyLogger = getLogger('ui')
  .usePrettyFormat(true);

Creating Child Loggers with Context

import { getLogger } from '@xenral/logpro';

const logger = getLogger('requestHandler');

// Create a child logger for a specific request
function handleRequest(req) {
  const requestLogger = logger.child({
    requestId: req.id,
    path: req.path,
    method: req.method
  });
  
  requestLogger.info('Request received');
  
  // All logs from requestLogger will include the request context
  requestLogger.debug('Processing request');
}

Environment-Aware Logger

import { createEnvLogger } from '@xenral/logpro';

// Automatically configures based on NODE_ENV
const logger = createEnvLogger('app');

// In development: Pretty output with colors, DEBUG level
// In test: Default output, WARN level
// In production: JSON output, INFO level

Sending Logs to Telegram (Optional)

Optionally send important logs directly to a Telegram channel for real-time monitoring:

import { getLogger, LogLevel, TelegramTransport } from '@xenral/logpro';

// First install the required dependency
// npm install node-telegram-bot-api

// Create a logger
const logger = getLogger('app');

// Create a Telegram transport
const telegramTransport = new TelegramTransport({
  token: 'YOUR_TELEGRAM_BOT_TOKEN',
  chatId: 'YOUR_CHAT_ID',
  minLevel: LogLevel.ERROR, // Only send ERROR and FATAL logs
  // Optional: Add a filter for specific logs
  filter: (entry) => entry.context.important === true
});

// Add the transport to the logger
logger.addTransport(telegramTransport);

// Regular logs will go to console only
logger.info('Application started');

// Error logs will go to both console and Telegram
logger.error('Database connection failed', { 
  important: true,
  dbHost: 'production-db-1'
});

To set up the Telegram integration:

  1. Install the optional dependency: npm install node-telegram-bot-api
  2. Create a bot using BotFather and get the token
  3. Add the bot to your channel or group
  4. Get the chat ID (you can use the @username_to_id_bot)
  5. Configure the TelegramTransport with your token and chat ID

API Reference

Log Levels

  • LogLevel.DEBUG - Detailed information for debugging
  • LogLevel.INFO - Informational messages highlighting progress
  • LogLevel.WARN - Potentially harmful situations
  • LogLevel.ERROR - Error events that might still allow the application to continue
  • LogLevel.FATAL - Severe error events that lead to application termination
  • LogLevel.SILENT - Turns off all logging

Core Methods

  • debug(message, context?, error?) - Log at debug level
  • info(message, context?, error?) - Log at info level
  • warn(message, context?, error?) - Log at warn level
  • error(message, context?, error?) - Log at error level
  • fatal(message, context?, error?) - Log at fatal level

Configuration Methods

  • setLevel(level) - Set minimum log level
  • useJsonFormat() - Use JSON output format
  • usePrettyFormat(enableColors?) - Use human-readable output format
  • setFormatter(formatter) - Set custom formatter function
  • child(context) - Create a child logger with additional context

License

MIT