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

kitten-logger

Package Overview
Dependencies
Maintainers
0
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.2.2 to 0.3.0

4

CHANGELOG.md

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

## v0.3.0
*2024-02-29*
- Add support for diagnosticChannel on `kitten-logger`.
## v0.2.2

@@ -2,0 +6,0 @@ *2022-11-28*

2

package.json
{
"name": "kitten-logger",
"version": "0.2.2",
"version": "0.3.0",
"description": "",

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

@@ -1,7 +0,11 @@

const fs = require('fs');
const path = require('path');
const cluster = require('cluster');
const formatters = require('./formatters');
const { KITTEN_LOGGER_TAG } = require('./utils');
const fs = require('fs');
const path = require('path');
const cluster = require('cluster');
const formatters = require('./formatters');
const {
KITTEN_LOGGER_TAG,
publishDiagnostic
} = require('./utils');
const originalWrite = process.stdout.write.bind(process.stdout);

@@ -90,7 +94,11 @@ let formatFn = formatters.formatTTY;

const message = chunk.toString();
destination(
formatters.format('DEBUG', cluster.isWorker ? 'worker' : 'master', process.pid, [chunk.toString()]),
formatters.format('DEBUG', cluster.isWorker ? 'worker' : 'master', process.pid, [message]),
encoding,
callback
);
publishDiagnostic('DEBUG', cluster.isWorker ? 'worker' : 'master', process.pid, formatters.parseMsgOrOptions([message]));
};

@@ -107,2 +115,4 @@ process.stderr.write = (chunk, encoding, callback) => {

);
publishDiagnostic('ERROR', cluster.isWorker ? 'worker' : 'master', process.pid, formatters.parseMsgOrOptions([chunk.toString()]));
};

@@ -109,0 +119,0 @@

@@ -61,2 +61,3 @@ const utils = require('./utils');

module.exports = {
parseMsgOrOptions,

@@ -63,0 +64,0 @@ /**

@@ -1,7 +0,7 @@

const formatters = require('./formatters');
const filter = require('./filter');
const destination = require('./destination');
const utils = require('./utils');
const formatFn = utils.isTTY ? formatters.formatTTY : formatters.format;
let loggers = {};
const formatters = require('./formatters');
const filter = require('./filter');
const destination = require('./destination');
const utils = require('./utils');
const formatFn = utils.isTTY ? formatters.formatTTY : formatters.format;
let loggers = {};

@@ -22,6 +22,26 @@

const LOG_LEVEL_FNS = {
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) )}},
info (namespace) {
return function info () {
utils.publishDiagnostic('INFO', namespace, process.pid, formatters.parseMsgOrOptions(arguments));
destination.desWrite(formatFn('INFO' , namespace, process.pid, arguments));
}
},
debug (namespace) {
return function debug () {
utils.publishDiagnostic('DEBUG', namespace, process.pid, formatters.parseMsgOrOptions( arguments));
destination.desWrite(formatFn('DEBUG', namespace, process.pid, arguments));
}
},
warn (namespace) {
return function warn () {
utils.publishDiagnostic('WARN', namespace, process.pid, formatters.parseMsgOrOptions( arguments));
destination.desWrite(formatFn('WARN' , namespace, process.pid, arguments));
}
},
error (namespace) {
return function error () {
utils.publishDiagnostic('ERROR', namespace, process.pid, formatters.parseMsgOrOptions( arguments));
destination.desWrite(formatFn('ERROR', namespace, process.pid, arguments));
}
},
disabled : function disabled () { return; }

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

@@ -1,4 +0,14 @@

const cluster = require('cluster');
const tty = require('tty');
const tty = require('tty');
const diagnosticsChannel = require('diagnostics_channel');
const DIAGNOSTIC_CHANNEL_NAME = 'kitten-logger';
const channel = diagnosticsChannel.channel(DIAGNOSTIC_CHANNEL_NAME);
const DIAGNOSTIC_SEVERITY = {
ERROR : 3,
WARN : 2,
INFO : 1,
DEBUG : 0,
};
/**

@@ -43,3 +53,31 @@ * zero padding

KITTEN_LOGGER_TAG : 'K_LOG'
KITTEN_LOGGER_TAG : 'K_LOG',
DIAGNOSTIC_CHANNEL_NAME,
DIAGNOSTIC_SEVERITY,
/**
* Publishes a diagnostic message to a diagnostics channel.
*
* @param {string} level - The logging level (e.g., 'INFO', 'ERROR').
* @param {string} namespace - The namespace associated with the message.
* @param {number} pid - The process ID from which the message originates.
* @param {string} message - The message to be published.
*/
publishDiagnostic(level, namespace, pid, message) {
const diagnostic = {
severity : DIAGNOSTIC_SEVERITY[level],
message : message.msg,
properties : {
namespace,
pid,
}
};
if (message.id) {
diagnostic.properties.id = message.id;
}
channel.publish(diagnostic);
}
};
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