Skip to content

Commit 4392f8b

Browse files
committed
docs: add initial readme
Release-As: 0.1.0
1 parent 81b0bd3 commit 4392f8b

File tree

1 file changed

+72
-0
lines changed

1 file changed

+72
-0
lines changed

README.md

+72
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
# log4js layout - json
2+
3+
Simple json layouy module for [log4js][log4js_github].
4+
5+
[log4js_github]: https://log4js-node.github.io/log4js-node/
6+
7+
## Installation
8+
9+
### npm registry
10+
11+
```sh
12+
npm install log4js-layout-json
13+
```
14+
15+
## Example Output
16+
17+
Output:
18+
19+
```plain
20+
{"time":"2024-05-11T18:18:34.266Z","category":"default","level":"INFO","msg":"Initializing DB connection"}
21+
```
22+
23+
Adding context:
24+
25+
```ts
26+
log.addContext("user", "john");
27+
```
28+
29+
```plain
30+
{"time":"2024-05-11T18:19:34.266Z","category":"default","level":"INFO","msg":"Initializing DB connection","user":"john"}
31+
```
32+
33+
## Usage
34+
35+
Set the layout type to `json`.
36+
37+
Each log object contains the following properties:
38+
39+
- `time` - time in ISO 8601 format
40+
- `category` - specified when log4js is initialized
41+
- `msg` - if the log message is a string, otherwise omitted
42+
- `level` - level in human readable format
43+
44+
## Example configuration
45+
46+
```ts
47+
import log4js from "log4js";
48+
import jsonLayout from "log4js-json-layout";
49+
50+
log4js.addLayout("json", jsonLayout);
51+
```
52+
53+
minimal:
54+
55+
```ts
56+
log4js.configure({
57+
appenders: {
58+
out: {
59+
type: "stdout",
60+
layout: {
61+
type: "json",
62+
},
63+
},
64+
},
65+
categories: {
66+
default: {
67+
level: "debug",
68+
appenders: ["out"],
69+
},
70+
},
71+
});
72+
```

0 commit comments

Comments
 (0)