fluxsauce / log4js-json-layout

provides a slim and easy to use json-layout for log4js-node

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

log4js-json-layout

A slim and easy to use JSON layout for log4js-node.

NPM

Build Status

Installation

npm install log4js-json-layout --save

Example Output

Output:

{"startTime":"2017-07-27T00:01:05.175Z","categoryName":"/path/to/file/redis-client.js","level":"DEBUG","data":"Connection to Redis successful!"}

Usage

Set the layout type to json.

Each log object contains the following properties:

  • startTime - time in ISO 8601 format
  • categoryName - specified when log4js is initialized
  • data - if the log message is a string, otherwise omitted
  • level - level in human readable format
  • source - if provided, will be included

Options

  • type - string, always json
  • source - optional string, just sets the property source. Example value: development
  • include - array of properties to include in the log object
  • colors - boolean; off by default. If set to true, colorizes the output using log4js default color scheme based on log level. Useful for development, do not use for storing logs.

Example Config

const log4js = require('log4js');
const jsonLayout = require('log4js-json-layout');

log4js.layouts.addLayout('json', jsonLayout);

Minimal:

appenders = [{
  type: 'console',
  layout: {
    type: 'json',
  }
}];

More options:

appenders = [{
  type: 'console',
  messageParam: 'msg',
  layout: {
    type: 'json',
    source: 'development',
    include: ['startTime', 'categoryName'],
  }
}];

About

provides a slim and easy to use json-layout for log4js-node

License:MIT License


Languages

Language:JavaScript 100.0%