@emartech/json-logger 3.1.0 → 3.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.npmignore +4 -0
- package/LICENSE.txt +7 -0
- package/README.md +3 -3
- package/package.json +2 -2
- package/src/logger/logger.js +16 -2
package/.npmignore
ADDED
package/LICENSE.txt
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
Copyright 2018 Emarsys
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
4
|
+
|
|
5
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
6
|
+
|
|
7
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/README.md
CHANGED
|
@@ -89,7 +89,7 @@ Same as info with fatal log level.
|
|
|
89
89
|
##### JsonLogger.prototype.fromError(action, data)
|
|
90
90
|
|
|
91
91
|
Displays an error object which formatted to fit into one line.
|
|
92
|
-
The displayed line contains the stack trace, the name and the message of the error.
|
|
92
|
+
The displayed line contains the stack trace, the name and the message of the error (for Axios errors, also request and response details).
|
|
93
93
|
The log level defaults to error.
|
|
94
94
|
|
|
95
95
|
```javascript
|
|
@@ -153,11 +153,11 @@ Logger.configure({
|
|
|
153
153
|
|
|
154
154
|
### Logging request identifier automatically
|
|
155
155
|
|
|
156
|
-
You need to use the middlewares of `@emartech/cls-adapter` and add its transformer to the
|
|
156
|
+
You need to use the middlewares of `@emartech/cls-adapter` and add its transformer to the logger's configure method.
|
|
157
157
|
This way it will log the request identifier coming from the header field (`X-Request-Id`) to every log line
|
|
158
158
|
where the called function is originating from the route handler.
|
|
159
159
|
|
|
160
|
-
For
|
|
160
|
+
For automating
|
|
161
161
|
|
|
162
162
|
```javascript
|
|
163
163
|
const Koa = require('koa');
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@emartech/json-logger",
|
|
3
|
-
"version": "3.1
|
|
3
|
+
"version": "3.4.1",
|
|
4
4
|
"description": "Tiny and fast json logger with namespace support",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
"engines": {
|
|
18
18
|
"node": ">= 8"
|
|
19
19
|
},
|
|
20
|
-
"license": "
|
|
20
|
+
"license": "MIT",
|
|
21
21
|
"keywords": [
|
|
22
22
|
"log",
|
|
23
23
|
"logging",
|
package/src/logger/logger.js
CHANGED
|
@@ -66,12 +66,26 @@ class Logger {
|
|
|
66
66
|
}
|
|
67
67
|
|
|
68
68
|
_getErrorDetails(error) {
|
|
69
|
-
|
|
69
|
+
const baseDetails = {
|
|
70
70
|
error_name: error.name,
|
|
71
71
|
error_stack: this._shortenStackTrace(error.stack),
|
|
72
72
|
error_message: error.message,
|
|
73
73
|
error_data: this._shortenData(error.data)
|
|
74
74
|
};
|
|
75
|
+
|
|
76
|
+
return Object.assign(baseDetails, this._getAxiosErrorDetails(error));
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
_getAxiosErrorDetails(error) {
|
|
80
|
+
if (!error.isAxiosError) return {};
|
|
81
|
+
|
|
82
|
+
return {
|
|
83
|
+
request_method: error.config.method,
|
|
84
|
+
request_url: error.config.url,
|
|
85
|
+
response_status: error.response ? error.response.status : undefined,
|
|
86
|
+
response_status_text: error.response ? error.response.statusText : undefined,
|
|
87
|
+
response_data: error.response ? this._shortenData(error.response.data) : undefined
|
|
88
|
+
};
|
|
75
89
|
}
|
|
76
90
|
}
|
|
77
91
|
|
|
@@ -82,7 +96,7 @@ Logger.config = {
|
|
|
82
96
|
};
|
|
83
97
|
|
|
84
98
|
const logMethodFactory = function(level) {
|
|
85
|
-
return function(action, data) {
|
|
99
|
+
return function(action, data = {}) {
|
|
86
100
|
if (!this._enabled) {
|
|
87
101
|
return;
|
|
88
102
|
}
|