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

@rjnapp/dyno-logging

v0.0.1-rc.3

Published

error-reporting and logging app, it allows console logging, file logging and remote logging

Downloads

38

Readme

dyno-logging

error-reporting and logging app, it allows console logging, file logging and remote logging

Overview

This package provides a flexible and customizable logging solution for TypeScript applications. It includes a Logger class that implements the ILogger interface, allowing you to log messages at various levels with configurable options.

Features

  • Configurable Log Levels: Supports multiple log levels including TRACE, DEBUG, INFO, WARN, ERROR, CRITICAL, and FATAL.
  • Customizable Output: Log messages can be formatted and written to various transports.
  • Namespace Support: Categorize logs using namespaces.
  • Flexible Options: Customize logging behavior with various options.

Installation

To install the package, use npm:

npm install @rjnapp/dyno-logging

Or with Yarn:

yarn add @rjnapp/dyno-logging

Usage

Importing

To use the logger, import it into your TypeScript file:

import { getLogger, LogLevel, Options } from '@rjnapp/dyno-logging'

Creating a Logger Instance

const options: Options = {
  minLevel: LogLevel.DEBUG,  // Minimum log level to be output
  messageKey: 'msg',         // Key used for log messages
  formatLevel: (level, levelString) => ({ level: levelString }),
  formatContent: (content) => JSON.stringify(content),
  timestamp: () => new Date().toISOString(),
};

const logger = getLogger('my-namespace', options);

Logging Messages

Use the logger instance to log messages at different levels:

logger.fatal('A fatal error occurred', { sessionId: 12345 })
logger.error('An error occurred')
logger.warn('A warning message')
logger.info('Informational message')
logger.debug('Debugging information')
logger.trace('Trace message')
logger.critical('A critical issue')

Options

  • minLevel: The minimum log level to output. Logs below this level will be ignored. Defaults to LogLevel.INFO.

  • messageKey: The key used to represent the log message. Defaults to 'msg'.

  • formatLevel(level: LogLevel, levelString: string): { level: string }: Function to format the log level.

  • formatContent(content: Payload): string: Function to format the log content.

  • timestamp() => string: Function to generate a timestamp for the log entry.

API

getLogger(namespace: string, options?: Options): ILogger

Returns a logger instance with the specified namespace and options.

Parameters:

  • namespace: The namespace for the logger.
  • options: Optional configuration options for the logger.

Returns:

  • An instance of ILogger.

Logger Class

The Logger class implements the ILogger interface with methods to log messages at various levels:

  • fatal(message: string, meta?: MetaData): void
  • error(message: string, meta?: MetaData): void
  • warn(message: string, meta?: MetaData): void
  • info(message: string, meta?: MetaData): void
  • debug(message: string, meta?: MetaData): void
  • trace(message: string, meta?: MetaData): void
  • critical(message: string, meta?: MetaData): void

Parameters for logging methods:

  • message: The message to log.
  • meta: Optional metadata to include in the log.

Contributing

We welcome contributions to this project. Please read our CONTRIBUTING.md file for guidelines on how to contribute.