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 🙏

© 2025 – Pkg Stats / Ryan Hefner

commonlog-gas

v1.1.4

Published

log for gas-chain implement from commonlog-kb

Readme

Example commonlog-kb

config

let conf = {};
conf.projectName = 'PROJECT_NAME';  //project name

//Stream log server
conf.logStream = {};
conf.logStream.host = 'xx.xx.xx.xx';
conf.logStream.port = 80;
conf.logStream.maxQueueSize = 10000; //maxQueueSize

//Enable appLog
conf.log = {};
conf.log.time = 15;  //Minute
conf.log.size = null;   //maxsize per file, K
conf.log.path = './appLogPath/';  //path file
conf.log.level = 'debug'; //debug,info,warn,error
conf.log.console = false; 
conf.log.file = true;
conf.log.stream = false; //Stream to tcp server //needs conf.logStream
conf.log.autoAddResBody = true; //default  true
conf.log.format = 'json'; //json, pipe //default json

//Enable summaryLog
conf.summary = {};
conf.summary.time = 15;
conf.summary.size = null;   //maxsize per file, K
conf.summary.path = './summaryPath/';
conf.summary.console = false;
conf.summary.file = true;
conf.summary.stream = false; //Stream to tcp server //needs conf.logStream
conf.summary.format = 'json'; //write summaryLog format "json" OR "pipe" //default json

//Enable detail
conf.detail = {};
conf.detail.time = 15;
conf.detail.size = null;   //maxsize per file, K
conf.detail.path = './detailPath/';
conf.detail.console = false;
conf.detail.file = true;
conf.detail.stream = false; //Stream to tcp server //needs conf.logStream
conf.detail.rawData = true; //true == show raw data

//Enable stat
conf.stat={};
conf.stat.time = 15;
conf.stat.size = null;   //maxsize per file, K
conf.stat.path = './statPath/';
conf.stat.mode = 0; //0 == :memory:, 1== file
conf.stat.pathDB = undefined; //optional, "Folder" path DB store
conf.stat.statInterval = 15;
conf.stat.console = false;
conf.stat.file = true;
conf.stat.stream = false; //Stream to tcp server //needs conf.logStream
conf.stat.flush = false; //true == enable flush stat
conf.stat.format = 'json'; //json, pipe //default json
//conf.stat.process  => String | Array
conf.stat.process = '/path/that/contain/data'
//OR
conf.stat.process = [{
  "name":"stat_name_a",
  "threshold": 3,
  "severity":"critical" //critical, major
},{
  "name":"stat_name_b",
  "threshold": 1
}]; 

//Enable alarm
conf.alarm = {};
conf.alarm.time = 15;
conf.alarm.size = null;
conf.alarm.path = './alarmPath/';
conf.alarm.console = false;
conf.alarm.file = true;
//conf.alarm.process  => String | Array
conf.alarm.process = '/path/that/contain/data'
//OR
conf.alarm.process = [{
  "id": 1,
  "name":"stat_name_a"
}]; 

init log with config (call once)

Please calli init() after lasted middleware

//simple
let logg = require('commonlog-kb').init(conf);

//integrate with express
let app = express();
let logg = require('commonlog-kb').init(conf, app);

logg.sessionID = (req,res) =>{
  return 'how to find session'
};

Check log already init

let alreadyInit = logg.ready();

Example appLog

logg.debug('without session');
logg.debug('session', 'text to log');
logg.debug('session', {foo:'bar'},['foo','bar']);

logg.info('without session');
logg.info('session', 'text to log');
logg.info('session', {foo:'bar'},['foo','bar']);

logg.warn('without session');
logg.warn('session', 'text to log');
logg.warn('session', {foo:'bar'},['foo','bar']);

logg.error('without session');
logg.error('session', 'text to log');
logg.error('session', {foo:'bar'},['foo','bar']);
  • example data (conf.log.format="pipe")
