micronodelib 1.0.6 → 1.0.8
Sign up to get free protection for your applications and to get access to all the features.
- package/README.md +22 -6
- package/package.json +1 -1
package/README.md
CHANGED
@@ -20,22 +20,38 @@ yarn add micronodelib
|
|
20
20
|
|
21
21
|
## Usage
|
22
22
|
|
23
|
-
```
|
23
|
+
```javascript
|
24
24
|
import express, {Application} from "express";
|
25
25
|
import {Logger, httpContextMiddleware, requestLogMiddleware} from "micronodelib";
|
26
26
|
const app: Application = express();
|
27
27
|
|
28
|
-
|
28
|
+
// Optional, if you want to override default console log
|
29
|
+
console.log = Logger.info
|
30
|
+
console.error = Logger.error
|
31
|
+
|
32
|
+
// Enable request context
|
29
33
|
app.use(httpContextMiddleware());
|
30
34
|
|
31
|
-
|
35
|
+
// Enable http request log
|
32
36
|
app.use(requestLogMiddleware({
|
33
|
-
|
37
|
+
// Ignore request log for specific routes
|
34
38
|
ignoreRoutes: ["/actuator/health"]
|
35
39
|
}));
|
36
40
|
|
37
41
|
app.listen(3000, () => {
|
38
|
-
|
42
|
+
// Using standard log level: debug, info, warn, error
|
39
43
|
Logger.info('App started');
|
40
44
|
})
|
41
|
-
```
|
45
|
+
```
|
46
|
+
|
47
|
+
## Sample output format
|
48
|
+
|
49
|
+
**Standard log format**
|
50
|
+
```json
|
51
|
+
{"level":"INFO","msg":"Test log message","request_meta":{"request_id":"a06dd50a-7127-4f87-bfe0-b7104fb453c9"},"ts":1652842663}
|
52
|
+
```
|
53
|
+
|
54
|
+
**Http request log format**
|
55
|
+
```json
|
56
|
+
{"level":"INFO","msg":"finish router","request_meta":{"client_ip":null,"execution_time":4,"query":"","request_id":"a06dd50a-7127-4f87-bfe0-b7104fb453c9","request_method":"GET","request_path":"/example-path","request_pattern":"/example-path","status":200,"url":"/example-path","user_agent":"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/101.0.4951.64 Safari/537.36"},"ts":1652842718}
|
57
|
+
```
|