https://github.com/xseman/log4js-layout-json
Log4js JSON layout
https://github.com/xseman/log4js-layout-json
json log4js log4js-layout log4js-node logger
Last synced: 3 months ago
JSON representation
Log4js JSON layout
- Host: GitHub
- URL: https://github.com/xseman/log4js-layout-json
- Owner: xseman
- License: apache-2.0
- Created: 2023-07-27T16:12:52.000Z (almost 2 years ago)
- Default Branch: master
- Last Pushed: 2024-12-22T20:26:11.000Z (6 months ago)
- Last Synced: 2025-03-26T06:18:51.871Z (3 months ago)
- Topics: json, log4js, log4js-layout, log4js-node, logger
- Language: TypeScript
- Homepage: http://npm.im/log4js-layout-json
- Size: 86.9 KB
- Stars: 3
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# log4js layout - json
Simple json layout module for [log4js][log4js_github].
[log4js_github]: https://log4js-node.github.io/log4js-node/
## Installation
### npm registry
```sh
npm install log4js-layout-json
```## Example Output
Output:
```plain
{"time":"2024-05-11T18:18:34.266Z","category":"default","level":"INFO","msg":"Initializing DB connection"}
```Adding context:
```ts
log.addContext("user", "john");
``````plain
{"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
```ts
import log4js from "log4js";
import { layout as jsonLayout } from "log4js-json-layout";log4js.addLayout("json", jsonLayout);
```minimal:
```ts
log4js.configure({
appenders: {
out: {
type: "stdout",
layout: {
type: "json",
includeFileName: true,
includeFunctionName: true,
},
},
},
categories: {
default: {
level: "debug",
appenders: ["out"],
},
},
});
```