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 🙏

© 2024 – Pkg Stats / Ryan Hefner

@sha3/logger

v1.0.1

Published

Logger library

Downloads

20

Readme

Logger

A TypeScript-based Logger class utilizing the debug library for flexible and configurable logging.

Features

  • Supports multiple log levels: debug, info, warn, error.
  • Configurable logger name and plugins.
  • Easily extensible for additional functionality.

Installation

npm install @sha3/logger

Usage

Importing the Logger

import Logger, { LoggerType, LoggerConfig, LoggerPluginConfig } from '@sha3/logger';

Creating a Logger Instance

You can create a logger instance with or without configuration:

Without Configuration

const logger = new Logger();

With Configuration

const config: LoggerConfig = {
  loggerName: 'myLogger',
  plugins: [{ name: 'plugin1', options: {} }]
};

const logger = new Logger(config);

Logging Messages

logger.debug('This is a debug message');
logger.info('This is an info message');
logger.warn('This is a warning message');
logger.error('This is an error message');

Configuration

LoggerConfig

  • loggerName: A string representing the base name for the logger.
  • plugins: An optional array of plugins with their configurations.

LoggerPluginConfig

  • name: The name of the plugin.
  • options: Configuration options for the plugin.

LoggerType

Defines the types of log levels available:

  • debug
  • info
  • warn
  • error

Code Overview

Imports

External dependencies:

import createDebug, { Debugger } from 'debug';

Internal dependencies:

import CONFIG from '../config';

Types

Defines types for the logger:

export type LoggerType = 'debug' | 'info' | 'warn' | 'error';
export type LoggerPluginConfig = { name: string; options: any };
export type LoggerConfig = { loggerName: string | null; plugins?: LoggerPluginConfig[] };

Logger Class

Private Attributes

  • baseLoggerName: The base name for the logger from the configuration.
  • config: Configuration for the logger.
  • loggersInstances: Instances of the logger for different log levels.

Private Methods

  • getLoggerByLevel(loggerName: string | null, level: LoggerType): Debugger: Creates a logger instance for a specific level.
  • runPlugins(loggerType: LoggerType): Executes configured plugins (currently a placeholder).

Constructor

Initializes the logger with optional configuration.

Public Methods

  • debug(value: string): Logs a debug message.
  • info(value: string): Logs an info message.
  • warn(value: string): Logs a warning message.
  • error(value: string): Logs an error message.

Environment Configuration

The BASE_LOGGER_NAME variable is a crucial part of the logger configuration. It is read from the environment variables to provide a base name for all loggers. This allows for consistent and configurable naming across different environments and deployments.

To set this variable, you can include it in your environment configuration file (e.g., .env):

BASE_LOGGER_NAME=my_app_name

TODO

  • Implement the runPlugins method to handle logger plugins.

License

MIT