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

infront-logger

v1.1.11

Published

The logger supports both writhing to file and to console.

Downloads

570

Readme

Infront Logger

Logging done right

The logger supports both writhing to file and to console.

npm i @infront/logger

Usage

BaseLogger

const {BaseLogger} = require('infront-logger');  
let options = {};
let logger = new BaseLogger("component1", options);  
logger.log("this is a test message");

HttpLogger (Express Logger)

const {HttpLogger} = require('infront-logger');

const responseInterceptor = (req, res, next) => {
// Save the original response method

const originalSend = res.send;
const originalJSON = res.json;
const originalSendStatus = res.sendStatus;

let responseSent = false;
let startTime = Date.now();

// Override the response method
res.sendStatus = function(status){
try{
    const httpLogger = new HttpLogger();
    if (!responseSent) {
        res.statusCode = status;
        httpLogger.request(req);
        httpLogger.response(res);


        if (status < 400) {
          httpLogger.success();
        } else {
          httpLogger.error("req.sendStatus with error status");
        }
        responseSent = true;
      }
    } catch (err){
      console.error(err);

    }
    return originalSendStatus.call(this, status);
};

res.send = function (body){
try{
const httpLogger = new HttpLogger();
if (!responseSent) {
httpLogger.request(req);
httpLogger.response(res);
httpLogger.body(body);
        if (res.statusCode < 400) {
          httpLogger.success();
        } else {
          httpLogger.error(body.message);
        }
        responseSent = true;
      }
    } catch (err){
      console.error(err);
    }

    // Call the original response method
    return originalSend.call(this, body);
};


res.json = function (body){
try{
const httpLogger = new HttpLogger();
if (!responseSent) {
httpLogger.request(req).response(res).body(body);

        if (res.statusCode < 400) {
          httpLogger.success();
        } else {
          httpLogger.error(body.message);
        }
        responseSent = true;
      }


    } catch (err){
      console.error(err);
    }

    // Call the original response method
    return originalJSON.call(this, body);
};

// Continue processing the request
next();
}

app.use(responseInterceptor);

DatadogLogger

import {DatadogLogger} from 'infront-logger/browser';
let loggerOptions = {
    clientToken: 'YOUR_DATADOG_CLIENT_TOKEN',
    service : "SERVICE_NAME"
}	
let logger = new DatadogLogger(loggerOptions);
logger.log("this is a test message", {prop1: "val1"});

FastifyLogger

MongooseLoggerPlugin

Make sure to use before defining schemas;

const {MongooseLoggerPlugin} = require('infront-logger');
const mongoose = require('mongoose');
let plugin = MongooseLoggerPlugin({console : false, filename : 'db.log'});
mongoose.plugin(plugin);

Loggers

BaseLogger

Methods

  • session(id)
  • log(msg)
  • info(msg)
  • error(err)
  • profile(action, options)
  • profileMem(options)

HttpLogger (extends BaseLogger)

Methods

  • request(req)
  • response(res)
  • body(data)
  • success(req, res, body)
  • error(err)

FastifyLogger (extends BaseLogger)

Methods

  • request(req)
  • response(res)
  • body(data)
  • success(req, res, body)
  • error(err)

options

  • dirname - The directory in which the logs will be created (default: "logs")
  • levels - An object of "level name : hierarchical value"
  • level - default level (default: info)
  • dateFormat : default "YYYY-MM-DD HH:mm:ss:ms"
  • file - boolean - should log to file (default : true)
  • maxFileSize: The maximum file size for a rotating file strategy (default: "30m")
  • maxFiles: The maximum number of files for a rotating file strategy (default: 2)
  • filename - name of the default log file (default: "logs.log")
  • errorFilename - name of the default error log file (default: "error.log")
  • console - boolean - should log to console (default: true)
  • consoleJSON - boolean - print full json to console (default : false)