20190410 16:09:38.289|DESKTOP-E0NGPUA|PROJECT_NAME|0||debug|without session
20190410 16:09:38.290|DESKTOP-E0NGPUA|PROJECT_NAME|0|session|debug|text to log
20190410 16:09:38.290|DESKTOP-E0NGPUA|PROJECT_NAME|0|session|debug|{"foo":"bar"} ["foo","bar"]
20190410 16:09:38.291|DESKTOP-E0NGPUA|PROJECT_NAME|0||info|without session
20190410 16:09:38.291|DESKTOP-E0NGPUA|PROJECT_NAME|0|session|info|text to log
20190410 16:09:38.291|DESKTOP-E0NGPUA|PROJECT_NAME|0|session|info|{"foo":"bar"} ["foo","bar"]
20190410 16:09:38.291|DESKTOP-E0NGPUA|PROJECT_NAME|0||warn|without session
20190410 16:09:38.291|DESKTOP-E0NGPUA|PROJECT_NAME|0|session|warn|text to log
20190410 16:09:38.291|DESKTOP-E0NGPUA|PROJECT_NAME|0|session|warn|{"foo":"bar"} ["foo","bar"]
20190410 16:09:38.291|DESKTOP-E0NGPUA|PROJECT_NAME|0||error|without session
20190410 16:09:38.291|DESKTOP-E0NGPUA|PROJECT_NAME|0|session|error|text to log
20190410 16:09:38.291|DESKTOP-E0NGPUA|PROJECT_NAME|0|session|error|{"foo":"bar"} ["foo","bar"]
  • example data (conf.log.format="json")
{"LogType":"App","Host":"DESKTOP-E0NGPUA","AppName":"PROJECT_NAME","Instance":"0","Session":"","InputTimeStamp":"20190826 16:01:21.715","Level":"debug","Message":"without session"}
{"LogType":"App","Host":"DESKTOP-E0NGPUA","AppName":"PROJECT_NAME","Instance":"0","Session":"session","InputTimeStamp":"20190826 16:01:21.721","Level":"debug","Message":"text to log"}
{"LogType":"App","Host":"DESKTOP-E0NGPUA","AppName":"PROJECT_NAME","Instance":"0","Session":"session","InputTimeStamp":"20190826 16:01:21.722","Level":"debug","Message":[{"foo":"bar"},["foo","bar"]]}

{"LogType":"App","Host":"DESKTOP-E0NGPUA","AppName":"PROJECT_NAME","Instance":"0","Session":"","InputTimeStamp":"20190826 16:01:21.733","Level":"info","Message":"without session"}
{"LogType":"App","Host":"DESKTOP-E0NGPUA","AppName":"PROJECT_NAME","Instance":"0","Session":"session","InputTimeStamp":"20190826 16:01:21.735","Level":"info","Message":"text to log"}
{"LogType":"App","Host":"DESKTOP-E0NGPUA","AppName":"PROJECT_NAME","Instance":"0","Session":"session","InputTimeStamp":"20190826 16:01:21.736","Level":"info","Message":[{"foo":"bar"},["foo","bar"]]}

{"LogType":"App","Host":"DESKTOP-E0NGPUA","AppName":"PROJECT_NAME","Instance":"0","Session":"","InputTimeStamp":"20190826 16:01:21.747","Level":"warn","Message":"without session"}
{"LogType":"App","Host":"DESKTOP-E0NGPUA","AppName":"PROJECT_NAME","Instance":"0","Session":"session","InputTimeStamp":"20190826 16:01:21.749","Level":"warn","Message":"text to log"}
{"LogType":"App","Host":"DESKTOP-E0NGPUA","AppName":"PROJECT_NAME","Instance":"0","Session":"session","InputTimeStamp":"20190826 16:01:21.750","Level":"warn","Message":[{"foo":"bar"},["foo","bar"]]}

{"LogType":"App","Host":"DESKTOP-E0NGPUA","AppName":"PROJECT_NAME","Instance":"0","Session":"","InputTimeStamp":"20190826 16:01:21.751","Level":"error","Message":"without session"}
{"LogType":"App","Host":"DESKTOP-E0NGPUA","AppName":"PROJECT_NAME","Instance":"0","Session":"session","InputTimeStamp":"20190826 16:01:21.752","Level":"error","Message":"text to log"}
{"LogType":"App","Host":"DESKTOP-E0NGPUA","AppName":"PROJECT_NAME","Instance":"0","Session":"session","InputTimeStamp":"20190826 16:01:21.753","Level":"error","Message":[{"foo":"bar"},["foo","bar"]]}

