New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@ulu/node-logger

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@ulu/node-logger - npm Package Compare versions

Comparing version 1.0.0 to 1.0.1

example.png

89

index.js

@@ -15,11 +15,13 @@ const Chalk = require('chalk');

};
/**
* Returns a debug object based on the configuration past
* @param {object} passed The options passed when constructing the debug Object
* @return {Object} Object with methods that used the passed options
* @typedef {Object} logger-instance
*/
module.exports = function(passed) {
/**
* Returns a logger instance based on the configuration
* @param {object} config The options for the logger instance
* @return {logger-instance} Object with methods to use to log output
*/
module.exports = function(config) {
const options = Object.assign({}, defaults, passed);
const options = Object.assign({}, defaults, config);

@@ -44,3 +46,14 @@ let prefix = options.title ? chalk.bold[options.colorTitle](`${ options.title } `) : "";

return {
log: function(...msgs) {
/**
* Changes to merge into options (ie. enable = false)
* @param {Object} changes
*/
setOptions(changes) {
Object.assign(options, changes, options);
},
/**
* Standard console.log
* @param {*} msgs Messages to output in console
*/
log(...msgs) {
if (!isEnabled()) return;

@@ -50,11 +63,23 @@ msgs.unshift(prefix);

},
required: function(...msgs) {
/**
* Always output messages (regardless of options.enabled)
* @param {*} msgs Messages to output in console
*/
required(...msgs) {
msgs.unshift(prefix);
console.log.apply(console, msgs);
},
error: function(...msgs) {
/**
* Always output styled error message
* @param {*} msgs Messages to output in console
*/
error(...msgs) {
msgs.unshift(chalk[options.colorError]('(Error) '));
this.required.apply(this, msgs);
},
warn: function(...msgs) {
/**
* Output warning styles logs
* @param {*} msgs Messages to output in console
*/
warn(...msgs) {
if (!isEnabled()) return;

@@ -64,3 +89,8 @@ msgs.unshift(chalk[options.colorWarning]('(Warning) '));

},
list: function(title, array) {
/**
* Output log in list (unordered/bullet) form
* @param {String} title Title for the list
* @param {Array} array Array of items to log
*/
list(title, array) {
if (!isEnabled()) return;

@@ -73,3 +103,8 @@ if (!title) {

},
listOrdered: function(title, array) {
/**
* Output log in an ordered list form
* @param {String} title Title for the list
* @param {Array} array Array of items to log
*/
listOrdered(title, array) {
if (!isEnabled()) return;

@@ -86,3 +121,9 @@ var list = array.reduce((acc, current, index) => {

},
devLog: function(...msgs) {
/**
* Output a log for the developer
* - Uses the 'options.devEnabled' flag for output condition
* - Styled differently (adds options.devTitle) to prefix
* @param {*} msgs Messages to output in console
*/
devLog(...msgs) {
if (!isEnabled(true)) return;

@@ -93,3 +134,8 @@ msgs.unshift(chalk.magenta(`(${ options.devTitle })`));

},
memory: function(scriptProcess, ...msgs) {
/**
* Display a dev log of the passed processes memory usage, plus any additional messages
* @param {Object} scriptProcess The process to use for memory log (ie. process variable in your script)
* @param {*} msgs Other messages to include
*/
memory(scriptProcess, ...msgs) {
if (!isEnabled()) return;

@@ -105,7 +151,18 @@

},
time: function(label = prefix) {
/**
* Start a log timer
* - call logger.timeEnd() to output the time span
* @param {String} label A custom label to use if you are running multiple time checks, defualts to prefix from options
*/
time(label = prefix) {
if (!isEnabled()) return;
console.time(label);
},
timeEnd: function(label = prefix, ...msgs) {
/**
* Start a log timer
* - call logger.timeEnd() to output the time span
* @param {String} label A custom label to use if you are running multiple time checks, defualts to prefix from options
* @param {*} msgs Other messages to include in the output
*/
timeEnd(label = prefix, ...msgs) {
if (!isEnabled()) return;

@@ -112,0 +169,0 @@ msgs.unshift(chalk.yellow('(Time Stamp)'));

2

package.json
{
"name": "@ulu/node-logger",
"version": "1.0.0",
"version": "1.0.1",
"description": "Reusable colored logging module for node",

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

@@ -30,2 +30,11 @@ const logger = require("./index.js")({

]);
logger.memory(process, "memory test");
logger.memory(process, "memory test");
let functionLoggerCounter = 0;
const functionLogger = require("./index.js")({
title: "Function Enabled Logger",
enabled: () => functionLoggerCounter++
});
functionLogger.log("This SHOULD NOT BE VISIBLE");
functionLogger.log("This should be visible");
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