@squiz/component-logger-lib
Advanced tools
Comparing version
@@ -38,4 +38,5 @@ "use strict"; | ||
async append(level, message, traceId) { | ||
var _a; | ||
const payload = typeof message == 'string' ? message : JSON.stringify(message); | ||
this.batch.push({ | ||
let logMessage = { | ||
level: level, | ||
@@ -45,5 +46,11 @@ service: 'render-runtime', | ||
message: payload, | ||
tags: this.config.tags, | ||
traceid: traceId, | ||
}); | ||
}; | ||
if ((_a = this.config.tags) === null || _a === void 0 ? void 0 : _a.length) { | ||
logMessage = { | ||
...logMessage, | ||
tags: this.config.tags, | ||
}; | ||
} | ||
this.batch.push(logMessage); | ||
if (this.batch.length == MESSAGE_BATCH_SIZE) { | ||
@@ -50,0 +57,0 @@ await this.flush(); |
@@ -92,2 +92,45 @@ "use strict"; | ||
}); | ||
it('should not include "tags" in payload if tags is not configured', async () => { | ||
const loggerConfig = { | ||
enabled: true, | ||
logUrl: 'some-log-url/', | ||
key: 'some-key', | ||
tenantId: 'some-tenant-id', | ||
}; | ||
const logger = new component_logger_1.ComponentLogger(loggerConfig); | ||
await logger.info('The quick brown fox', '123'); | ||
await logger.flush(); | ||
const expectedMessages = [ | ||
{ | ||
level: 'INFO', | ||
service: 'render-runtime', | ||
timestamp: '2023-05-28T00:00:00.000Z', | ||
message: 'The quick brown fox', | ||
traceid: '123', | ||
}, | ||
]; | ||
expect(postSetMock.send).toBeCalledWith(expectedMessages); | ||
}); | ||
it('should not include "tags" in payload if tags is configured as empty string', async () => { | ||
const loggerConfig = { | ||
enabled: true, | ||
logUrl: 'some-log-url/', | ||
key: 'some-key', | ||
tenantId: 'some-tenant-id', | ||
tags: '', | ||
}; | ||
const logger = new component_logger_1.ComponentLogger(loggerConfig); | ||
await logger.info('The quick brown fox', '123'); | ||
await logger.flush(); | ||
const expectedMessages = [ | ||
{ | ||
level: 'INFO', | ||
service: 'render-runtime', | ||
timestamp: '2023-05-28T00:00:00.000Z', | ||
message: 'The quick brown fox', | ||
traceid: '123', | ||
}, | ||
]; | ||
expect(postSetMock.send).toBeCalledWith(expectedMessages); | ||
}); | ||
it('should not send message if disabled', async () => { | ||
@@ -94,0 +137,0 @@ const loggerConfig = { |
{ | ||
"name": "@squiz/component-logger-lib", | ||
"version": "1.35.1-alpha.5", | ||
"version": "1.35.1-alpha.6", | ||
"description": "", | ||
@@ -24,3 +24,3 @@ "main": "lib/index.js", | ||
}, | ||
"gitHead": "6c976023e77f7cceab962b5563fcaf669aedaa6d" | ||
"gitHead": "59c19bcba89607f7909e83d5d9f6895841870a3a" | ||
} |
@@ -104,2 +104,53 @@ import { ComponentLogger } from './component-logger'; | ||
it('should not include "tags" in payload if tags is not configured', async () => { | ||
const loggerConfig = <ComponentLoggerConfig>{ | ||
enabled: true, | ||
logUrl: 'some-log-url/', | ||
key: 'some-key', | ||
tenantId: 'some-tenant-id', | ||
}; | ||
const logger = new ComponentLogger(loggerConfig); | ||
await logger.info('The quick brown fox', '123'); | ||
await logger.flush(); | ||
const expectedMessages = [ | ||
{ | ||
level: 'INFO', | ||
service: 'render-runtime', | ||
timestamp: '2023-05-28T00:00:00.000Z', | ||
message: 'The quick brown fox', | ||
traceid: '123', | ||
}, | ||
]; | ||
expect(postSetMock.send).toBeCalledWith(expectedMessages); | ||
}); | ||
it('should not include "tags" in payload if tags is configured as empty string', async () => { | ||
const loggerConfig = <ComponentLoggerConfig>{ | ||
enabled: true, | ||
logUrl: 'some-log-url/', | ||
key: 'some-key', | ||
tenantId: 'some-tenant-id', | ||
tags: '', | ||
}; | ||
const logger = new ComponentLogger(loggerConfig); | ||
await logger.info('The quick brown fox', '123'); | ||
await logger.flush(); | ||
const expectedMessages = [ | ||
{ | ||
level: 'INFO', | ||
service: 'render-runtime', | ||
timestamp: '2023-05-28T00:00:00.000Z', | ||
message: 'The quick brown fox', | ||
traceid: '123', | ||
}, | ||
]; | ||
expect(postSetMock.send).toBeCalledWith(expectedMessages); | ||
}); | ||
it('should not send message if disabled', async () => { | ||
@@ -106,0 +157,0 @@ const loggerConfig = <ComponentLoggerConfig>{ |
@@ -42,4 +42,3 @@ import superagent from 'superagent'; | ||
const payload = typeof message == 'string' ? message : JSON.stringify(message); | ||
this.batch.push({ | ||
let logMessage: ComponentLogMessage = { | ||
level: level, | ||
@@ -49,5 +48,11 @@ service: 'render-runtime', | ||
message: payload, | ||
tags: this.config.tags, | ||
traceid: traceId, | ||
}); | ||
}; | ||
if (this.config.tags?.length) { | ||
logMessage = { | ||
...logMessage, | ||
tags: this.config.tags, | ||
}; | ||
} | ||
this.batch.push(logMessage); | ||
@@ -54,0 +59,0 @@ if (this.batch.length == MESSAGE_BATCH_SIZE) { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
117668
4.09%950
11.63%