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

@zcodeapp/logger

v0.2.11

Published

Logger for application

Downloads

27

Readme

Logger

Logger CI codecov

Overview

This TypeScript Logger class is part of the @zcodeapp packages. It offers a flexible logging system with support for different logging strategies and levels.

Features

  • Singleton pattern with getInstance method.
  • Configurable logging levels (DEBUG, INFO, WARN, ERROR, FATAL).
  • Customizable logging strategies.
  • Prefix addition to log messages.

Installation

Include the Logger class in your TypeScript project:

npm install @zcodeapp/logger

Usage

First, import the Logger class and other necessary interfaces:

import { Logger, ELoggerLevel, ILoggerOptions, LoggerStrategyConsole } from "@zcodeapp/interfaces";

Then, configure and use the logger:

// Configure Logger
const loggerOptions: ILoggerOptions = {
  level: ELoggerLevel.DEBUG,
  strategy: new LoggerStrategyConsole(),
  // other options...
};
const logger = Logger.getInstance(loggerOptions);

// Use Logger
logger.debug("Debug message");
logger.info("Info message");
logger.warn("Warning message");
logger.error("Error message");
logger.fatal("Fatal message");

API Reference

Logger.getInstance(options?: ILoggerOptions): ILogger Returns a singleton instance of the Logger. If options is provided, it configures the logger accordingly.

configure(options: ILoggerOptions): void Configures the logger with the given options.

getOptions(): ILoggerOptions Returns the current logger options.

addPrefix(prefix: string): void Adds a prefix to all log messages.

Logging Methods

  • debug(message: string, params?: any): void
  • info(message: string, params?: any): void
  • warn(message: string, params?: any): void
  • error(message: string, params?: any): void
  • fatal(message: string, params?: any): void

ILoggerOptions Reference

ILoggerOptions is an interface that provides various configuration options for the Logger. Below are the details of each option available:

  • level (ELoggerLevel): This option sets the logging level for the logger. The available levels are:

    • DEBUG: Logs detailed information, primarily useful for developers.
    • INFORMATION: Logs informative messages that highlight the progress of the application.
    • WARNING: Logs potentially harmful situations.
    • ERROR: Logs error events that might still allow the application to continue running.
    • FATAL: Logs severe error events that presumably lead the application to abort.
  • strategy: Defines the strategy for logging messages. This can be an instance of any class that implements the logging strategy, like LoggerStrategyConsole. The strategy default determines how and where the log messages are outputted.

  • prefix (string): An optional string that is prepended to every log message. This is useful for tagging logs with specific identifiers like module names or environment names.

  • newInstance (boolean): An optional flag to create a new logger instance instead of using the singleton pattern. By default, Logger uses a singleton pattern, and this flag is set to false.

Example

Here's an example of how to configure the Logger with ILoggerOptions:

const options: ILoggerOptions = {
  level: ELoggerLevel.DEBUG,
  strategy: new LoggerStrategyConsole(),
  prefix: "MyApp",
  newInstance: true
};

const logger = Logger.getInstance(options);
logger.info("Application started");

License

This project is licensed under the MIT License - see the LICENSE file for details.