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

als-logger

v3.0.0

Published

Flexible and powerful logging utility for Node.js applications.

Downloads

14

Readme

ALS Logger (Version 3.0)

als-logger is a flexible and powerful logging utility for Node.js applications. It supports customizable log formats, file management, error handling, and much more.

Features

  • Customizable Logging Levels: Easily log different message types like log, warn, and error.
  • File Management: Automatically rotates log files and removes old entries based on age.
  • Error Handling: Captures uncaught exceptions and unhandled promise rejections.

Installation

Install the package via npm:

npm install als-logger

Usage

Basic Usage

Create an instance of the Logger and start logging messages.

const Logger = require('als-logger');

const logger = new Logger('/path/to/logs');

// Log messages of various types
logger.log('some msg','This is a log message.');
logger.warn('some msg','This is a warning.');
logger.error('some msg','This is an error.');

API

const logger = new Logger(dirPath:String,options={}:Object):instanceof Logger
logger.log(...msgs):Promise
logger.warn(...msgs):Promise
logger.error(...msgs):Promise
add(type:String, msgs:Array):Promise
logger.close():undefined

logger.report:instanceof LoggerReport
logger.report.limit(limit:Number):instanceof LoggerReport
logger.report.days(days:Number):instanceof LoggerReport
logger.report.type(...types:String):instanceof LoggerReport
logger.report.get(query:Object):Promise=>array

Options and validation

  • dirPath - dir path for logs
    • Default:undefined
    • Validation: throwing error if dirPath no type of string
      • if folder not exists, it will be created
    • Limits: You can't create two instances of Logger with same directory (throwing error)
  • options
    • Default: { timeout = 0, types = ['log', 'warn', 'error'], dev = false, errorFn = console, maxDays = 10 }
  • options.timeout - debounce timeout to write logs
    • Default 0
    • Validate: throwing error if timeout no positive number
  • options.types - logger methods from types
    • Default:['log', 'warn', 'error']
    • Validation: throwing error if types not array
      • Filtering array's item which not type of string
  • options.dev - developement mode. Using errorFn, instead writing logs.
    • Default:false
    • Validation: throwing error if dev not type of Boolean
  • options.errorFn
    • Default:console
    • Validation: throwing error if errorFn is not and object or don't have method from options.types
  • options.maxDays - maxDays to save in cache
    • Default:10
    • Validation: throwing error if maxDays no positive number

Report

logger.report
.limit(20) // limit for 20 logs
.days(5) // return up to 5 last days
.types('warn','error') // return only types of warn and error
.get() // return Promise which resolved to  [...,{ timestamp, type, msgs }]