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

sugoi-logger

v1.0.0-alpha.3

Published

Javascript logging module with support for syslog RFC5424

Downloads

6

Readme

sugoi-logger

📝 Javascript logging module with support for syslog RFC5424 and json log format.

Features

  • Supports syslog and json logging format.
  • Custom format is also supported with options.formatter
  • Adds an unique requestId to log messages. Can be used with express APIs.
  • Adds info about line number and filename to log messages.
  • Logging levels: {emergency|alert|critical|error|warning|notice|info|debug}
  • Supports custom transports. By default it prints messages as stdout/stderr

Installation

npm install sugoi-logger --save

Usage

Set LOGGING_TYPE env variable to set logType. Logtype defaults to SYSLOG if not set.

export LOGGING_TYPE=JSON

Create your own logger and export it:

// main.js
import { Logger, setRequestId } from 'logging';

// create logger instance 
export const logger = new Logger({
    application: 'my-application' // custom application name
});

// Use setRequestId function to persist messageId in CLS within the callback function. Logger will pick up the context from this.
// example as express middleware
app.use((_req, _res, next) => setRequestId(next));

// example with other functions
function doSomething() {
   setRequestId(() => {
      doingSomething();
   })
}

// example with custom messageId
app.use((req, _res, next) => setRequestId(next, req.headers.messageId));

Use the logger instance:

// routes/list.js
import { logger } from './main';
import { v4 as uuidv4 } from 'uuid';

function getList () {
    // log the message. by default it will format messages into syslog RFC5424 and prints it in stdout
    logger.info('log message');

    // usage with structured data (can be set in data field)
    logger.error('log message', { meta: { user: { id: '1234' } } });
}

Options

Syntax

logger.info('log message', { key: value })

| key | value | note | |------------|------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------| | data | { [ sdId : string ] : Record < string | number , any > } | additional properties for this logger. If LOGGING_TYPE is syslog, this will be printed as structured data. | | context | { [key:string]: any } | context of this log message in key-value format. Can be used in custom formatter | | transports | (( arg : FormatterOptions ) => void)[] | set of logging transport functions | | formatter | ( arg : FormatterOptions ) => string | formatter function for log message |