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

log4js-json-layout

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

log4js-json-layout

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

  • 2.2.2
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
4.5K
decreased by-24.98%
Maintainers
1
Weekly downloads
 
Created
Source

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

Additional properties can be specified as extra arguments of object type during invocation of log function. Static or constant properties can be specified using the static config option.

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
  • static - object, name value pairs of this object are added to output
  • dynamic - object, where each value is a no-argument function that must return a string/number/boolean. The key and the function's return value are added to the output

Example Config

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

log4js.addLayout('json', jsonLayout);

Minimal:

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

More options:

appenders = [{
  type: 'console',
  messageParam: 'msg',
  layout: {
    type: 'json',
    source: 'development',
    static: {
      appName: 'mysuperbapp'
    },
    dynamic: {
      transactionId: function() {
        return 'tx-id'; // string
      },
      isAdmin: function() {
        return 1>0; // boolean
      },
      countLogin: function() {
        return 20; // number
      }
    },
    include: ['startTime', 'categoryName'],
  }
}];

const logger = log4js.getLogger('info');

logger.info('Test log');

Output:

{"startTime":"2017-07-27T00:01:05.175Z","categoryName":"/path/to/file/redis-client.js","level":"DEBUG","transactionId": "tx-id","isAdmin": true,"countLogin": 20,"data":"Test log",}

FAQs

Package last updated on 18 Mar 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

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