@mimik/sumologic-winston-logger 2.1.10 → 2.1.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/eslint.config.js CHANGED
@@ -30,10 +30,8 @@ export default [
30
30
  ecmaVersion: ECMA_VERSION,
31
31
  globals: {
32
32
  ...globals.nodeBuiltin,
33
- console: 'readonly',
34
33
  describe: 'readonly',
35
34
  it: 'readonly',
36
- require: 'readonly',
37
35
  },
38
36
  sourceType: 'module',
39
37
  },
@@ -41,6 +39,7 @@ export default [
41
39
  '@stylistic/brace-style': ['warn', 'stroustrup', { allowSingleLine: true }],
42
40
  '@stylistic/line-comment-position': ['off'],
43
41
  '@stylistic/max-len': ['warn', MAX_LENGTH_LINE, { ignoreComments: true, ignoreStrings: true, ignoreRegExpLiterals: true }],
42
+ '@stylistic/quotes': ['warn', 'single'],
44
43
  '@stylistic/semi': ['error', 'always'],
45
44
  'capitalized-comments': ['off'],
46
45
  'complexity': ['error', MAX_COMPLEXITY],
@@ -51,6 +50,7 @@ export default [
51
50
  'init-declarations': ['off'],
52
51
  'linebreak-style': ['off'],
53
52
  'max-depth': ['error', MAX_DEPTH],
53
+ 'max-len': 'off',
54
54
  'max-lines': ['warn', { max: MAX_LINES_IN_FILES, skipComments: true, skipBlankLines: true }],
55
55
  'max-lines-per-function': ['warn', { max: MAX_LINES_IN_FUNCTION, skipComments: true, skipBlankLines: true }],
56
56
  'max-params': ['error', MAX_FUNCTION_PARAMETERS],
@@ -63,7 +63,7 @@ export default [
63
63
  'no-undefined': ['off'],
64
64
  'one-var': ['error', 'never'],
65
65
  'processDoc/validate-document-env': ['error'],
66
- 'quotes': ['warn', 'single'],
66
+ 'quotes': 'off',
67
67
  'sort-imports': ['error', { allowSeparatedGroups: true }],
68
68
  'sort-keys': ['error', 'asc', { caseSensitive: true, minKeys: MIN_KEYS_IN_OBJECT, natural: false, allowLineSeparatedGroups: true }],
69
69
  },
@@ -13,6 +13,7 @@ import {
13
13
  UNKNOWN_ID,
14
14
  UNKNOWN_TYPE,
15
15
  WARN,
16
+ safeStringify,
16
17
  } from './common.js';
17
18
  import {
18
19
  KinesisClient,
@@ -119,12 +120,11 @@ export default class AwsKinesis extends Transport {
119
120
  }
120
121
 
121
122
  log(info, callback) {
122
- const messageInfo = info[MESSAGE];
123
- const infoSize = messageInfo.length;
123
+ const infoSize = Buffer.byteLength(info[MESSAGE]);
124
124
  let { level } = info;
125
125
  const { serverType } = globalThis;
126
126
  let { serverId } = globalThis;
127
- const data = JSON.parse(messageInfo);
127
+ const data = { ...info };
128
128
 
129
129
  if (serverType) {
130
130
  if (!serverId) serverId = `${UNKNOWN_ID}${CLIENTS}`;
@@ -143,7 +143,7 @@ export default class AwsKinesis extends Transport {
143
143
  levelData = events[level];
144
144
  }
145
145
  levelData.size += infoSize;
146
- levelData.Records.push({ Data: Buffer.from(JSON.stringify(data)), PartitionKey: `${PARTITION_KEY}-${randomInt(RANDOM_MIN, RANDOM_LIMIT)}` });
146
+ levelData.Records.push({ Data: Buffer.from(safeStringify(data)), PartitionKey: `${PARTITION_KEY}-${randomInt(RANDOM_MIN, RANDOM_LIMIT)}` });
147
147
  if (levelData.Records.length >= this.maxEvents || levelData.size >= this.maxSize) {
148
148
  this.send(levelData.Records, level);
149
149
  levelData.Records = [];
@@ -9,6 +9,7 @@ import {
9
9
  UNKNOWN_ID,
10
10
  UNKNOWN_TYPE,
11
11
  WARN,
12
+ safeStringify,
12
13
  } from './common.js';
13
14
  import {
14
15
  PutObjectCommand,
@@ -179,12 +180,11 @@ export default class AwsS3 extends Transport {
179
180
  }
180
181
 
181
182
  log(info, callback) {
182
- const messageInfo = info[MESSAGE];
183
- const infoSize = messageInfo.length;
183
+ const infoSize = Buffer.byteLength(info[MESSAGE]);
184
184
  const { level } = info;
185
185
  const { serverType } = globalThis;
186
186
  let { serverId } = globalThis;
187
- const data = JSON.parse(messageInfo);
187
+ const data = { ...info };
188
188
 
189
189
  if (serverType) {
190
190
  if (!serverId) serverId = `${UNKNOWN_ID}${CLIENTS}`;
@@ -210,7 +210,7 @@ export default class AwsS3 extends Transport {
210
210
  }
211
211
  typeLevelData.size += infoSize;
212
212
  typeLevelData.nbEvents += 1;
213
- serverData.push(data);
213
+ serverData.push(safeStringify(data));
214
214
  if (typeLevelData.nbEvents >= this.maxEvents || typeLevelData.size >= this.maxSize) {
215
215
  this.sendRemote(typeLevelData.data, level, new Date());
216
216
  typeLevelData.data = {};
@@ -228,7 +228,7 @@ export default class AwsS3 extends Transport {
228
228
  levelData = events[level];
229
229
  }
230
230
  levelData.size += infoSize;
231
- levelData.data.push(data);
231
+ levelData.data.push(safeStringify(data));
232
232
  if (levelData.data.length >= this.maxEvents || levelData.size >= this.maxSize) {
233
233
  this.send(levelData.data, level, new Date());
234
234
  levelData.data = [];
package/lib/common.js CHANGED
@@ -41,6 +41,18 @@ const OK_EXIT = 0;
41
41
  const MEGA = 1048576; // 2^20 conversion to mega
42
42
  const MILLI_MIN = 60000; // 1000*60 conversion to minute
43
43
 
44
+ const safeStringify = (obj) => {
45
+ const seen = new WeakSet();
46
+
47
+ return JSON.stringify(obj, (key, value) => {
48
+ if (typeof value === 'object' && value !== null) {
49
+ if (seen.has(value)) return '[Circular]';
50
+ seen.add(value);
51
+ }
52
+ return value;
53
+ });
54
+ };
55
+
44
56
  export {
45
57
  ALL_MODE,
46
58
  ALL_MODES,
@@ -75,4 +87,5 @@ export {
75
87
  UNKNOWN_TYPE,
76
88
  UNKNOWN_ID,
77
89
  WARN,
90
+ safeStringify,
78
91
  };
@@ -9,10 +9,10 @@ import {
9
9
  UNKNOWN_ID,
10
10
  UNKNOWN_TYPE,
11
11
  WARN,
12
+ safeStringify,
12
13
  } from './common.js';
13
14
  import Transport from 'winston-transport';
14
15
  import axios from 'axios';
15
- import { inspect } from 'node:util';
16
16
  import { setImmediate } from 'node:timers';
17
17
 
18
18
  export default class Sumo extends Transport {
@@ -28,7 +28,7 @@ export default class Sumo extends Transport {
28
28
  log(info, callback) {
29
29
  const { serverType } = globalThis;
30
30
  let { serverId } = globalThis;
31
- const data = info;
31
+ const data = { ...info };
32
32
 
33
33
  if (serverType) {
34
34
  if (!serverId) serverId = `${UNKNOWN_ID}${CLIENTS}`;
@@ -42,7 +42,7 @@ export default class Sumo extends Transport {
42
42
  axios({
43
43
  method: 'POST',
44
44
  url: `${this.endpoint}${this.code}`,
45
- data: inspect(data, { depth: null, compact: false }),
45
+ data: safeStringify(data),
46
46
  })
47
47
  .then(() => this.emit(LOG, { message: `logs sent to ${SUMOLOGIC}` }))
48
48
  .catch((err) => {
package/package.json CHANGED
@@ -1,9 +1,10 @@
1
1
  {
2
2
  "name": "@mimik/sumologic-winston-logger",
3
- "version": "2.1.10",
3
+ "version": "2.1.11",
4
4
  "description": "Log wrapper for sumo, s3, kinesis and winston",
5
5
  "main": "./index.js",
6
6
  "type": "module",
7
+ "exports": "./index.js",
7
8
  "engines": {
8
9
  "node": ">=24.0.0"
9
10
  },
@@ -15,12 +16,6 @@
15
16
  "prepublishOnly": "npm run docs && npm run lint && npm run test-ci",
16
17
  "commit-ready": "npm run docs && npm run lint && npm run test-ci"
17
18
  },
18
- "husky": {
19
- "hooks": {
20
- "pre-commit": "npm run commit-ready",
21
- "pre-push": "npm run test"
22
- }
23
- },
24
19
  "keywords": [
25
20
  "log",
26
21
  "logging",
@@ -36,9 +31,9 @@
36
31
  "url": "https://bitbucket.org/mimiktech/sumologic-winston-logger"
37
32
  },
38
33
  "dependencies": {
39
- "@mimik/lib-filters": "^2.0.5",
40
- "@aws-sdk/client-s3": "3.990.0",
41
- "@aws-sdk/client-kinesis": "3.990.0",
34
+ "@mimik/lib-filters": "^2.0.6",
35
+ "@aws-sdk/client-s3": "3.993.0",
36
+ "@aws-sdk/client-kinesis": "3.993.0",
42
37
  "@smithy/node-http-handler": "4.4.10",
43
38
  "axios": "1.13.5",
44
39
  "winston": "3.19.0",
@@ -47,7 +42,7 @@
47
42
  "devDependencies": {
48
43
  "@eslint/js": "9.39.2",
49
44
  "@mimik/eslint-plugin-document-env": "^2.0.8",
50
- "@mimik/request-helper": "^2.0.2",
45
+ "@mimik/request-helper": "^2.0.3",
51
46
  "@stylistic/eslint-plugin": "5.8.0",
52
47
  "aws-sdk-client-mock": "4.1.0",
53
48
  "c8": "10.1.3",
@@ -248,8 +248,8 @@ describe('S3 transport', function S3Tests() {
248
248
  calls.length.should.be.greaterThan(0);
249
249
  const payload = JSON.parse(calls[0].args[0].input.Body);
250
250
  payload.should.be.an('array').with.lengthOf(1);
251
- payload[0].should.have.property('message');
252
- payload[0].should.have.property('serverType', 'mTest');
251
+ JSON.parse(payload[0]).should.have.property('message');
252
+ JSON.parse(payload[0]).should.have.property('serverType', 'mTest');
253
253
  done();
254
254
  }, TEST_DELAY);
255
255
  });
@@ -261,7 +261,7 @@ describe('S3 transport', function S3Tests() {
261
261
  calls.length.should.be.greaterThan(0);
262
262
  const payload = JSON.parse(calls[0].args[0].input.Body);
263
263
  payload.should.be.an('array').with.lengthOf(1);
264
- payload[0].should.have.property('correlationId');
264
+ JSON.parse(payload[0]).should.have.property('correlationId');
265
265
  done();
266
266
  }, TEST_DELAY);
267
267
  });
@@ -299,8 +299,8 @@ describe('S3 remote transport', function S3RemoteTests() {
299
299
  calls.length.should.be.greaterThan(0);
300
300
  const payload = JSON.parse(calls[0].args[0].input.Body);
301
301
  payload.should.be.an('array');
302
- payload[0].should.have.property('serverType', 'mTestRemote');
303
- payload[0].should.have.property('serverId', 'remoteServerId');
302
+ JSON.parse(payload[0]).should.have.property('serverType', 'mTestRemote');
303
+ JSON.parse(payload[0]).should.have.property('serverId', 'remoteServerId');
304
304
  done();
305
305
  }, TEST_DELAY);
306
306
  });
@@ -441,6 +441,28 @@ describe('S3 transport error handling', function S3ErrorTests() {
441
441
  });
442
442
  });
443
443
 
444
+ describe('Circular reference handling', function CircularTests() {
445
+ this.timeout(START_TIMEOUT);
446
+ beforeEach(() => {
447
+ s3Mock.resetHistory();
448
+ kinesisMock.resetHistory();
449
+ });
450
+
451
+ it('handles logging objects with circular references', (done) => {
452
+ const circular = { name: 'test' };
453
+ circular.self = circular;
454
+ logger.info('test circular reference', circular);
455
+ setTimeout(() => {
456
+ const s3Calls = s3Mock.commandCalls(PutObjectCommand);
457
+ s3Calls.length.should.be.greaterThan(0);
458
+ const payload = JSON.parse(s3Calls[0].args[0].input.Body);
459
+ payload.should.be.an('array');
460
+ JSON.parse(payload[0]).should.have.property('message');
461
+ done();
462
+ }, TEST_DELAY);
463
+ });
464
+ });
465
+
444
466
  describe('Kinesis transport', function KinesisTests() {
445
467
  this.timeout(START_TIMEOUT);
446
468
  beforeEach(() => kinesisMock.resetHistory());
package/.nycrc DELETED
@@ -1,4 +0,0 @@
1
- {
2
- "exclude": ["gulpfile.js"],
3
- "reporter": ["lcov", "text"]
4
- }