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

@eklabdev/logger

v1.0.1

Published

A modular and extensible TypeScript logging library

Readme

@eklabdev/logger

A modular and extensible TypeScript logging library with support for multiple channels, log levels, and method decorators.

Features

  • Multiple log levels (DEBUG, INFO, WARN, ERROR, FATAL)
  • Support for both synchronous and asynchronous logging channels
  • Built-in console and file channels
  • TypeScript decorators for automatic method logging
  • Extensible channel system for custom logging destinations
  • Metadata support for contextual logging
  • TypeScript 5 compatible

Installation

npm install @eklabdev/logger

Basic Usage

import { Logger, ConsoleChannel, LogLevel } from '@eklabdev/logger';

// Create a logger with a console channel
const logger = new Logger('AppLogger')
  .addChannel(new ConsoleChannel());

// Basic logging
logger.debug('Debug message');
logger.info('Info message');
logger.warn('Warning message', { source: 'system' });
logger.error('Error occurred', new Error('Something went wrong'));

// Logging with metadata
logger.info('User logged in', { userId: '123' }, { sessionId: 'abc' });

Using File Channel

import { Logger, FileChannel } from '@eklabdev/logger';

const logger = new Logger('AppLogger')
  .addChannel(new FileChannel('/path/to/logs/app.log', 'FileChannel', {
    append: true,
    encoding: 'utf8'
  }));

// Logs will be written to the file
logger.info('Application started');

Using Decorators

import { Logger, ConsoleChannel, LogClass, LogSync, LogAsync } from '@eklabdev/logger';

const logger = new Logger('UserService')
  .addChannel(new ConsoleChannel());

@LogClass(logger, { service: 'UserService' })
class UserService {
  @LogSync({
    logStart: true,
    logFinish: true,
    metadata: { operation: 'getUser' }
  })
  getUser(id: string) {
    return { id, name: 'John Doe' };
  }

  @LogAsync({
    logStart: true,
    logFinish: true,
    logError: true,
    errorHandler: (error) => ({ errorCode: (error as Error).message })
  })
  async updateUser(id: string, data: any): Promise<void> {
    // Async method implementation
    return Promise.resolve();
  }
}

Creating Custom Channels

import { AsyncChannel, LogEntry } from '@eklabdev/logger';

class DatabaseChannel extends AsyncChannel {
  constructor(private dbConnection: any) {
    super('DatabaseChannel');
  }

  protected async writeAsync(entry: LogEntry): Promise<void> {
    await this.dbConnection.logs.insert({
      timestamp: entry.timestamp,
      level: entry.level,
      message: entry.message,
      data: entry.data,
      metadata: entry.metadata
    });
  }
}

// Usage
const logger = new Logger('AppLogger')
  .addChannel(new DatabaseChannel(dbConnection));

API Reference

Logger

The main logger class that manages channels and logging operations.

class Logger {
  constructor(name: string, options?: LogOptions);
  addChannel(channel: IChannel): this;
  removeChannel(channelName: string): this;
  setMetadata(metadata: Record<string, any>): this;
  log<T>(level: LogLevel, message: string, data?: T, metadata?: Record<string, any>): void;
  debug<T>(message: string, data?: T, metadata?: Record<string, any>): void;
  info<T>(message: string, data?: T, metadata?: Record<string, any>): void;
  warn<T>(message: string, data?: T, metadata?: Record<string, any>): void;
  error<T>(message: string, data?: T, metadata?: Record<string, any>): void;
  fatal<T>(message: string, data?: T, metadata?: Record<string, any>): void;
}

Channels

ConsoleChannel

Synchronous channel that writes logs to the console.

class ConsoleChannel extends SyncChannel {
  constructor(name?: string, options?: ConsoleChannelOptions);
}

FileChannel

Asynchronous channel that writes logs to a file.

class FileChannel extends AsyncChannel {
  constructor(filePath: string, name?: string, options?: FileChannelOptions);
  initialize(): Promise<void>;
  close(): Promise<void>;
}

Decorators

@LogClass

Class decorator that attaches a logger instance to the class.

function LogClass(logger: Logger, metadata?: Record<string, any>);

@LogSync

Method decorator for synchronous methods.

function LogSync(options?: LogOptions);

@LogAsync

Method decorator for asynchronous methods.

function LogAsync(options?: LogOptions);

Contributing

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

License

MIT