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

@lbu/insight

Package Overview
Dependencies
Maintainers
1
Versions
102
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@lbu/insight - npm Package Compare versions

Comparing version 0.0.6 to 0.0.7

19

index.js

@@ -1,17 +0,8 @@

const {
bytesToHumanReadable,
printProcessMemoryUsage,
} = require("./src/memory");
const { newLogger } = require("./src/logger");
import { newLogger } from "./src/logger.js";
const log = newLogger({
export { bytesToHumanReadable, printProcessMemoryUsage } from "./src/memory.js";
export { newLogger } from "./src/logger.js";
export const log = newLogger({
depth: 4,
});
module.exports = {
bytesToHumanReadable,
printProcessMemoryUsage,
log,
newLogger,
};
{
"name": "@lbu/insight",
"version": "0.0.6",
"version": "0.0.7",
"description": "Simple logger in NDJSON format",
"main": "index.js",
"type": "module",
"keywords": [

@@ -26,3 +27,3 @@ "lightbase",

},
"gitHead": "a7b150d9265f449127dc812d4bcef7fb803d6d63"
"gitHead": "4c2199aeb1052bab67b3b1355bd648086736abf7"
}

@@ -27,16 +27,15 @@ # @lbu/insight

- @lbu/cli: Project template, and simple script runner
- @lbu/code-gen: Flexible code generators. Supports generating validators,
router, SQL and more
- @lbu/code-gen: Flexible code generators. Supports generating router, validator
- @lbu/insight: Opinionated logger
- @lbu/server: Wrap around Koa and some useful middleware
- @lbu/stdlib: Growing library with features like uuid generation and background
jobs
- @lbu/stdlib: Growing library of various common utilities like uuid & a basic
templating system
## Roadmap
- [ ] @lbu/store: Common abstraction for FileSystem, Redis, Memory support for
queues, KV store etc
- [ ] @lbu/code-gen: More plugins
- [ ] @lbu/code-gen: OpenAPI importer
- [ ] @lbu/features: Feature flag implementation based on @lbu/store & support
for code-gen
- [ ] @lbu/code-gen: Postgres query generator
## Docs

@@ -43,0 +42,0 @@

@@ -1,3 +0,10 @@

const { writeNDJSON, writePretty } = require("./writer");
import { writeNDJSON, writePretty } from "./writer.js";
const defaultOptions = {
isProduction: () => process.env.NODE_ENV === "production",
stream: () => process.stdout,
ctx: () => {},
depth: () => 3,
};
/**

@@ -8,3 +15,2 @@ * @callback LogFn

*/
/**

@@ -18,68 +24,39 @@ * @typedef Logger

* Create a new logger
* @param {Object=} opts
* @param {boolean=} opts.isProduction
* @param {NodeJS.WritableStream} [opts.stream=process.stdout]
* @param {Object} [opts.ctx={}]
* @param {number} [opts.depth=3]
* @param {Object} [options]
* @param {boolean} [options.isProduction]
* @param {NodeJS.WritableStream} [options.stream=process.stdout]
* @param {Object} [options.ctx]
* @param {number} [options.depth]
* @return {{isProduction: (function(): boolean), setCtx: (function(Object): void),
* getCtx: (function(): Object|*), error: LogFn, setDepth: (function(number): void),
* info: LogFn}}
*/
const newLogger = opts => {
opts = opts || {};
opts.isProduction =
typeof opts.isProduction === "boolean"
? opts.isProduction
: process.env.NODE_ENV === "production";
opts.stream = opts.stream || process.stdout;
opts.ctx = opts.ctx || {};
opts.depth = opts.depth || 3;
export const newLogger = (options = {}) => {
const stream = options.stream || defaultOptions.stream();
const isProduction =
typeof options.isProduction === "boolean"
? options.isProduction
: defaultOptions.isProduction();
let ctx = options.ctx || defaultOptions.ctx();
let depth = options.depth || defaultOptions.depth();
return {
info: logger.bind(
undefined,
opts.isProduction,
opts.stream,
opts.depth,
opts.ctx,
"info",
),
error: logger.bind(
undefined,
opts.isProduction,
opts.stream,
opts.depth,
opts.ctx,
"error",
),
setDepth: setDepth.bind(undefined, opts),
setCtx: setCtx.bind(undefined, opts),
getCtx: () => opts.ctx,
info: (...args) => {
logger(isProduction, stream, depth, ctx, "info", ...args);
},
error: (...args) => {
logger(isProduction, stream, depth, ctx, "error", ...args);
},
setDepth: newDepth => {
depth = newDepth;
},
setCtx: newCtx => {
ctx = newCtx;
},
getCtx: () => ctx,
isProduction: () => isProduction,
};
};
/**
* @param opts
* @param {number} depth
*/
const setDepth = (opts, depth) => {
opts.depth = depth;
return newLogger(opts);
};
/**
* @param opts
* @param {Object} ctx
*/
const setCtx = (opts, ctx) => {
opts.ctx = ctx;
return newLogger(opts);
};
/**
* @param {boolean} isProduction
* @param {WritableStream} stream
* @param {number} depth
* @param {Object} ctx
* @param {"info", "error"} level
* @param {*} args
*/
const logger = (isProduction, stream, depth, ctx, level, ...args) => {
function logger(isProduction, stream, depth, ctx, level, ...args) {
const metaData = {

@@ -97,6 +74,2 @@ ...ctx,

}
};
module.exports = {
newLogger,
};
}

@@ -9,3 +9,3 @@ const sizes = ["Bytes", "KiB", "MiB", "GiB", "TiB", "PiB"];

*/
const bytesToHumanReadable = bytes => {
export const bytesToHumanReadable = bytes => {
if (bytes === 0) {

@@ -35,15 +35,19 @@ return "0 Byte";

*/
const printProcessMemoryUsage = logger => {
export const printProcessMemoryUsage = logger => {
const { external, heapTotal, heapUsed, rss } = process.memoryUsage();
logger.info({
rss: bytesToHumanReadable(rss),
heapUsed: bytesToHumanReadable(heapUsed),
heapTotal: bytesToHumanReadable(heapTotal),
external: bytesToHumanReadable(external),
});
if (logger.isProduction()) {
logger.info({
rss,
heapUsed,
heapTotal,
external,
});
} else {
logger.info({
rss: bytesToHumanReadable(rss),
heapUsed: bytesToHumanReadable(heapUsed),
heapTotal: bytesToHumanReadable(heapTotal),
external: bytesToHumanReadable(external),
});
}
};
module.exports = {
bytesToHumanReadable,
printProcessMemoryUsage,
};

@@ -1,2 +0,2 @@

const { inspect } = require("util");
import { inspect } from "util";

@@ -105,3 +105,3 @@ /**

// Handle classes & objects, note this also contains Typescript private members
// Handle classes & objects
const keys =

@@ -122,3 +122,3 @@ typeof message === "object" &&

const writePretty = (
export const writePretty = (
stream,

@@ -154,3 +154,3 @@ depth,

const writeNDJSON = (stream, depth, input) => {
export const writeNDJSON = (stream, depth, input) => {
input.timestamp = input.timestamp.toISOString();

@@ -162,6 +162,1 @@ input.message = formatMessage(depth, input.message);

};
module.exports = {
writeNDJSON,
writePretty,
};
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