@gxyz/data.formats
@gxyz/data.formats is a collection of data logging formats for use with Winston.
Installation
Install the module locally via your favorite npm client, like npm:
npm install @gxyz/data.formats
or yarn:
yarn add @gxyz/data.formats
Usage
mustache
Use Mustache.js as template system to format logs’s display.
You can use this format from the main entrance:
const {mustache,} = require('@gxyz/data.formats');
Or from the custom sub-path ./mustache
:
const mustache = require('@gxyz/data.formats/mustache');
Using this path is not recommended:
const mustache = require('@gxyz/data.formats/lib/mustache');
const mustache = require('@gxyz/logger.format.mustache');
const logger = winston.createLogger({
format: mustache({
source: require.resolve('./tpl.mustache'),
}),
});
mustache format accepts the following config props:
-
source
prop of type String that points to Mustache filename or Mustache template. Please consider usingrequire.resolve
to point to a filename. - All remaining props of config will be considered part of view obj (take a look at Mustache.js docs).
Credits
Aziz Da |