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

@xplora-uk/logger

v1.2.0

Published

shared logger library based on pino

Downloads

162

Readme

logger

This is a shared (wrapper) logger library, based on pino and console, aiming to consolidate logging features across multiple microservice components.

DEV

Check code inside src.

requirements for dev

  • Node v18+

install, build, test

npm run install
npm run build

# check tests inside src/__tests__
npm run test
npm run test:coverage

Current code coverage:

------------------|---------|----------|---------|---------|-------------------
File              | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s 
------------------|---------|----------|---------|---------|-------------------
All files         |   93.26 |    73.33 |     100 |   97.59 |                   
 src              |     100 |      100 |     100 |     100 |                   
  types.ts        |     100 |      100 |     100 |     100 |                   
 src/logger       |   95.12 |    64.28 |     100 |   94.28 |                   
  constants.ts    |     100 |      100 |     100 |     100 |                   
  factory.ts      |     100 |       75 |     100 |     100 | 16-17             
  index.ts        |     100 |      100 |     100 |     100 |                   
  utils.ts        |    91.3 |       50 |     100 |   88.88 | 24,40             
 src/logger/kinds |    90.9 |    74.07 |     100 |     100 |                   
  console.ts      |   84.21 |    63.63 |     100 |     100 | 13-29             
  pino.ts         |   94.44 |    81.25 |     100 |     100 | 8,22,32           
------------------|---------|----------|---------|---------|-------------------

USAGE

requirements for usage

  • Node v18+

installation

npm i @xplora-uk/logger

configuration

import { newLogger } from '@xplora-uk/logger';
import { randomUUID } from 'crypto';

// configure and load
const app = { app_name: 'my-api', app_version: '1.0.0', env: 'staging' };
const logger = newLogger({ app });
//const logger = newLogger({ app, kind: 'pino', level: 'info' }); //default


// collect info, e.g. get header value using express request
const client_id  = req.get('x-api-key');
const request_id = req.get('x-request-id') || randomUUID();

// log simple messages or objects; date, time will be included
logger.info('POST /my-end-point'); // log string

logger.info({ msg: 'POST /my-end-point', client_id, request_id }); // log object

// or with level check; faster if level is not enabled
if (logger.isLevelEnabled('debug')) {
  // example: extract URL query parameters and request body
  const { query, body } = req;
  const data = { query, body }; // TODO: remove sensitive data points
  logger.debug({ msg: 'POST /end-point', client_id, request_id, data });
}