@jitesoft/yolog-json-plugin
v1.1.6
Published
Plugin for @jitesoft/yolog to output logs as JSON.
Downloads
39
Readme
Yolog JSON Plugin
Plugin for the @jitesoft/yolog
logger create logs in json format.
When running in the browser, all the data will be printed to the console, while, when using the nodejs version
the data can either be pushed to a file or to the stdout/stderr of the application.
Usage:
Install with your favorite package manager!
npm i @jitesoft/yolog-json-plugin --save
yarn add @jitesoft/yolog-json-plugin
Import and use just as with any other yolog plugin!
import logger from '@jitesoft/yolog';
import JsonPlugin from '@jitesoft/yolog-json-plugin';
logger.addPlugin(new JsonPlugin('file.txt'));
To import it in a browser environment, the src/browser
(or /dist/browser
for precompiled) suffix have to be added:
import logger from '@jitesoft/yolog';
import JsonPlugin from '@jitesoft/yolog-json-plugin/src/browser';
logger.addPlugin(new JsonPlugin()); // No file!
Data format
Each line in the output is a single JS Object notation, that is, the full file is not an array of json objects, but each line should be parsed as its own.
Example:
{"tag": "emergency", "timestamp": 123123123, "message": "abc123!!", "error": { "message": "error message!", "stack": [ "callstack here." ] }}
{"tag": "warning", "timestamp": 123123124, "message": "abc123"}
That means that when parsing the file (or output), each line should be parsed as its own object.