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

@c2m/c2m-logger

v1.0.20

Published

1. npm i 2. npm audit 3. npm run build-wim/build-linux 4. cd dist 1. if needed login: npm login --auth-type=web 5. npm publish --otp=[opt number here]

Downloads

128

Readme

C2M Logger

how to deploy:

  1. npm i
  2. npm audit
  3. npm run build-wim/build-linux
  4. cd dist
    1. if needed login: npm login --auth-type=web
  5. npm publish --otp=[opt number here]

General usage

You can unset the logger's formatting when printing to the console by setting an environment variable named NO_LOG_FORMAT to anything truthy (true,non-empty string etc.)

  • Initial setup example (in main.ts):
   import { logger } from "@c2m/c2m-logger";

   /*
      This is the class we're using for the logger's options.
      For most projects, just specifiying the PROJECT_NAME (e.g. PROJECT_NAME: "PCLR")
      and have LOG_LEVEL: process.env.LOG_LEVEL will suffice.
      export class LoggerOptions{
      PROJECT_NAME?: string; Name of the project
      LOG_NAME?: string; Name of the log file (has default according to PROJECT_NAME)
      LOG_DIRNAME?: string; Directory path for log file
      LOG_LEVEL?: string; Level from which we're logging into the file
      LOG_KEEP_FILES?: string; Max number of files we'd like to keep on disk (e.g. 10 will mean we'll rotate out the oldest log file once we hit 10 files)
      LOG_FREQUENCY?: string; How often we want to create a new file (see https://github.com/winstonjs/winston-daily-rotate-file)
      }
    */
   logger.setconfig({
   PROJECT_NAME: <name of the project>,
   LOG_LEVEL: process.env.LOG_LEVEL
   }
  • Usage example:
   import { logger } from "@c2m/c2m-logger";

   //Passing objects to print out
   let item = {name: "honey", price: 50, weight: 0.35}
   logger.info("user wanted to buy item", item);

   //Multiple objects
   let posResponse = buyItem(item);
   logger.info("response from pos for buying item", {posResponse, item});

   //logging errors
   catch(exception){
       //Will automatically extract the error message from the error object
       logger.error(exception);

       // Not yet madnatory but about to be in the future:
       // we want to have an array of errors in each process to streamline
       // the different kind of errors that we see. For example: 
       // import {C2MError} from '@c2m/c2m-logger'
       // errors: Object = {
       //      POS_FAIL_BUY: {code: 50, description: "POS failed on buy item"}
       // }
       //
       //Then when logging an error you should pass the appropriate C2MError object to the logger:

       //POS returned fail on buying item:
       posRes = buyItem(item);
       catch(exception){
           logger.error(exception, {posRes, item}, errors.POS_FAIL_BUY);
       }
   }

ELK setup

ElkLoggerOptions should get the following properties:

  • ELK_HOST - the host of the ELK server
  • ELK_AUTH - the authorization token of the ELK server
  • LOG_LEVEL(optional) - the log level of the logger. default is warn (only logs from level 'warn' and above will be sent to the ELK)

in order to send logs to ELK, you need to configure the logger with the following ElkLoggerOptions:

Usage

import { logger, ElkLoggerOptions } from "@c2m/c2m-logger";

const elkOptions: ElkLoggerOptions = {
  ELK_HOST: <host url from cart settings>,
  ELK_AUTH: <token from cart settings>
};
logger.setELKConfig(elkOptions);


//setup of process metadata so we can filter the logs by
//which process sent this. for example:
const metadata: IElkCartMetadata = {
             processName: "PCLR",
             cartId: this.getConfig('cartID') as string,
             branchId: this.getConfig('branchId') as string
};
logger.setProcessMetadata(metadata);

//Extend the IElkMetadata interface to include whatever metadata you think is relevant
//to the process (for the PCLR, include the cartID and branchId, for the device manager maybe include arduino version etc.)