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

dimoba-log

v1.0.8

Published

A module that contains log models and method

Downloads

2

Readme

dimoba-log

A module in TypeScript for structuring logs.

Getting started

Installing

npm install dimoba-log --save

Usage

import { Log, LogRequest, LogLevel, LogQueue, LogQueueConfig } from 'dimoba-log';

Log model uses a simple syntax to define a log:

class Log {
  level: number; // See LogLevel model below for further detail
  date: number; // In millisecond
  message: string; // Log message itself
}

LogLevel enum defines an attributed number for each log level:

enum class LogLevel {
  Debug = 0, 
  Info,
  Warn, 
  Error
}

LogRequest model contains a list of Log generated as well as few information about the user who sent his error report:

class LogRequest {
  appVersion: string; // App version
  token: string; // User token
  issues?: string[]; // A list of issue selected by user 
  otherIssue?: string; // Another issue specified by user
  logs: Log[]; // Array of Log
}

LogQueue

A class which manages a log queue.

class LogQueue {
  // Takes a Log as parameter and adds it in Log queue.
  add(log: Log)
  // Stringify and returns a Log queue where each entry has its log level converted in string to be more readable
  toString(): string
  static filter(logs: Log[]): Log[]
  static sort(logs: Logs): Log[]
}

Define a LogQueueConfig in the constructor to set the limit of queue.

class LogQueueConfig {
  maxLines: number
  maxCharactersPerLine: number
}
const logQueue = new LogQueue(new LogQueueConfig({maxLines: 500, maxCharactersPerLine: 400}))

Any values not specified will be set to the defaults below:

{
  maxLines: 10000,
  maxCharactersPerLine: 1000
}

Static methods

LogQueue has two static methods that could be used to manage your own Log array:

LogQueue.filter(logs: Log[]) method takes an array of Log as parameter and checks if it contains malformed entries. An error is thrown if any element is null or its date is null or undefined

try {
  logs = LogQueue.filter(logs)
} catch (e) {
  // Catch your error
}

LogQueue.sort(logs: Log[]) method takes an array of Log as parameter and sort it by date.

try {
  logs = LogQueue.sort(logs)
} catch (e) {
 // Catch your error
}

N.B.: sort() method calls filter() first before to check the malformed entries

Author

Dimoba