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

@ecopages/logger

v0.2.1

Published

A lightweight, flexible logging library with color support, timestamps, and timer functionality. This logger supports multiple log levels and allows for easy extension and integration into any project.

Downloads

224

Readme

@ecopages/logger

A lightweight, flexible logging library with color support, timestamps, and timer functionality. This logger supports multiple log levels and allows for easy extension and integration into any project.

Features

  • Multiple Log Levels: Supports INFO, ERROR, WARN, and DEBUG log levels
  • Colored Output: Configurable colors for different log levels in both browser and Node.js environments
  • Timestamps: Optional timestamps with configurable formats
  • Timer Support: Built-in timer functionality for performance measurements
  • Prefixed Messages: Customizable prefix for all log messages
  • Environment Detection: Automatically adapts output format for browser or Node.js environments
  • Extensible: Easy to extend with custom functionality

Installation

npm install @ecopages/logger
# or
yarn add @ecopages/logger
# or
bun add @ecopages/logger

Basic Usage

import { Logger } from "@ecopages/logger";

// Create a basic logger
const logger = new Logger("[my-app]");

// Log messages at different levels
logger.info("This is an informational message");
logger.warn("This is a warning message");
logger.error("This is an error message");
logger.debug("This is a debug message"); // Only shown if debug is enabled

Advanced Configuration

The logger supports various configuration options:

const logger = new Logger("[my-app]", {
  debug: true,              // Enable debug messages
  color: true,             // Enable colored output
  timestamp: true,         // Add timestamps to messages
  timestampFormat: 'full', // Configure timestamp format
  verboseTimer: true,      // Show timer start messages
  colors: {                // Custom colors
    INFO: 'color: purple',
    ERROR: 'color: darkred'
  }
});

Configuration Options

| Option | Type | Default | Description | |--------|------|---------|-------------| | debug | boolean | false | Enable debug level messages | | color | boolean | true | Enable colored output | | timestamp | boolean | false | Add timestamps to messages | | timestampFormat | 'full' | 'time' | 'short' | 'time' | Timestamp format | | verboseTimer | boolean | false | Show timer start messages | | colors | Partial | - | Custom colors for log levels |

Timestamp Formats

  • full: YYYY-MM-DD HH:mm:ss
  • time: HH:mm:ss
  • short: MM-DD HH:mm:ss

Timer Functionality

// Start a timer
logger.time("operation");

// ... some operations ...

// End the timer and log duration
logger.timeEnd("operation");

Custom Colors

Colors can be customized differently for browser and Node.js environments:

// Browser colors (CSS syntax)
const logger = new Logger("[my-app]", {
  colors: {
    INFO: 'color: purple',
    ERROR: 'color: darkred',
    WARN: 'color: orange',
    DEBUG: 'color: cyan',
    TIMER: 'color: magenta'
  }
});

// Node.js colors (ANSI codes)
const logger = new Logger("[my-app]", {
  colors: {
    INFO: '\x1b[35m',  // Purple
    ERROR: '\x1b[31m', // Red
    WARN: '\x1b[33m',  // Yellow
    DEBUG: '\x1b[36m', // Cyan
    TIMER: '\x1b[35m'  // Magenta
  }
});

Examples

With Timestamps and Colors

const logger = new Logger("[my-app]", { 
  timestamp: true, 
  timestampFormat: 'full' 
});

logger.info("Application started");
// Output: [2024-02-16 15:30:45] [my-app] Application started

With Debug Messages

const logger = new Logger("[my-app]", { debug: true });

logger.debug("Configuration loaded:", { port: 3000 });
// Output: [my-app] Configuration loaded: { port: 3000 }

With Timer

const logger = new Logger("[my-app]", { verboseTimer: true });

logger.time("db-query");
// ... database operation ...
logger.timeEnd("db-query");
// Output: [my-app] db-query: 123.45ms