You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+23-2Lines changed: 23 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,7 +1,7 @@
1
1
# console-log-json
2
2
3
3
## 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()`,
5
5
`console.error()` to handle anything you throw at it and have the
6
6
output be formatted to a consistent format in a single JSON line of text, including stack traces,
7
7
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.
13
13
- Log extra context if passed in.
14
14
- 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.
15
15
- 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"}
0 commit comments