Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@vladmandic/pilogger

Package Overview
Dependencies
Maintainers
1
Versions
42
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@vladmandic/pilogger - npm Package Compare versions

Comparing version 0.1.5 to 0.1.6

1

.eslintrc.json

@@ -16,3 +16,4 @@ {

"rules": {
"no-param-reassign": "off"
}
}

2

package.json
{
"name": "@vladmandic/pilogger",
"version": "0.1.5",
"version": "0.1.6",
"description": "Simple Logger for NodeJS",

@@ -5,0 +5,0 @@ "main": "pilogger.js",

@@ -17,2 +17,3 @@ const fs = require('fs');

tags.fatal = chalk.bold.red('FATAL: ');
tags.timed = chalk.magentaBright('TIMED: ');
tags.state = chalk.magenta('STATE: ');

@@ -86,2 +87,19 @@ let logStream = null;

async function timed(t0, ...messages) {
if (arguments.length < 2) {
messages = [t0];
t0 = process.hrtime.bigint();
}
const t1 = process.hrtime.bigint();
let elapsed = 0;
try {
elapsed = parseInt(t1 - t0, 10);
} catch { /**/ }
elapsed = Math.round(elapsed / 1000000).toLocaleString();
const time = moment(Date.now()).format(dateFormat);
// eslint-disable-next-line no-console
console.log(time, tags.timed, `${elapsed} ms`, ...messages);
if (logFileOK) logStream.write(`${tags.timed} ${time} ${elapsed} ms ${combineMessages(...messages)}\n`);
}
async function log(tag, ...messages) {

@@ -114,2 +132,9 @@ const time = moment(Date.now()).format(dateFormat);

function test() {
const t0 = process.hrtime.bigint();
setTimeout(() => timed(t0, 'Test function execution'), 1000);
}
if (!module.parent) test();
// local ring buffer

@@ -122,2 +147,4 @@ exports.ring = ring;

exports.console = print;
// log with timing
exports.timed = timed;
// simple logging to application log

@@ -124,0 +151,0 @@ exports.logFile = setLogFile;

@@ -51,2 +51,21 @@ # PiLogger

Example output (note that markdown rules strip colored output):
2020-08-08 10:36:55 INFO: piscan version 0.0.1
2020-08-08 10:36:55 INFO: User: root Platform: linux Arch: x64 Node: v14.4.0
2020-08-08 10:36:55 STATE: Running as root with full capabilities
2020-08-08 10:37:08 DATA: host: pi ip: 192.168.0.100 time: 12,210
2020-08-08 10:37:10 DATA: mac: DC:A6:32:1B:74:D5 vendor: Raspberry Pi os: Linux 5.4
2020-08-08 10:37:12 DATA: ports: 22,139,445,514,873
Messages that are mirrored to console and `logFile` (if set), each one prefixed and color coded and with time measurement
const t0 = process.hrtime.bigint();
// do your stuff here
log.timed(t0, ...msg);
Example output:
2020-08-08 10:39:59 TIMED: 1,004 ms Test function execution
Messages that are output to `accessFile` (if set) only

@@ -53,0 +72,0 @@ Useful for detailed application access log that you don't want printed to console

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc