@aws-amplify/core 4.4.1-cloud-logging.7 → 4.4.1-unstable.3

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.
Files changed (41) hide show
  1. package/dist/aws-amplify-core.js +103 -281
  2. package/dist/aws-amplify-core.js.map +1 -1
  3. package/dist/aws-amplify-core.min.js +6 -6
  4. package/dist/aws-amplify-core.min.js.map +1 -1
  5. package/lib/Logger/ConsoleLogger.d.ts +0 -6
  6. package/lib/Logger/ConsoleLogger.js +43 -117
  7. package/lib/Logger/ConsoleLogger.js.map +1 -1
  8. package/lib/Providers/AWSCloudWatchProvider.d.ts +3 -11
  9. package/lib/Providers/AWSCloudWatchProvider.js +37 -97
  10. package/lib/Providers/AWSCloudWatchProvider.js.map +1 -1
  11. package/lib/Util/Constants.d.ts +1 -3
  12. package/lib/Util/Constants.js +0 -5
  13. package/lib/Util/Constants.js.map +1 -1
  14. package/lib/Util/Retry.js +1 -1
  15. package/lib/Util/Retry.js.map +1 -1
  16. package/lib/types/types.d.ts +0 -13
  17. package/lib-esm/Logger/ConsoleLogger.d.ts +0 -6
  18. package/lib-esm/Logger/ConsoleLogger.js +43 -117
  19. package/lib-esm/Logger/ConsoleLogger.js.map +1 -1
  20. package/lib-esm/Providers/AWSCloudWatchProvider.d.ts +3 -11
  21. package/lib-esm/Providers/AWSCloudWatchProvider.js +37 -97
  22. package/lib-esm/Providers/AWSCloudWatchProvider.js.map +1 -1
  23. package/lib-esm/Util/Constants.d.ts +1 -3
  24. package/lib-esm/Util/Constants.js +1 -4
  25. package/lib-esm/Util/Constants.js.map +1 -1
  26. package/lib-esm/Util/Retry.js +1 -1
  27. package/lib-esm/Util/Retry.js.map +1 -1
  28. package/lib-esm/types/types.d.ts +0 -13
  29. package/package.json +2 -3
  30. package/src/Logger/ConsoleLogger.ts +34 -117
  31. package/src/Providers/AWSCloudWatchProvider.ts +18 -112
  32. package/src/Util/Constants.ts +0 -7
  33. package/src/Util/Retry.ts +3 -2
  34. package/src/types/types.ts +62 -79
  35. package/lib/Providers/AmazonKinesisLoggingProvider.d.ts +0 -13
  36. package/lib/Providers/AmazonKinesisLoggingProvider.js +0 -30
  37. package/lib/Providers/AmazonKinesisLoggingProvider.js.map +0 -1
  38. package/lib-esm/Providers/AmazonKinesisLoggingProvider.d.ts +0 -13
  39. package/lib-esm/Providers/AmazonKinesisLoggingProvider.js +0 -28
  40. package/lib-esm/Providers/AmazonKinesisLoggingProvider.js.map +0 -1
  41. package/src/Providers/AmazonKinesisLoggingProvider.ts +0 -43
@@ -1 +1 @@
1
- {"version":3,"file":"Constants.js","sourceRoot":"","sources":["../../src/Util/Constants.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,oBAAoB;AACpB,aAAa;AACb,IAAM,+BAA+B,GAAG,EAAE,CAAC;AAC3C,IAAM,mCAAmC,GAAG,OAAO,CAAC;AACpD,IAAM,6BAA6B,GAAG,MAAM,CAAC;AAC7C,IAAM,uBAAuB,GAAG,SAAS,CAAC;AAC1C,IAAM,4BAA4B,GAAG,eAAe,CAAC;AAErD,IAAM,+BAA+B,GAAG,gBAAgB,CAAC;AACzD,IAAM,oCAAoC,GAAG,sBAAsB,CAAC;AAEpE,IAAM,qBAAqB,GAAG,gBAAgB,CAAC;AAC/C,IAAM,iBAAiB,GAAG;IACzB,2BAA2B;IAC3B,+BAA+B;CAC/B,CAAC;AAEF,OAAO,EACN,+BAA+B,EAC/B,uBAAuB,EACvB,mCAAmC,EACnC,6BAA6B,EAC7B,4BAA4B,EAC5B,qBAAqB,EACrB,iBAAiB,EACjB,oCAAoC,EACpC,+BAA+B,GAC/B,CAAC"}
1
+ {"version":3,"file":"Constants.js","sourceRoot":"","sources":["../../src/Util/Constants.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,oBAAoB;AACpB,IAAM,+BAA+B,GAAG,EAAE,CAAC;AAC3C,IAAM,mCAAmC,GAAG,OAAO,CAAC;AACpD,IAAM,6BAA6B,GAAG,MAAM,CAAC;AAC7C,IAAM,uBAAuB,GAAG,SAAS,CAAC;AAC1C,IAAM,4BAA4B,GAAG,eAAe,CAAC;AACrD,IAAM,qBAAqB,GAAG,gBAAgB,CAAC;AAC/C,IAAM,iBAAiB,GAAG;IACzB,2BAA2B;IAC3B,+BAA+B;CAC/B,CAAC;AAEF,OAAO,EACN,+BAA+B,EAC/B,uBAAuB,EACvB,mCAAmC,EACnC,6BAA6B,EAC7B,4BAA4B,EAC5B,qBAAqB,EACrB,iBAAiB,GACjB,CAAC"}
@@ -97,7 +97,7 @@ export function retry(functionToRetry, args, delayFn, attempt) {
97
97
  if (typeof functionToRetry !== 'function') {
98
98
  throw Error('functionToRetry must be a function');
99
99
  }
100
- logger.debug(functionToRetry.name + " attempt #" + attempt + " with this vars:", args);
100
+ logger.debug(functionToRetry.name + " attempt #" + attempt + " with this vars: " + JSON.stringify(args));
101
101
  _a.label = 1;
102
102
  case 1:
103
103
  _a.trys.push([1, 3, , 8]);
@@ -1 +1 @@
1
- {"version":3,"file":"Retry.js","sourceRoot":"","sources":["../../src/Util/Retry.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,OAAO,EAAE,aAAa,IAAI,MAAM,EAAE,MAAM,yBAAyB,CAAC;AAClE,IAAM,MAAM,GAAG,IAAI,MAAM,CAAC,MAAM,CAAC,CAAC;AAElC;IAAuC,qCAAK;IAE3C,2BAAY,OAAe;QAA3B,YACC,kBAAM,OAAO,CAAC,SACd;QAHe,kBAAY,GAAG,IAAI,CAAC;;IAGpC,CAAC;IACF,wBAAC;AAAD,CAAC,AALD,CAAuC,KAAK,GAK3C;;AAED,IAAM,mBAAmB,GAAG,UAAC,GAAQ;IACpC,IAAM,GAAG,GAA4B,cAAc,CAAC;IACpD,OAAO,GAAG,IAAI,GAAG,CAAC,GAAG,CAAC,CAAC;AACxB,CAAC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G,GAAG,CAAC;IAE1B,OAAO,UAAA,OAAO;QACb,IAAM,KAAK,GAAG,SAAA,CAAC,EAAI,OAAO,CAAA,GAAG,YAAY,GAAG,aAAa,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC;QAC1E,OAAO,KAAK,GAAG,UAAU,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC;IAC3C,CAAC,CAAC;AACH,CAAC;AAED;;;GAGG;AACH,MAAM,CAAC,IAAM,wBAAwB,GAAG,UACvC,eAAyB,EACzB,IAAW,EACX,UAAiC;IAAjC,2BAAA,EAAA,yBAAiC;IAC7B,OAAA,KAAK,CAAC,eAAe,EAAE,IAAI,EAAE,eAAe,CAAC,UAAU,CAAC,CAAC;AAAzD,CAAyD,CAAC"}
@@ -28,8 +28,6 @@ export interface LoggingProvider {
28
28
  getCategoryName(): string;
29
29
  configure(config?: object): object;
30
30
  pushLogs(logs: InputLogEvent[]): void;
31
- pause(): void;
32
- resume(): void;
33
31
  }
34
32
  export interface AWSCloudWatchProviderOptions {
35
33
  logGroupName?: string;
@@ -38,19 +36,8 @@ export interface AWSCloudWatchProviderOptions {
38
36
  credentials?: Credentials;
39
37
  endpoint?: string;
40
38
  }
41
- export interface AmplifyConfigure {
42
- Logging: {
43
- logGroupName: string;
44
- logStreamName: string;
45
- };
46
- }
47
39
  export interface CloudWatchDataTracker {
48
40
  eventUploadInProgress: boolean;
49
41
  logEvents: InputLogEvent[];
50
42
  verifiedLogGroup?: LogGroup;
51
43
  }
52
- export interface AmazonKinesisLoggerOptions {
53
- region?: string;
54
- credentials?: Credentials;
55
- endpoint?: string;
56
- }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aws-amplify/core",
3
- "version": "4.4.1-cloud-logging.7+a219f0109",
3
+ "version": "4.4.1-unstable.3+1b188626a",
4
4
  "description": "Core category of aws-amplify",
5
5
  "main": "./lib/index.js",
6
6
  "module": "./lib-esm/index.js",
@@ -61,7 +61,6 @@
61
61
  "@aws-sdk/credential-provider-cognito-identity": "3.6.1",
62
62
  "@aws-sdk/types": "3.6.1",
63
63
  "@aws-sdk/util-hex-encoding": "3.6.1",
64
- "fast-text-encoding": "1.0.3",
65
64
  "universal-cookie": "^4.0.4",
66
65
  "zen-observable-ts": "0.8.19"
67
66
  },
@@ -109,5 +108,5 @@
109
108
  "lib-esm"
110
109
  ]
111
110
  },
112
- "gitHead": "a219f01098b90acc930fcbb9ffd4d6ed261ac6dd"
111
+ "gitHead": "1b188626afcc7f0f755ba449534236a38260e692"
113
112
  }
@@ -24,8 +24,6 @@ const LOG_LEVELS = {
24
24
  ERROR: 5,
25
25
  };
26
26
 
27
- const COMPATIBLE_PLUGINS = [AWS_CLOUDWATCH_CATEGORY];
28
-
29
27
  export enum LOG_TYPE {
30
28
  DEBUG = 'DEBUG',
31
29
  ERROR = 'ERROR',
@@ -34,14 +32,6 @@ export enum LOG_TYPE {
34
32
  VERBOSE = 'VERBOSE',
35
33
  }
36
34
 
37
- const cloudWatchExcludeList = [
38
- 'AWSCloudWatch',
39
- 'Amplify',
40
- 'Credentials',
41
- 'AuthClass',
42
- 'CloudLogger',
43
- ];
44
-
45
35
  /**
46
36
  * Write logs
47
37
  * @class Logger
@@ -51,7 +41,6 @@ export class ConsoleLogger implements Logger {
51
41
  level: LOG_TYPE | string;
52
42
  private _pluggables: LoggingProvider[];
53
43
  private _config: object;
54
- private static _globalpluggables: LoggingProvider[] = [];
55
44
 
56
45
  /**
57
46
  * @constructor
@@ -61,21 +50,9 @@ export class ConsoleLogger implements Logger {
61
50
  this.name = name;
62
51
  this.level = level;
63
52
  this._pluggables = [];
64
- this.addPluggable = this.addPluggable.bind(this);
65
53
  }
66
54
 
67
55
  static LOG_LEVEL = null;
68
- static CLOUD_LOG_LEVEL = null;
69
- static globalPluggables(pluggable: LoggingProvider) {
70
- if (pluggable && COMPATIBLE_PLUGINS.includes(pluggable.getCategoryName())) {
71
- ConsoleLogger._globalpluggables.push(pluggable);
72
- }
73
- }
74
-
75
- static clearGlobalPluggables() {
76
- ConsoleLogger._globalpluggables = [];
77
- }
78
- static connectivity;
79
56
 
80
57
  _padding(n) {
81
58
  return n < 10 ? '0' + n : '' + n;
@@ -100,19 +77,6 @@ export class ConsoleLogger implements Logger {
100
77
  return this._config;
101
78
  }
102
79
 
103
- _checkPluggables() {
104
- if (this._pluggables.length !== ConsoleLogger._globalpluggables.length) {
105
- if (ConsoleLogger._globalpluggables.length > 0) {
106
- ConsoleLogger._globalpluggables.forEach(this.addPluggable);
107
- return;
108
- }
109
-
110
- if (ConsoleLogger._globalpluggables.length === 0) {
111
- this._pluggables = [];
112
- }
113
- }
114
- }
115
-
116
80
  /**
117
81
  * Write log
118
82
  * @method
@@ -121,37 +85,6 @@ export class ConsoleLogger implements Logger {
121
85
  * @param {string|object} msg - Logging message or object
122
86
  */
123
87
  _log(type: LOG_TYPE | string, ...msg) {
124
- if (!cloudWatchExcludeList.includes(this.name)) {
125
- this._checkPluggables();
126
- }
127
-
128
- const generateCloudMessage = (msg: any[]) => {
129
- let message = '';
130
- let data;
131
-
132
- if (msg.length === 1 && typeof msg[0] === 'string') {
133
- message = msg[0];
134
- } else if (msg.length === 1) {
135
- data = msg[0];
136
- } else if (typeof msg[0] === 'string') {
137
- let obj = msg.slice(1);
138
- if (obj.length === 1) {
139
- obj = obj[0];
140
- }
141
- message = msg[0];
142
- data = obj;
143
- } else {
144
- data = msg;
145
- }
146
-
147
- return JSON.stringify({
148
- level: type,
149
- class: this.name,
150
- message,
151
- data,
152
- });
153
- };
154
-
155
88
  let logger_level_name = this.level;
156
89
  if (ConsoleLogger.LOG_LEVEL) {
157
90
  logger_level_name = ConsoleLogger.LOG_LEVEL;
@@ -161,60 +94,43 @@ export class ConsoleLogger implements Logger {
161
94
  }
162
95
  const logger_level = LOG_LEVELS[logger_level_name];
163
96
  const type_level = LOG_LEVELS[type];
164
- if (type_level >= logger_level) {
165
- let log = console.log.bind(console);
166
-
167
- if (type === LOG_TYPE.ERROR && console.error) {
168
- log = console.error.bind(console);
169
- }
170
- if (type === LOG_TYPE.WARN && console.warn) {
171
- log = console.warn.bind(console);
172
- }
97
+ if (!(type_level >= logger_level)) {
98
+ // Do nothing if type is not greater than or equal to logger level (handle undefined)
99
+ return;
100
+ }
173
101
 
174
- const prefix = `[${type}] ${this._ts()} ${this.name}`;
175
- let message = '';
176
- let data;
102
+ let log = console.log.bind(console);
103
+ if (type === LOG_TYPE.ERROR && console.error) {
104
+ log = console.error.bind(console);
105
+ }
106
+ if (type === LOG_TYPE.WARN && console.warn) {
107
+ log = console.warn.bind(console);
108
+ }
177
109
 
178
- if (msg.length === 1 && typeof msg[0] === 'string') {
179
- message = msg[0];
180
- log(`${prefix} - ${message}`);
181
- } else if (msg.length === 1) {
182
- data = msg[0];
183
- log(prefix, data);
184
- } else if (typeof msg[0] === 'string') {
185
- let obj = msg.slice(1);
186
- if (obj.length === 1) {
187
- obj = obj[0];
188
- }
189
- message = msg[0];
190
- data = obj;
191
- log(`${prefix} - ${message}`, data);
192
- } else {
193
- data = msg;
194
- log(prefix, data);
110
+ const prefix = `[${type}] ${this._ts()} ${this.name}`;
111
+ let message = '';
112
+
113
+ if (msg.length === 1 && typeof msg[0] === 'string') {
114
+ message = `${prefix} - ${msg[0]}`;
115
+ log(message);
116
+ } else if (msg.length === 1) {
117
+ message = `${prefix} ${msg[0]}`;
118
+ log(prefix, msg[0]);
119
+ } else if (typeof msg[0] === 'string') {
120
+ let obj = msg.slice(1);
121
+ if (obj.length === 1) {
122
+ obj = obj[0];
195
123
  }
124
+ message = `${prefix} - ${msg[0]} ${obj}`;
125
+ log(`${prefix} - ${msg[0]}`, obj);
126
+ } else {
127
+ message = `${prefix} ${msg}`;
128
+ log(prefix, msg);
196
129
  }
197
130
 
198
- if (
199
- ConsoleLogger.CLOUD_LOG_LEVEL != null &&
200
- !cloudWatchExcludeList.includes(this.name)
201
- ) {
202
- const cloudMessage = generateCloudMessage(msg);
203
- for (const plugin of this._pluggables) {
204
- const logger_level = LOG_LEVELS[ConsoleLogger.CLOUD_LOG_LEVEL];
205
- const type_level = LOG_LEVELS[type];
206
-
207
- const logEvent: InputLogEvent = {
208
- message: cloudMessage,
209
- timestamp: Date.now(),
210
- };
211
-
212
- if (type_level >= logger_level) {
213
- plugin.pushLogs([logEvent]);
214
- } else {
215
- plugin.pushLogs([]);
216
- }
217
- }
131
+ for (const plugin of this._pluggables) {
132
+ const logEvent: InputLogEvent = { message, timestamp: Date.now() };
133
+ plugin.pushLogs([logEvent]);
218
134
  }
219
135
  }
220
136
 
@@ -279,8 +195,9 @@ export class ConsoleLogger implements Logger {
279
195
  }
280
196
 
281
197
  addPluggable(pluggable: LoggingProvider) {
282
- if (pluggable && COMPATIBLE_PLUGINS.includes(pluggable.getCategoryName())) {
198
+ if (pluggable && pluggable.getCategoryName() === AWS_CLOUDWATCH_CATEGORY) {
283
199
  this._pluggables.push(pluggable);
200
+ pluggable.configure(this._config);
284
201
  }
285
202
  }
286
203
 
@@ -39,7 +39,6 @@ import {
39
39
  AWSCloudWatchProviderOptions,
40
40
  CloudWatchDataTracker,
41
41
  LoggingProvider,
42
- AmplifyConfigure,
43
42
  } from '../types/types';
44
43
  import { Credentials } from '../..';
45
44
  import { ConsoleLogger as Logger } from '../Logger';
@@ -55,15 +54,8 @@ import {
55
54
  RETRY_ERROR_CODES,
56
55
  } from '../Util/Constants';
57
56
 
58
- if (
59
- typeof window === 'undefined' ||
60
- (typeof window === 'object' && !window.TextEncoder)
61
- ) {
62
- require('fast-text-encoding');
63
- }
64
-
65
57
  const logger = new Logger('AWSCloudWatch');
66
- const INTERVAL = 10000;
58
+
67
59
  class AWSCloudWatchProvider implements LoggingProvider {
68
60
  static readonly PROVIDER_NAME = AWS_CLOUDWATCH_PROVIDER_NAME;
69
61
  static readonly CATEGORY = AWS_CLOUDWATCH_CATEGORY;
@@ -73,25 +65,15 @@ class AWSCloudWatchProvider implements LoggingProvider {
73
65
  private _currentLogBatch: InputLogEvent[];
74
66
  private _timer;
75
67
  private _nextSequenceToken: string | undefined;
76
- private _processing: boolean;
77
- private _initialized = false;
78
- private _preFlightCheck: () => Promise<boolean>;
79
-
80
- constructor(config?: AmplifyConfigure) {
81
- console.log('cstr', config);
82
- if (!this._initialized) {
83
- this.configure(config);
84
-
85
- this._dataTracker = {
86
- eventUploadInProgress: false,
87
- logEvents: [],
88
- verifiedLogGroup: { logGroupName: this._config.logGroupName },
89
- };
90
68
 
91
- this._currentLogBatch = [];
92
- this._initiateLogPushInterval();
93
- this._initialized = true;
94
- }
69
+ constructor(config?: AWSCloudWatchProviderOptions) {
70
+ this.configure(config);
71
+ this._dataTracker = {
72
+ eventUploadInProgress: false,
73
+ logEvents: [],
74
+ };
75
+ this._currentLogBatch = [];
76
+ this._initiateLogPushInterval();
95
77
  }
96
78
 
97
79
  public getProviderName(): string {
@@ -106,13 +88,9 @@ class AWSCloudWatchProvider implements LoggingProvider {
106
88
  return this._dataTracker.logEvents;
107
89
  }
108
90
 
109
- public setPreFlightCheck(cb): void {
110
- if (typeof cb === 'function') {
111
- this._preFlightCheck = cb;
112
- }
113
- }
114
-
115
- public configure(config?: AmplifyConfigure): AWSCloudWatchProviderOptions {
91
+ public configure(
92
+ config?: AWSCloudWatchProviderOptions
93
+ ): AWSCloudWatchProviderOptions {
116
94
  if (!config) return this._config || {};
117
95
 
118
96
  const conf = Object.assign(
@@ -239,25 +217,8 @@ class AWSCloudWatchProvider implements LoggingProvider {
239
217
  }
240
218
 
241
219
  public pushLogs(logs: InputLogEvent[]): void {
242
- logger.debug('pushing log events to buffer');
243
- this._dataTracker.logEvents = this._dataTracker.logEvents.concat(logs);
244
- }
245
-
246
- public pause() {
247
- this._processing = false;
248
- if (this._timer) {
249
- clearInterval(this._timer);
250
- }
251
- }
252
-
253
- public resume() {
254
- this._processing = true;
255
- this._initiateLogPushInterval();
256
- }
257
-
258
- public clear() {
259
- this._dataTracker.logEvents = [];
260
- this._currentLogBatch = [];
220
+ logger.debug('pushing log events to Cloudwatch...');
221
+ this._dataTracker.logEvents = [...this._dataTracker.logEvents, ...logs];
261
222
  }
262
223
 
263
224
  private async _validateLogGroupExistsAndCreate(
@@ -433,11 +394,6 @@ class AWSCloudWatchProvider implements LoggingProvider {
433
394
  * We also need to ensure that the logs in the batch are sorted in chronological order.
434
395
  * https://docs.aws.amazon.com/AmazonCloudWatchLogs/latest/APIReference/API_PutLogEvents.html
435
396
  */
436
- if (!(await this._preFlightCheck())) {
437
- this.clear();
438
- return;
439
- }
440
-
441
397
  const seqToken = await this._getNextSequenceToken();
442
398
  const logBatch =
443
399
  this._currentLogBatch.length === 0
@@ -475,47 +431,6 @@ class AWSCloudWatchProvider implements LoggingProvider {
475
431
  }
476
432
  }
477
433
 
478
- private truncateOversizedEvent(event) {
479
- const { timestamp, message } = event;
480
- let messageJson;
481
- try {
482
- messageJson = JSON.parse(message);
483
-
484
- const truncated = JSON.stringify({
485
- level: messageJson.level,
486
- class: messageJson.class,
487
- message: messageJson.message.substring(0, 500),
488
- });
489
-
490
- if (messageJson.data != null) {
491
- truncated[
492
- 'data'
493
- ] = `OBJECT SIZE EXCEEDS CLOUDWATCH EVENT LIMIT. Truncated: ${JSON.stringify(
494
- messageJson.data
495
- ).substring(0, 500)}`;
496
- }
497
-
498
- return {
499
- timestamp,
500
- message: truncated,
501
- };
502
- } catch (error) {
503
- logger.warn('Could not minify oversized event', error);
504
-
505
- const truncated = JSON.stringify({
506
- level: 'UNKNOWN',
507
- class: 'Unknown',
508
- message:
509
- 'OBJECT SIZE EXCEEDS CLOUDWATCH EVENT LIMIT. Could not parse event to truncate',
510
- });
511
-
512
- return {
513
- timestamp,
514
- message: truncated,
515
- };
516
- }
517
- }
518
-
519
434
  private _getBufferedBatchOfLogs(): InputLogEvent[] {
520
435
  /**
521
436
  * CloudWatch has restrictions on the size of the log events that get sent up.
@@ -529,28 +444,20 @@ class AWSCloudWatchProvider implements LoggingProvider {
529
444
  let totalByteSize = 0;
530
445
 
531
446
  while (currentEventIdx < this._dataTracker.logEvents.length) {
532
- let currentEvent = this._dataTracker.logEvents[currentEventIdx];
533
-
534
- let eventSize = currentEvent
447
+ const currentEvent = this._dataTracker.logEvents[currentEventIdx];
448
+ const eventSize = currentEvent
535
449
  ? new TextEncoder().encode(currentEvent.message).length +
536
450
  AWS_CLOUDWATCH_BASE_BUFFER_SIZE
537
451
  : 0;
538
-
539
452
  if (eventSize > AWS_CLOUDWATCH_MAX_EVENT_SIZE) {
540
453
  const errString = `Log entry exceeds maximum size for CloudWatch logs. Log size: ${eventSize}. Truncating log message.`;
541
454
  logger.warn(errString);
542
455
 
543
- currentEvent = this.truncateOversizedEvent(currentEvent);
544
- this._dataTracker.logEvents[currentEventIdx] = currentEvent;
545
-
546
- eventSize =
547
- new TextEncoder().encode(currentEvent.message).length +
548
- AWS_CLOUDWATCH_BASE_BUFFER_SIZE;
456
+ currentEvent.message = currentEvent.message.substring(0, eventSize);
549
457
  }
550
458
 
551
459
  if (totalByteSize + eventSize > AWS_CLOUDWATCH_MAX_BATCH_EVENT_SIZE)
552
460
  break;
553
-
554
461
  totalByteSize += eventSize;
555
462
  currentEventIdx++;
556
463
  }
@@ -602,9 +509,8 @@ class AWSCloudWatchProvider implements LoggingProvider {
602
509
  logger.error(
603
510
  `error when calling _safeUploadLogEvents in the timer interval - ${err}`
604
511
  );
605
- this.pause();
606
512
  }
607
- }, INTERVAL);
513
+ }, 2000);
608
514
  }
609
515
 
610
516
  private _getDocUploadPermissibility(): boolean {
@@ -12,16 +12,11 @@
12
12
  */
13
13
 
14
14
  // Logging constants
15
- // Cloudwatch
16
15
  const AWS_CLOUDWATCH_BASE_BUFFER_SIZE = 26;
17
16
  const AWS_CLOUDWATCH_MAX_BATCH_EVENT_SIZE = 1048576;
18
17
  const AWS_CLOUDWATCH_MAX_EVENT_SIZE = 256000;
19
18
  const AWS_CLOUDWATCH_CATEGORY = 'Logging';
20
19
  const AWS_CLOUDWATCH_PROVIDER_NAME = 'AWSCloudWatch';
21
-
22
- const AMAZON_KINESIS_LOGGING_CATEGORY = 'KinesisLogging';
23
- const AMAZON_KINESIS_LOGGING_PROVIDER_NAME = 'AmazonKinesisLogging';
24
-
25
20
  const NO_CREDS_ERROR_STRING = 'No credentials';
26
21
  const RETRY_ERROR_CODES = [
27
22
  'ResourceNotFoundException',
@@ -36,6 +31,4 @@ export {
36
31
  AWS_CLOUDWATCH_PROVIDER_NAME,
37
32
  NO_CREDS_ERROR_STRING,
38
33
  RETRY_ERROR_CODES,
39
- AMAZON_KINESIS_LOGGING_PROVIDER_NAME,
40
- AMAZON_KINESIS_LOGGING_CATEGORY,
41
34
  };
package/src/Util/Retry.ts CHANGED
@@ -28,8 +28,9 @@ export async function retry(
28
28
  throw Error('functionToRetry must be a function');
29
29
  }
30
30
  logger.debug(
31
- `${functionToRetry.name} attempt #${attempt} with this vars:`,
32
- args
31
+ `${
32
+ functionToRetry.name
33
+ } attempt #${attempt} with this vars: ${JSON.stringify(args)}`
33
34
  );
34
35
 
35
36
  try {
@@ -1,79 +1,62 @@
1
- import { InputLogEvent, LogGroup } from '@aws-sdk/client-cloudwatch-logs';
2
- import { Credentials } from '@aws-sdk/types';
3
-
4
- export interface AmplifyConfig {
5
- Analytics?: object;
6
- Auth?: object;
7
- API?: object;
8
- Logging?: object;
9
- Storage?: object;
10
- Cache?: object;
11
- Geo?: object;
12
- ssr?: boolean;
13
- }
14
-
15
- export interface ICredentials {
16
- accessKeyId: string;
17
- sessionToken: string;
18
- secretAccessKey: string;
19
- identityId: string;
20
- authenticated: boolean;
21
- // Long term creds do not provide an expiration date
22
- expiration?: Date;
23
- }
24
-
25
- /**
26
- * @private
27
- * Internal use of Amplify only
28
- */
29
-
30
- export type DelayFunction = (
31
- attempt: number,
32
- args?: any[],
33
- error?: Error
34
- ) => number | false;
35
-
36
- export interface LoggingProvider {
37
- // return the name of you provider
38
- getProviderName(): string;
39
-
40
- // return the name of you category
41
- getCategoryName(): string;
42
-
43
- // configure the plugin
44
- configure(config?: object): object;
45
-
46
- // take logs and push to provider
47
- pushLogs(logs: InputLogEvent[]): void;
48
-
49
- // pause sending logs
50
- pause(): void;
51
- resume(): void;
52
- }
53
-
54
- export interface AWSCloudWatchProviderOptions {
55
- logGroupName?: string;
56
- logStreamName?: string;
57
- region?: string;
58
- credentials?: Credentials;
59
- endpoint?: string;
60
- }
61
-
62
- export interface AmplifyConfigure {
63
- Logging: {
64
- logGroupName: string;
65
- logStreamName: string;
66
- };
67
- }
68
-
69
- export interface CloudWatchDataTracker {
70
- eventUploadInProgress: boolean;
71
- logEvents: InputLogEvent[];
72
- verifiedLogGroup?: LogGroup;
73
- }
74
-
75
- export interface AmazonKinesisLoggerOptions {
76
- region?: string;
77
- credentials?: Credentials;
78
- endpoint?: string;
79
- }
1
+ import { InputLogEvent, LogGroup } from '@aws-sdk/client-cloudwatch-logs';
2
+ import { Credentials } from '@aws-sdk/types';
3
+
4
+ export interface AmplifyConfig {
5
+ Analytics?: object;
6
+ Auth?: object;
7
+ API?: object;
8
+ Logging?: object;
9
+ Storage?: object;
10
+ Cache?: object;
11
+ Geo?: object;
12
+ ssr?: boolean;
13
+ }
14
+
15
+ export interface ICredentials {
16
+ accessKeyId: string;
17
+ sessionToken: string;
18
+ secretAccessKey: string;
19
+ identityId: string;
20
+ authenticated: boolean;
21
+ // Long term creds do not provide an expiration date
22
+ expiration?: Date;
23
+ }
24
+
25
+ /**
26
+ * @private
27
+ * Internal use of Amplify only
28
+ */
29
+
30
+ export type DelayFunction = (
31
+ attempt: number,
32
+ args?: any[],
33
+ error?: Error
34
+ ) => number | false;
35
+
36
+ export interface LoggingProvider {
37
+ // return the name of you provider
38
+ getProviderName(): string;
39
+
40
+ // return the name of you category
41
+ getCategoryName(): string;
42
+
43
+ // configure the plugin
44
+ configure(config?: object): object;
45
+
46
+ // take logs and push to provider
47
+ pushLogs(logs: InputLogEvent[]): void;
48
+ }
49
+
50
+ export interface AWSCloudWatchProviderOptions {
51
+ logGroupName?: string;
52
+ logStreamName?: string;
53
+ region?: string;
54
+ credentials?: Credentials;
55
+ endpoint?: string;
56
+ }
57
+
58
+ export interface CloudWatchDataTracker {
59
+ eventUploadInProgress: boolean;
60
+ logEvents: InputLogEvent[];
61
+ verifiedLogGroup?: LogGroup;
62
+ }