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

@voodoo.io/fast-logger

Package Overview
Dependencies
Maintainers
7
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@voodoo.io/fast-logger - npm Package Compare versions

Comparing version 0.0.3 to 0.0.4

0

index.js
module.exports = require('./src/logger');

@@ -0,0 +0,0 @@ module.exports = {

2

package.json
{
"name": "@voodoo.io/fast-logger",
"version": "0.0.3",
"version": "0.0.4",
"description": "Fast logger with a buffer",

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

@@ -40,2 +40,11 @@ # fast-logger

You can provide a var env: `LOG_LEVEL`. For example, setting "warn" will disabled trace, debug and info logs.
Accepted values:
- trace
- debug
- info _(default if wrong or none defined)_
- warn
- error
### Basic Usage

@@ -55,3 +64,5 @@

The logger has a buffer of 100 ms by default if the logs are exactly the same
The logger has a buffer of 100 ms by default if the logs are exactly the same (same objects, not same JSON-equivalent object)
More information at: https://www.npmjs.com/package/lru-cache

@@ -58,0 +69,0 @@ ```javascript

@@ -9,23 +9,30 @@ 'use strict';

const APP_NAME = process.env.APP_NAME || 'UnknownAppName',
SKELETON_LOG = {
app: APP_NAME,
time: '',
level: '',
msg: '',
err: ''
};
const info = (...data) => {
setImmediate(() => {
generateLog('info', ...data)
})
const levels = ['trace', 'debug', 'info', 'warn', 'error'];
const defaultLevel = 'info';
const APP_NAME = process.env.APP_NAME || 'UnknownAppName';
const LOG_LEVEL = process.env.LOG_LEVEL || defaultLevel;
const SKELETON_LOG = {
app: APP_NAME,
time: '',
level: '',
msg: '',
err: ''
};
const error = (...data) => {
setImmediate(() => {
generateLog('error', ...data)
})
};
let loglevelIndex = levels.indexOf(LOG_LEVEL);
if (loglevelIndex === -1) {
loglevelIndex = levels.indexOf(defaultLevel);
}
const logFunctions = {};
levels.forEach((level, index) => {
logFunctions[level] = (...data) => {
if (index >= loglevelIndex) {
setImmediate(() => {
generateLog(level, ...data)
});
}
};
});
function generateLog(type, ...data) {

@@ -85,6 +92,5 @@ let finalLog = utils.clone(SKELETON_LOG),

module.exports = {
info,
error,
...logFunctions,
setCacheTTL,
cache
};

@@ -0,0 +0,0 @@ 'use strict';

@@ -8,9 +8,18 @@ const logger = require('../index');

describe('Logger', () => {
const OLD_ENV = process.env;
const OLD_DATE = Date;
afterEach(() => {
mockConsole.mockClear();
process.env = OLD_ENV;
global.Date = OLD_DATE;
});
beforeEach(() => {
logger.cache.reset()
jest.resetModules();
logger.cache.reset();
process.env = { ...OLD_ENV };
});

@@ -88,3 +97,66 @@

expect(mockConsole).toBeCalledTimes(4)
})
});
it('Default LOG_LEVEL is info', () => {
const obj = {key: 'value'};
logger.trace(obj);
logger.debug(obj);
logger.info(obj);
logger.warn(obj);
logger.error(obj);
expect(mockConsole).toBeCalledTimes(3);
});
it('Trace Log level shows all logs', () => {
process.env.LOG_LEVEL = 'trace';
const logger = require('../index');
const obj = {key: 'value'};
logger.trace(obj);
logger.debug(obj);
logger.info(obj);
logger.warn(obj);
logger.error(obj);
expect(mockConsole).toBeCalledTimes(5);
});
it('Error Log level shows only error logs', () => {
process.env.LOG_LEVEL = 'error';
const logger = require('../index');
const obj = {key: 'value'};
logger.trace(obj);
logger.debug(obj);
logger.info(obj);
logger.warn(obj);
logger.error(obj);
expect(mockConsole).toBeCalledTimes(1);
});
it('Wrong LOG_LEVEL fallback to info', () => {
process.env.LOG_LEVEL = 'voodoo';
const logger = require('../index');
const obj = {key: 'value'};
logger.trace(obj);
logger.debug(obj);
logger.info(obj);
logger.warn(obj);
logger.error(obj);
expect(mockConsole).toBeCalledTimes(3);
});
it('Logging only boolean does not log anything special.', () => {
const staticDate = new Date();
global.Date = jest.fn(() => staticDate);
global.Date.now = OLD_DATE.now;
logger.info(true);
const expectedOutput = JSON.stringify({app: "Logger", time: new Date(), level: "info"});
expect(mockConsole).toBeCalledWith(expectedOutput);
});
});

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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