@devrev/ts-adaas 1.11.1-beta.10 → 1.11.1-beta.11
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/dist/logger/logger.js +1 -1
- package/dist/logger/logger.test.js +18 -7
- package/package.json +1 -1
package/dist/logger/logger.js
CHANGED
|
@@ -36,7 +36,7 @@ class Logger extends node_console_1.Console {
|
|
|
36
36
|
}
|
|
37
37
|
else {
|
|
38
38
|
const logObject = Object.assign({ message: argsString }, this.tags);
|
|
39
|
-
this.originalConsole[level](logObject);
|
|
39
|
+
this.originalConsole[level](JSON.stringify(logObject));
|
|
40
40
|
}
|
|
41
41
|
}
|
|
42
42
|
logFn(args, level) {
|
|
@@ -64,7 +64,9 @@ describe(logger_1.Logger.name, () => {
|
|
|
64
64
|
const message = 'Worker is online. Started processing the task.';
|
|
65
65
|
logger.info(message);
|
|
66
66
|
const expectedLogObject = Object.assign(Object.assign({ message }, mockEvent.payload.event_context), { dev_oid: mockEvent.payload.event_context.dev_oid });
|
|
67
|
-
|
|
67
|
+
const actualCall = mockConsoleInfo.mock.calls[0][0];
|
|
68
|
+
const actualLogObject = JSON.parse(actualCall);
|
|
69
|
+
expect(actualLogObject).toEqual(expectedLogObject);
|
|
68
70
|
});
|
|
69
71
|
it('should log single object message with JSON stringify', () => {
|
|
70
72
|
const data = { id: 123, name: 'test' };
|
|
@@ -76,7 +78,9 @@ describe(logger_1.Logger.name, () => {
|
|
|
76
78
|
maxStringLength: Infinity,
|
|
77
79
|
});
|
|
78
80
|
const expectedLogObject = Object.assign(Object.assign({ message: expectedMessage }, mockEvent.payload.event_context), { dev_oid: mockEvent.payload.event_context.dev_oid });
|
|
79
|
-
|
|
81
|
+
const actualCall = mockConsoleInfo.mock.calls[0][0];
|
|
82
|
+
const actualLogObject = JSON.parse(actualCall);
|
|
83
|
+
expect(actualLogObject).toEqual(expectedLogObject);
|
|
80
84
|
});
|
|
81
85
|
it('should log multiple arguments joined with space', () => {
|
|
82
86
|
const text = 'Successfully fetched';
|
|
@@ -89,7 +93,9 @@ describe(logger_1.Logger.name, () => {
|
|
|
89
93
|
maxStringLength: Infinity,
|
|
90
94
|
});
|
|
91
95
|
const expectedLogObject = Object.assign(Object.assign({ message: `${text} ${expectedDataMessage}` }, mockEvent.payload.event_context), { dev_oid: mockEvent.payload.event_context.dev_oid });
|
|
92
|
-
|
|
96
|
+
const actualCall = mockConsoleInfo.mock.calls[0][0];
|
|
97
|
+
const actualLogObject = JSON.parse(actualCall);
|
|
98
|
+
expect(actualLogObject).toEqual(expectedLogObject);
|
|
93
99
|
});
|
|
94
100
|
it('should handle mixed string and object arguments', () => {
|
|
95
101
|
const text1 = 'Processing';
|
|
@@ -103,7 +109,9 @@ describe(logger_1.Logger.name, () => {
|
|
|
103
109
|
maxStringLength: Infinity,
|
|
104
110
|
});
|
|
105
111
|
const expectedLogObject = Object.assign(Object.assign({ message: `${text1} ${expectedDataMessage} ${text2}` }, mockEvent.payload.event_context), { dev_oid: mockEvent.payload.event_context.dev_oid });
|
|
106
|
-
|
|
112
|
+
const actualCall = mockConsoleInfo.mock.calls[0][0];
|
|
113
|
+
const actualLogObject = JSON.parse(actualCall);
|
|
114
|
+
expect(actualLogObject).toEqual(expectedLogObject);
|
|
107
115
|
});
|
|
108
116
|
});
|
|
109
117
|
describe('local development logging', () => {
|
|
@@ -158,7 +166,8 @@ describe(logger_1.Logger.name, () => {
|
|
|
158
166
|
it('[edge] should handle empty string message', () => {
|
|
159
167
|
logger.info('');
|
|
160
168
|
expect(mockConsoleInfo).toHaveBeenCalledTimes(1);
|
|
161
|
-
const
|
|
169
|
+
const actualCall = mockConsoleInfo.mock.calls[0][0];
|
|
170
|
+
const logObject = JSON.parse(actualCall);
|
|
162
171
|
expect(logObject.message).toBe('');
|
|
163
172
|
expect(logObject.dev_oid).toBe(mockEvent.payload.event_context.dev_oid);
|
|
164
173
|
expect(logObject.request_id).toBe(mockEvent.payload.event_context.request_id);
|
|
@@ -166,7 +175,8 @@ describe(logger_1.Logger.name, () => {
|
|
|
166
175
|
it('[edge] should handle null and undefined values', () => {
|
|
167
176
|
logger.info('test', null, undefined);
|
|
168
177
|
expect(mockConsoleInfo).toHaveBeenCalledTimes(1);
|
|
169
|
-
const
|
|
178
|
+
const actualCall = mockConsoleInfo.mock.calls[0][0];
|
|
179
|
+
const logObject = JSON.parse(actualCall);
|
|
170
180
|
// inspect shows 'null' and 'undefined' as strings
|
|
171
181
|
expect(logObject.message).toBe('test null undefined');
|
|
172
182
|
expect(logObject.dev_oid).toBe(mockEvent.payload.event_context.dev_oid);
|
|
@@ -182,7 +192,8 @@ describe(logger_1.Logger.name, () => {
|
|
|
182
192
|
};
|
|
183
193
|
logger.info(complexObject);
|
|
184
194
|
expect(mockConsoleInfo).toHaveBeenCalledTimes(1);
|
|
185
|
-
const
|
|
195
|
+
const actualCall = mockConsoleInfo.mock.calls[0][0];
|
|
196
|
+
const logObject = JSON.parse(actualCall);
|
|
186
197
|
// The logger uses inspect() with compact: false formatting
|
|
187
198
|
const expectedMessage = require('util').inspect(complexObject, {
|
|
188
199
|
compact: false,
|
package/package.json
CHANGED