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

kitten-logger

Package Overview
Dependencies
Maintainers
2
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

kitten-logger - npm Package Compare versions

Comparing version 0.1.21 to 0.2.1

4

CHANGELOG.md

@@ -0,1 +1,5 @@

## v0.2.1
*2022-09-01*
- Add multi-arguments for format functions. As a result, all format functions (info, error and so on) accept multiple arguments to log, like console.log. Ex: `logger.info('first arg', second arg, nth arg)`.
## v0.1.21

@@ -2,0 +6,0 @@ - Fix #3: kitten-logger was crashing because of null or undefined messages.

5

package.json
{
"name": "kitten-logger",
"version": "0.1.21",
"version": "0.2.1",
"description": "",

@@ -15,3 +15,6 @@ "main": "index.js",

"should": "^13.2.3"
},
"publishConfig": {
"registry": "https://registry.npmjs.org/"
}
}

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

destination(
formatFn('DEBUG', cluster.isWorker ? 'worker' : 'master', process.pid, chunk.toString()),
formatFn('DEBUG', cluster.isWorker ? 'worker' : 'master', process.pid, [chunk.toString()]),
encoding,

@@ -70,3 +70,3 @@ callback

destination(
formatFn('ERROR', cluster.isWorker ? 'worker' : 'master', process.pid, chunk.toString()),
formatFn('ERROR', cluster.isWorker ? 'worker' : 'master', process.pid, [chunk.toString()]),
encoding,

@@ -93,3 +93,3 @@ callback

destination(
formatters.format('DEBUG', cluster.isWorker ? 'worker' : 'master', process.pid, chunk.toString()),
formatters.format('DEBUG', cluster.isWorker ? 'worker' : 'master', process.pid, [chunk.toString()]),
encoding,

@@ -105,3 +105,3 @@ callback

destination(
formatters.format('ERROR', cluster.isWorker ? 'worker' : 'master', process.pid, chunk.toString()),
formatters.format('ERROR', cluster.isWorker ? 'worker' : 'master', process.pid, [chunk.toString()]),
encoding,

@@ -108,0 +108,0 @@ callback

@@ -18,2 +18,44 @@ const utils = require('./utils');

/**
* @param {Array} msgOrOptions Array of items to log and/or object of kitten options
* @param {Function} formatterFn
* @returns {{ id : {String}, msg : {String} }}
*/
function parseMsgOrOptions (msgOrOptions, formatterFn) {
let id = '';
let msg = [];
for (let key in msgOrOptions) {
let msgOrOption = msgOrOptions[key];
if (!msgOrOption) {
continue;
}
if (msgOrOption.idKittenLogger) {
id = msgOrOption.idKittenLogger;
continue;
}
if (formatterFn) {
msg.push(formatterFn(msgOrOption));
continue;
}
if (msgOrOption.constructor === String) {
msg.push(msgOrOption);
continue;
}
msg.push(JSON.stringify(msgOrOption, null, 2));
}
msg = msg.join(' ');
return {
id,
msg
};
}
module.exports = {

@@ -39,33 +81,21 @@

* @param {Int} pid
* @param {Object/String} msg to format/log
* @param {*} opt option to pass to formatter (ex: req)
* @param {Object/String} msgOrOptions message(s) to format/log, last is option object
*/
format (level, namespace, pid, msg, opt) {
format (level, namespace, pid, msgOrOptions) {
let _out = [];
let _time = '';
let _msg = '';
let _msg = [];
if (msg == null) {
msg = '';
if (!msgOrOptions) {
msgOrOptions = [];
}
// if the output is a terminal and we have a beautifier for this namespace, use it to parse the msg
if (msg.constructor === String){
_msg = msg;
}
else {
_msg = JSON.stringify(msg);
}
let { msg, id } = parseMsgOrOptions(msgOrOptions);
let _id = '';
if (opt && opt.idKittenLogger) {
_id = opt.idKittenLogger;
}
_time = getCurrentTimestamp();
// escape with simple quote, and add quote for CSV.
// As JSON uses double quote, we use simple quote for CSV to minimize replacements
_msg = "'" + _msg.replace(/'/g,"''").replace(/\n/g, '') + "'";
_msg = "'" + msg.replace(/'/g,"''").replace(/\n/g, '') + "'";
_out = _time + CSV_SEPARATOR + level + CSV_SEPARATOR + namespace + CSV_SEPARATOR + _msg + CSV_SEPARATOR + pid + CSV_SEPARATOR + _id;
_out = _time + CSV_SEPARATOR + level + CSV_SEPARATOR + namespace + CSV_SEPARATOR + _msg + CSV_SEPARATOR + pid + CSV_SEPARATOR + id;
return (variables.isLoggerChild && !variables.isInitialized ? KITTEN_LOGGER_TAG : '') + _out + '\n';

@@ -79,30 +109,14 @@ },

* @param {Int} pid
* @param {Object/String} msg to format/log
* @param {*} opt option to pass to formatter (ex: req)
* @param {Array} msgOrOptions message(s) to format/log, last is option object
*/
formatTTY (level, namespace, pid, msg, opt) {
formatTTY (level, namespace, pid, msgOrOptions) {
let _out = [];
let _time = '';
let _msg = '';
if (msg == null) {
msg = '';
if (!msgOrOptions) {
msgOrOptions = [];
}
// if the output is a terminal and we have a beautifier for this namespace, use it to parse the msg
if (formatters[namespace] instanceof Function) {
_msg = formatters[namespace](msg);
}
else if (msg.constructor === String){
_msg = msg;
}
else {
_msg = JSON.stringify(msg, null, 2);
}
let { msg : _msg, id : _id } = parseMsgOrOptions(msgOrOptions, formatters[namespace]);
let _id = '';
if (opt && opt.idKittenLogger) {
_id = opt.idKittenLogger;
}
_time = COLORS.DIM + getTime() + COLORS.OFF;

@@ -109,0 +123,0 @@ namespace = COLORS.DIM + namespace + COLORS.OFF;

@@ -22,6 +22,6 @@ const formatters = require('./formatters');

const LOG_LEVEL_FNS = {
info : function (namespace) { return function info (msg, opt) { destination.desWrite( formatFn('INFO' , namespace, process.pid, msg, opt) )}},
debug : function (namespace) { return function debug (msg, opt) { destination.desWrite( formatFn('DEBUG', namespace, process.pid, msg, opt) )}},
warn : function (namespace) { return function warn (msg, opt) { destination.desWrite( formatFn('WARN' , namespace, process.pid, msg, opt) )}},
error : function (namespace) { return function error (msg, opt) { destination.desWrite( formatFn('ERROR', namespace, process.pid, msg, opt) )}},
info : function (namespace) { return function info () { destination.desWrite( formatFn('INFO' , namespace, process.pid, arguments) )}},
debug : function (namespace) { return function debug () { destination.desWrite( formatFn('DEBUG', namespace, process.pid, arguments) )}},
warn : function (namespace) { return function warn () { destination.desWrite( formatFn('WARN' , namespace, process.pid, arguments) )}},
error : function (namespace) { return function error () { destination.desWrite( formatFn('ERROR', namespace, process.pid, arguments) )}},
disabled : function disabled () { return; }

@@ -28,0 +28,0 @@ };

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