Example stat

logg.stat('recv command a');
logg.stat('recv command a');
  • example app log (conf.log.format="pipe")
TIMESTAMP|HOSTNAME|STATNAME|COUNTER
2019-04-10 11:10:04.000|DESKTOP-E0NGPUA|recv command a|2
END
  • example app log (conf.log.format="json")
{"LogType":"Stat","Host":"DESKTOP-E0NGPUA","AppName":"PROJECT_NAME","Instance":"0","TimeStamp":"2019-08-26 16:18:00.000","StatName":"recv command a","StatCount":2}

Example alarm

  • example alarm
2019-04-10 12:20:34.000|DESKTOP-E0NGPUA|major|id|stat_name_b[1:2]

Force flush stat

http://IP:PORT/flushStat

Example summary

//CREATE summaryLog
var s1 = logg.summary('session1', 'initInvoke', 'cmd', 'identity');
//CREATE summaryLog without initInvoke parameter
var s1 = logg.summary('session1', undefined, 'cmd', 'identity');

//OPTIONAL add field
s1.addField('Field_1','value');
s1.addField('Field_1',{'example':'value'});

//OPTIONAL add sequence 
s1.addSuccessBlock('node', 'a', '20000', 'resultDesc');
s1.addSuccessBlock('node', 'b', 'resultCode', 'resultDesc');
s1.addSuccessBlock('node1', 'c', 'resultCode', 'resultDesc');
s1.addSuccessBlock('node1', 'cmd', 'resultCode', 'resultDesc');
s1.addErrorBlock('node1', 'cmd', 'resultCode', 'resultDesc');
//WITE summaryLog (sync)
s1.end('responseResult','responseDesc');
//WITE summaryLog (async)
s1.endASync('responseResult', 'responseDesc','transactionResult ','transactionDesc');

example summary log (pipe format)

20190724 09:31:33.344|DESKTOP-E0NGPUA|PROJECT_NAME|0|20190724 09:31:33.343|session1|initInvoke|cmd|identity|20000|sucesss|[node; a(1); [20000; resultDesc(1)], node; b(1); [resultCode; resultDesc(1)], node1; c(1); [resultCode; resultDesc(1)], node1; cmd(2); [resultCode; resultDesc(2)]]|20190724 09:31:33.344|1 ms

example summary log (json format)

{
  "InputTimeStamp": "20190724 09:32:59.870",
  "Host": "DESKTOP-E0NGPUA",
  "AppName": "PROJECT_NAME",
  "Instance": "0",
  "Session": "session1",
  "InitInvoke": "initInvoke",
  "Scenario": "cmd",
  "Identity": "identity",
  "ResponseResult": "20000",
  "ResponseDesc": "sucesss",
  "Sequences": [
    {
      "Node": "node",
      "Command": "a",
      "result": [
        {
          "Result": "20000",
          "Desc": "resultDesc"
        }
      ]
    },
    {
      "Node": "node",
      "Command": "b",
      "result": [
        {
          "Result": "resultCode",
          "Desc": "resultDesc"
        }
      ]
    },
    {
      "Node": "node1",
      "Command": "c",
      "result": [
        {
          "Result": "resultCode",
          "Desc": "resultDesc"
        }
      ]
    },
    {
      "Node": "node1",
      "Command": "cmd",
      "result": [
        {
          "Result": "resultCode",
          "Desc": "resultDesc"
        }
      ]
    }
  ],
  "EndProcessTimeStamp": "20190724 09:32:59.871",
  "ProcessTime": "1 ms"
}

Example detail

//Type of detailLog
- Input
    req, res, res_timeout, res_error
- Output
    req, res, req_retry_$COUNT/$MAX_COUNT(EX. req_retry_1/2)

//CREATE detailLog
var ddd = logg.detail('session1', 'initInvoke','cmd', 'identity');
//CREATE detailLog without initInvoke parameter
var ddd = logg.detail('session1', undefined, 'cmd', 'identity');

//Input without protocol
ddd.addInputRequest( 'node', 'cmd', 'invoke', 'rawData', {} );
let resTimeInMilliSec = 1007;
ddd.addInputResponse( 'node', 'cmd', 'invoke', 'rawData', {}, resTimeInMilliSec );
ddd.addInputResponse( 'node', 'cmd', 'invoke', 'rawData', {} );
ddd.addInputResponseTimeout( 'node', 'cmd', 'invoke');
ddd.addInputResponseError( 'node', 'cmd', 'invoke');

//Output without protocol
ddd.addOutputRequest( 'node', 'cmd', 'invoke', 'rawData', {});
ddd.addOutputResponse( 'node', 'cmd', 'invoke', 'rawData', {});
let totalCount_ex1 = 1;
let maxRetry_ex1 = 2;
ddd.addOutputRequestRetry( 'node', 'cmd', 'invoke', 'rawData', {}, totalCount_ex1, maxRetry_ex1 );
ddd.end();

//Input/Output with protocol
let protocol="http";
let protocolMethod="get";
ddd.addInputRequest( 'node', 'cmd', 'invoke', 'rawData', {}, protocol, protocolMethod );
ddd.addOutputRequest( 'node', 'cmd', 'invoke', 'rawData', {}, protocol, protocolMethod);
ddd.end();
  • example detail log
{
  "Host": "DESKTOP-E0NGPUA",
  "AppName": "PROJECT_NAME",
  "Instance": "0",
  "Session": "session1",
  "InitInvoke": "initInvoke",
  "Scenario": "cmd",
  "Identity": "identity",
  "InputTimeStamp": "20190724 09:37:49.200",
  "Input": [
    {
      "Invoke": "invoke",
      "Event": "node.cmd",
      "Type": "req",
      "Data": {
        
      }
    },
    {
      "Invoke": "invoke",
      "Event": "node.cmd",
      "Protocol": "http.get",
      "Type": "req",
      "Data": {
        
      }
    },
    {
      "Invoke": "invoke",
      "Event": "node.cmd",
      "Type": "res",
      "Data": {
        
      },
      "ResTime": "1007 ms"
    },
    {
      "Invoke": "invoke",
      "Event": "node.cmd",
      "Type": "res",
      "Data": {
        
      }
    },
    {
      "Invoke": "invoke",
      "Event": "node.cmd",
      "Type": "res_timeout"
    },
    {
      "Invoke": "invoke",
      "Event": "node.cmd",
      "Type": "res_error"
    }
  ],
  "OutputTimeStamp": "20190724 09:37:49.200",
  "Output": [
    {
      "Invoke": "invoke",
      "Event": "node.cmd",
      "Type": "req",
      "Data": {
        
      }
    },
    {
      "Invoke": "invoke",
      "Event": "node.cmd",
      "Protocol": "http.get",
      "Type": "req",
      "Data": {
        
      }
    },
    {
      "Invoke": "invoke",
      "Event": "node.cmd",
      "Type": "res",
      "Data": {
        
      }
    },
    {
      "Invoke": "invoke",
      "Event": "node.cmd",
      "Type": "req_retry_1/2",
      "Data": {
        
      }
    }
  ],
  "ProcessingTime": "1 ms"
}

Version History

version 1.5.1

Add function addField(key, value) to summary log.

version 1.6.0

Add function stream log to logStash.
Fix calulate detaillog ProcessingTime.
Add config conf.stat.format pipe or json (default json).
Add config conf.log.format pipe or json (default json).

version 1.6.1

Add field "ProcessApp" in app log.

version 1.6.2, 1.6.3

Fix error init log without conf.stat.

version 1.6.4

Fix bug call add stat without conf

version 1.6.5

Change summaryLog.Sequences.result to summaryLog.Sequences.Result

version 1.6.6

Fixed appLog write Instances of Error objects with {}

version 1.6.7

Fixed detailLog case only have input

version 1.6.8

DetailLog add ResTime to input responseType res,res_timeout,res_error

version 1.6.9

DetailLog add function isRawDataEnabled()

version 1.6.10, 1.6.11, 1.6.12

SummaryLog add function isEnd()
SummaryLog check end,endASync twice