Skip to content

Commit 7de72ba

Browse files
committed
Update README.md with examples
1 parent 8a3a2b2 commit 7de72ba

File tree

1 file changed

+23
-2
lines changed

1 file changed

+23
-2
lines changed

README.md

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# console-log-json
22

33
## Pupose and Description
4-
A drop-in replacement for `console.log()`, `console.info()`,
4+
A no fuss simple drop-in replacement for `console.log()`, `console.info()`,
55
`console.error()` to handle anything you throw at it and have the
66
output be formatted to a consistent format in a single JSON line of text, including stack traces,
77
so that it can be easily parsed by tool such as LogDNA.
@@ -13,4 +13,25 @@ so that it can be easily parsed by tool such as LogDNA.
1313
- Log extra context if passed in.
1414
- Won't crash out and cause the application to stop, if there is a problem with logger, instead try to fall back to original console.log, output what is possible and continue.
1515
- Logging is done in a non awaiting promise so that we yield to other processing while logging
16-
- Logs via error level when message contains the word "error" to properly flag errors even if a mistake is made using the wrong console.info instead of console.error.
16+
- Logs via error level when message contains the word "error" to properly flag errors even if a mistake is made using the wrong console.info instead of console.error.
17+
18+
## Usage
19+
20+
1. Install
21+
```
22+
npm install console-log-json
23+
```
24+
2. At the entry point of the application include the package and run *LoggerAdaptToConsole()*
25+
```
26+
import { LoggerAdaptToConsole } from "console-log-json";
27+
LoggerAdaptToConsole();
28+
```
29+
This will adapt *console.log()*, *console.error()*, etc... to take in any string, or object, in any order or any number of them, and it will log a consistently formatted single line JSON to console.
30+
For example:
31+
```
32+
console.warn('this is a message', {'some-extra-data': 'hello'});
33+
```
34+
will produce:
35+
```
36+
{"level":"warn","message":"this is a message","some-extra-data":"hello","@timestamp":"2019-11-29T21:44:40.463Z"}
37+
```

0 commit comments

Comments
 (0)