log4js-layout-json
TypeScript icon, indicating that this package has built-in type declarations

0.2.0 • Public • Published

log4js layout - json

Simple json layout module for log4js.

Installation

npm registry

npm install log4js-layout-json

Example Output

Output:

{"time":"2024-05-11T18:18:34.266Z","category":"default","level":"INFO","msg":"Initializing DB connection"}

Adding context:

log.addContext("user", "john");
{"time":"2024-05-11T18:19:34.266Z","category":"default","level":"INFO","msg":"Initializing DB connection","user":"john"}

Usage

Set the layout type to json.

Each log object contains the following properties:

  • time - time in ISO 8601 format
  • category - specified when log4js is initialized
  • msg - if the log message is a string, otherwise omitted
  • level - level in human readable format

Example configuration

import log4js from "log4js";
import { layout as jsonLayout } from "log4js-json-layout";

log4js.addLayout("json", jsonLayout);

minimal:

log4js.configure({
	appenders: {
		out: {
			type: "stdout",
			layout: {
				type: "json",
				includeFileName: true,
				includeFunctionName: true,
			},
		},
	},
	categories: {
		default: {
			level: "debug",
			appenders: ["out"],
		},
	},
});

Readme

Keywords

none

Package Sidebar

Install

npm i log4js-layout-json

Weekly Downloads

32

Version

0.2.0

License

Apache-2.0

Unpacked Size

16.3 kB

Total Files

5

Last publish

Collaborators

  • xseman