Logsplit
Takes large objects and splits them into small chunks for separate logging, with easily followable references.
Example
const createLogSplitter = ;const logsplit = ; const message = author: "Tommy Brunn" packages: name: "express-physical" url: "https://github.com/Nevon/express-physical" // additional fields making this object very large ; console; // `logsplit` returns this object, which contains a reference to the extracted// large object:// {// author: 'Tommy Brunn',// packages: 'Log-Reference-e44ab504-2202-4879-87ba-66c30ab7cf4f'// } // Additionally, the extracted object gets logged separately:// {// $reference: 'Log-Reference-e44ab504-2202-4879-87ba-66c30ab7cf4f',// $item: [// {// name: 'express-physical',// url: 'https://github.com/Nevon/express-physical'// // additional fields making this object very large// }// ]// }
Motivation
For debugging purposes, I find it very useful to log all data that was used in my system. For example, request and response bodies in a web service. However, due to limitations in logging tools, it's not always desirable to log the entire payload in a single message.
As it is impossible to know up front what parts of your data will be important until after you need it, Logsplit helps you to log a high level message while separately logging the details for when you need them.
Installation
npm install logsplit --save# yarn add logsplit
Usage
createLogSplitter
takes a logging function and an optional options object, and returns a function (logsplit
).
const createLogSplitter = ; const logFunction = console;const options = // maximum approximate object size for extraction maxByteSize: 1500 // generate the reference string to replace the large object with `Log-Reference-`; const logsplit = ; console;
Express Middleware
Logsplit can be used as an Express middleware for doing request/response body logging. If you are interested in this use case, open an issue.
License
See LICENSE for more details.