@aws-amplify/core 4.3.14 → 4.3.15-cloud-logging.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.
- package/dist/aws-amplify-core.js +248 -104
- package/dist/aws-amplify-core.js.map +1 -1
- package/dist/aws-amplify-core.min.js +6 -6
- package/dist/aws-amplify-core.min.js.map +1 -1
- package/lib/Hub.js +1 -0
- package/lib/Hub.js.map +1 -1
- package/lib/Logger/ConsoleLogger.d.ts +6 -0
- package/lib/Logger/ConsoleLogger.js +118 -43
- package/lib/Logger/ConsoleLogger.js.map +1 -1
- package/lib/Platform/version.d.ts +1 -1
- package/lib/Platform/version.js +1 -1
- package/lib/Providers/AWSCloudWatchProvider.d.ts +10 -3
- package/lib/Providers/AWSCloudWatchProvider.js +62 -36
- package/lib/Providers/AWSCloudWatchProvider.js.map +1 -1
- package/lib/Providers/AmazonKinesisLoggingProvider.d.ts +13 -0
- package/lib/Providers/AmazonKinesisLoggingProvider.js +30 -0
- package/lib/Providers/AmazonKinesisLoggingProvider.js.map +1 -0
- package/lib/Util/Constants.d.ts +3 -1
- package/lib/Util/Constants.js +5 -0
- package/lib/Util/Constants.js.map +1 -1
- package/lib/types/types.d.ts +13 -0
- package/lib-esm/Hub.js +1 -0
- package/lib-esm/Hub.js.map +1 -1
- package/lib-esm/Logger/ConsoleLogger.d.ts +6 -0
- package/lib-esm/Logger/ConsoleLogger.js +118 -43
- package/lib-esm/Logger/ConsoleLogger.js.map +1 -1
- package/lib-esm/Platform/version.d.ts +1 -1
- package/lib-esm/Platform/version.js +1 -1
- package/lib-esm/Providers/AWSCloudWatchProvider.d.ts +10 -3
- package/lib-esm/Providers/AWSCloudWatchProvider.js +62 -36
- package/lib-esm/Providers/AWSCloudWatchProvider.js.map +1 -1
- package/lib-esm/Providers/AmazonKinesisLoggingProvider.d.ts +13 -0
- package/lib-esm/Providers/AmazonKinesisLoggingProvider.js +28 -0
- package/lib-esm/Providers/AmazonKinesisLoggingProvider.js.map +1 -0
- package/lib-esm/Util/Constants.d.ts +3 -1
- package/lib-esm/Util/Constants.js +4 -1
- package/lib-esm/Util/Constants.js.map +1 -1
- package/lib-esm/types/types.d.ts +13 -0
- package/package.json +3 -2
- package/src/Hub.ts +1 -0
- package/src/Logger/ConsoleLogger.ts +119 -34
- package/src/Platform/version.ts +1 -1
- package/src/Providers/AWSCloudWatchProvider.ts +62 -15
- package/src/Providers/AmazonKinesisLoggingProvider.ts +43 -0
- package/src/Util/Constants.ts +7 -0
- package/src/types/types.ts +79 -62
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { ConsoleLogger as Logger } from '../Logger';
|
|
2
|
+
import { AMAZON_KINESIS_LOGGING_PROVIDER_NAME, AMAZON_KINESIS_LOGGING_CATEGORY, } from '../Util/Constants';
|
|
3
|
+
var logger = new Logger('AmazonKinesisLoggingProvider');
|
|
4
|
+
var AmazonKinesisLoggingProvider = /** @class */ (function () {
|
|
5
|
+
function AmazonKinesisLoggingProvider(config) {
|
|
6
|
+
}
|
|
7
|
+
AmazonKinesisLoggingProvider.prototype.getProviderName = function () {
|
|
8
|
+
return AmazonKinesisLoggingProvider.PROVIDER_NAME;
|
|
9
|
+
};
|
|
10
|
+
AmazonKinesisLoggingProvider.prototype.getCategoryName = function () {
|
|
11
|
+
return AmazonKinesisLoggingProvider.CATEGORY;
|
|
12
|
+
};
|
|
13
|
+
AmazonKinesisLoggingProvider.prototype.configure = function (config) {
|
|
14
|
+
if (!config)
|
|
15
|
+
return this._config || {};
|
|
16
|
+
return this._config;
|
|
17
|
+
};
|
|
18
|
+
AmazonKinesisLoggingProvider.prototype.pushLogs = function (logs) {
|
|
19
|
+
logger.debug('pushing log events to Kinesis...');
|
|
20
|
+
};
|
|
21
|
+
AmazonKinesisLoggingProvider.prototype.pause = function () { };
|
|
22
|
+
AmazonKinesisLoggingProvider.prototype.resume = function () { };
|
|
23
|
+
AmazonKinesisLoggingProvider.PROVIDER_NAME = AMAZON_KINESIS_LOGGING_PROVIDER_NAME;
|
|
24
|
+
AmazonKinesisLoggingProvider.CATEGORY = AMAZON_KINESIS_LOGGING_CATEGORY;
|
|
25
|
+
return AmazonKinesisLoggingProvider;
|
|
26
|
+
}());
|
|
27
|
+
export { AmazonKinesisLoggingProvider };
|
|
28
|
+
//# sourceMappingURL=AmazonKinesisLoggingProvider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AmazonKinesisLoggingProvider.js","sourceRoot":"","sources":["../../src/Providers/AmazonKinesisLoggingProvider.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,IAAI,MAAM,EAAE,MAAM,WAAW,CAAC;AACpD,OAAO,EACN,oCAAoC,EACpC,+BAA+B,GAG/B,MAAM,mBAAmB,CAAC;AAE3B,IAAM,MAAM,GAAG,IAAI,MAAM,CAAC,8BAA8B,CAAC,CAAC;AAE1D;IAMC,sCAAY,MAAmC;IAAG,CAAC;IAE5C,sDAAe,GAAtB;QACC,OAAO,4BAA4B,CAAC,aAAa,CAAC;IACnD,CAAC;IAEM,sDAAe,GAAtB;QACC,OAAO,4BAA4B,CAAC,QAAQ,CAAC;IAC9C,CAAC;IAEM,gDAAS,GAAhB,UACC,MAAmC;QAEnC,IAAI,CAAC,MAAM;YAAE,OAAO,IAAI,CAAC,OAAO,IAAI,EAAE,CAAC;QAEvC,OAAO,IAAI,CAAC,OAAO,CAAC;IACrB,CAAC;IAEM,+CAAQ,GAAf,UAAgB,IAAW;QAC1B,MAAM,CAAC,KAAK,CAAC,kCAAkC,CAAC,CAAC;IAClD,CAAC;IAEM,4CAAK,GAAZ,cAAgB,CAAC;IAEV,6CAAM,GAAb,cAAiB,CAAC;IA7BF,0CAAa,GAAG,oCAAoC,CAAC;IACrD,qCAAQ,GAAG,+BAA+B,CAAC;IA6B5D,mCAAC;CAAA,AA/BD,IA+BC;SA/BY,4BAA4B"}
|
|
@@ -3,6 +3,8 @@ declare const AWS_CLOUDWATCH_MAX_BATCH_EVENT_SIZE = 1048576;
|
|
|
3
3
|
declare const AWS_CLOUDWATCH_MAX_EVENT_SIZE = 256000;
|
|
4
4
|
declare const AWS_CLOUDWATCH_CATEGORY = "Logging";
|
|
5
5
|
declare const AWS_CLOUDWATCH_PROVIDER_NAME = "AWSCloudWatch";
|
|
6
|
+
declare const AMAZON_KINESIS_LOGGING_CATEGORY = "KinesisLogging";
|
|
7
|
+
declare const AMAZON_KINESIS_LOGGING_PROVIDER_NAME = "AmazonKinesisLogging";
|
|
6
8
|
declare const NO_CREDS_ERROR_STRING = "No credentials";
|
|
7
9
|
declare const RETRY_ERROR_CODES: string[];
|
|
8
|
-
export { AWS_CLOUDWATCH_BASE_BUFFER_SIZE, AWS_CLOUDWATCH_CATEGORY, AWS_CLOUDWATCH_MAX_BATCH_EVENT_SIZE, AWS_CLOUDWATCH_MAX_EVENT_SIZE, AWS_CLOUDWATCH_PROVIDER_NAME, NO_CREDS_ERROR_STRING, RETRY_ERROR_CODES, };
|
|
10
|
+
export { AWS_CLOUDWATCH_BASE_BUFFER_SIZE, AWS_CLOUDWATCH_CATEGORY, AWS_CLOUDWATCH_MAX_BATCH_EVENT_SIZE, AWS_CLOUDWATCH_MAX_EVENT_SIZE, AWS_CLOUDWATCH_PROVIDER_NAME, NO_CREDS_ERROR_STRING, RETRY_ERROR_CODES, AMAZON_KINESIS_LOGGING_PROVIDER_NAME, AMAZON_KINESIS_LOGGING_CATEGORY, };
|
|
@@ -11,15 +11,18 @@
|
|
|
11
11
|
* and limitations under the License.
|
|
12
12
|
*/
|
|
13
13
|
// Logging constants
|
|
14
|
+
// Cloudwatch
|
|
14
15
|
var AWS_CLOUDWATCH_BASE_BUFFER_SIZE = 26;
|
|
15
16
|
var AWS_CLOUDWATCH_MAX_BATCH_EVENT_SIZE = 1048576;
|
|
16
17
|
var AWS_CLOUDWATCH_MAX_EVENT_SIZE = 256000;
|
|
17
18
|
var AWS_CLOUDWATCH_CATEGORY = 'Logging';
|
|
18
19
|
var AWS_CLOUDWATCH_PROVIDER_NAME = 'AWSCloudWatch';
|
|
20
|
+
var AMAZON_KINESIS_LOGGING_CATEGORY = 'KinesisLogging';
|
|
21
|
+
var AMAZON_KINESIS_LOGGING_PROVIDER_NAME = 'AmazonKinesisLogging';
|
|
19
22
|
var NO_CREDS_ERROR_STRING = 'No credentials';
|
|
20
23
|
var RETRY_ERROR_CODES = [
|
|
21
24
|
'ResourceNotFoundException',
|
|
22
25
|
'InvalidSequenceTokenException',
|
|
23
26
|
];
|
|
24
|
-
export { AWS_CLOUDWATCH_BASE_BUFFER_SIZE, AWS_CLOUDWATCH_CATEGORY, AWS_CLOUDWATCH_MAX_BATCH_EVENT_SIZE, AWS_CLOUDWATCH_MAX_EVENT_SIZE, AWS_CLOUDWATCH_PROVIDER_NAME, NO_CREDS_ERROR_STRING, RETRY_ERROR_CODES, };
|
|
27
|
+
export { AWS_CLOUDWATCH_BASE_BUFFER_SIZE, AWS_CLOUDWATCH_CATEGORY, AWS_CLOUDWATCH_MAX_BATCH_EVENT_SIZE, AWS_CLOUDWATCH_MAX_EVENT_SIZE, AWS_CLOUDWATCH_PROVIDER_NAME, NO_CREDS_ERROR_STRING, RETRY_ERROR_CODES, AMAZON_KINESIS_LOGGING_PROVIDER_NAME, AMAZON_KINESIS_LOGGING_CATEGORY, };
|
|
25
28
|
//# sourceMappingURL=Constants.js.map
|
|
@@ -1 +1 @@
|
|
|
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;
|
|
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"}
|
package/lib-esm/types/types.d.ts
CHANGED
|
@@ -28,6 +28,8 @@ 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;
|
|
31
33
|
}
|
|
32
34
|
export interface AWSCloudWatchProviderOptions {
|
|
33
35
|
logGroupName?: string;
|
|
@@ -36,8 +38,19 @@ export interface AWSCloudWatchProviderOptions {
|
|
|
36
38
|
credentials?: Credentials;
|
|
37
39
|
endpoint?: string;
|
|
38
40
|
}
|
|
41
|
+
export interface AmplifyConfigure {
|
|
42
|
+
Logging: {
|
|
43
|
+
logGroupName: string;
|
|
44
|
+
logStreamName: string;
|
|
45
|
+
};
|
|
46
|
+
}
|
|
39
47
|
export interface CloudWatchDataTracker {
|
|
40
48
|
eventUploadInProgress: boolean;
|
|
41
49
|
logEvents: InputLogEvent[];
|
|
42
50
|
verifiedLogGroup?: LogGroup;
|
|
43
51
|
}
|
|
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.3.
|
|
3
|
+
"version": "4.3.15-cloud-logging.3+819a5a227",
|
|
4
4
|
"description": "Core category of aws-amplify",
|
|
5
5
|
"main": "./lib/index.js",
|
|
6
6
|
"module": "./lib-esm/index.js",
|
|
@@ -61,6 +61,7 @@
|
|
|
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",
|
|
64
65
|
"universal-cookie": "^4.0.4",
|
|
65
66
|
"zen-observable-ts": "0.8.19"
|
|
66
67
|
},
|
|
@@ -108,5 +109,5 @@
|
|
|
108
109
|
"lib-esm"
|
|
109
110
|
]
|
|
110
111
|
},
|
|
111
|
-
"gitHead": "
|
|
112
|
+
"gitHead": "819a5a2271232a709426c530bdfdc3a72c89addd"
|
|
112
113
|
}
|
package/src/Hub.ts
CHANGED
|
@@ -24,6 +24,8 @@ const LOG_LEVELS = {
|
|
|
24
24
|
ERROR: 5,
|
|
25
25
|
};
|
|
26
26
|
|
|
27
|
+
const COMPATIBLE_PLUGINS = [AWS_CLOUDWATCH_CATEGORY];
|
|
28
|
+
|
|
27
29
|
export enum LOG_TYPE {
|
|
28
30
|
DEBUG = 'DEBUG',
|
|
29
31
|
ERROR = 'ERROR',
|
|
@@ -32,6 +34,14 @@ export enum LOG_TYPE {
|
|
|
32
34
|
VERBOSE = 'VERBOSE',
|
|
33
35
|
}
|
|
34
36
|
|
|
37
|
+
const cloudWatchExcludeList = [
|
|
38
|
+
'AWSCloudWatch',
|
|
39
|
+
'Amplify',
|
|
40
|
+
'Credentials',
|
|
41
|
+
'AuthClass',
|
|
42
|
+
'CloudLogger',
|
|
43
|
+
];
|
|
44
|
+
|
|
35
45
|
/**
|
|
36
46
|
* Write logs
|
|
37
47
|
* @class Logger
|
|
@@ -41,6 +51,7 @@ export class ConsoleLogger implements Logger {
|
|
|
41
51
|
level: LOG_TYPE | string;
|
|
42
52
|
private _pluggables: LoggingProvider[];
|
|
43
53
|
private _config: object;
|
|
54
|
+
private static _globalpluggables: LoggingProvider[] = [];
|
|
44
55
|
|
|
45
56
|
/**
|
|
46
57
|
* @constructor
|
|
@@ -50,9 +61,21 @@ export class ConsoleLogger implements Logger {
|
|
|
50
61
|
this.name = name;
|
|
51
62
|
this.level = level;
|
|
52
63
|
this._pluggables = [];
|
|
64
|
+
this.addPluggable = this.addPluggable.bind(this);
|
|
53
65
|
}
|
|
54
66
|
|
|
55
67
|
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;
|
|
56
79
|
|
|
57
80
|
_padding(n) {
|
|
58
81
|
return n < 10 ? '0' + n : '' + n;
|
|
@@ -77,6 +100,19 @@ export class ConsoleLogger implements Logger {
|
|
|
77
100
|
return this._config;
|
|
78
101
|
}
|
|
79
102
|
|
|
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
|
+
|
|
80
116
|
/**
|
|
81
117
|
* Write log
|
|
82
118
|
* @method
|
|
@@ -85,6 +121,39 @@ export class ConsoleLogger implements Logger {
|
|
|
85
121
|
* @param {string|object} msg - Logging message or object
|
|
86
122
|
*/
|
|
87
123
|
_log(type: LOG_TYPE | string, ...msg) {
|
|
124
|
+
if (!cloudWatchExcludeList.includes(this.name)) {
|
|
125
|
+
this._checkPluggables();
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
const generateMessage = (msg: any[]): void => {};
|
|
129
|
+
|
|
130
|
+
const generateCloudMessage = (msg: any[]) => {
|
|
131
|
+
let message = '';
|
|
132
|
+
let data;
|
|
133
|
+
|
|
134
|
+
if (msg.length === 1 && typeof msg[0] === 'string') {
|
|
135
|
+
message = msg[0];
|
|
136
|
+
} else if (msg.length === 1) {
|
|
137
|
+
data = msg[0];
|
|
138
|
+
} else if (typeof msg[0] === 'string') {
|
|
139
|
+
let obj = msg.slice(1);
|
|
140
|
+
if (obj.length === 1) {
|
|
141
|
+
obj = obj[0];
|
|
142
|
+
}
|
|
143
|
+
message = msg[0];
|
|
144
|
+
data = obj;
|
|
145
|
+
} else {
|
|
146
|
+
data = msg;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
return JSON.stringify({
|
|
150
|
+
level: type,
|
|
151
|
+
class: this.name,
|
|
152
|
+
message,
|
|
153
|
+
data,
|
|
154
|
+
});
|
|
155
|
+
};
|
|
156
|
+
|
|
88
157
|
let logger_level_name = this.level;
|
|
89
158
|
if (ConsoleLogger.LOG_LEVEL) {
|
|
90
159
|
logger_level_name = ConsoleLogger.LOG_LEVEL;
|
|
@@ -94,43 +163,60 @@ export class ConsoleLogger implements Logger {
|
|
|
94
163
|
}
|
|
95
164
|
const logger_level = LOG_LEVELS[logger_level_name];
|
|
96
165
|
const type_level = LOG_LEVELS[type];
|
|
97
|
-
if (
|
|
98
|
-
|
|
99
|
-
return;
|
|
100
|
-
}
|
|
166
|
+
if (type_level >= logger_level) {
|
|
167
|
+
let log = console.log.bind(console);
|
|
101
168
|
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
169
|
+
if (type === LOG_TYPE.ERROR && console.error) {
|
|
170
|
+
log = console.error.bind(console);
|
|
171
|
+
}
|
|
172
|
+
if (type === LOG_TYPE.WARN && console.warn) {
|
|
173
|
+
log = console.warn.bind(console);
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
const prefix = `[${type}] ${this._ts()} ${this.name}`;
|
|
177
|
+
let message = '';
|
|
178
|
+
let data;
|
|
109
179
|
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
180
|
+
if (msg.length === 1 && typeof msg[0] === 'string') {
|
|
181
|
+
message = msg[0];
|
|
182
|
+
log(`${prefix} - ${message}`);
|
|
183
|
+
} else if (msg.length === 1) {
|
|
184
|
+
data = msg[0];
|
|
185
|
+
log(prefix, data);
|
|
186
|
+
} else if (typeof msg[0] === 'string') {
|
|
187
|
+
let obj = msg.slice(1);
|
|
188
|
+
if (obj.length === 1) {
|
|
189
|
+
obj = obj[0];
|
|
190
|
+
}
|
|
191
|
+
message = msg[0];
|
|
192
|
+
data = obj;
|
|
193
|
+
log(`${prefix} - ${message}`, data);
|
|
194
|
+
} else {
|
|
195
|
+
data = msg;
|
|
196
|
+
log(prefix, data);
|
|
123
197
|
}
|
|
124
|
-
message = `${prefix} - ${msg[0]} ${obj}`;
|
|
125
|
-
log(`${prefix} - ${msg[0]}`, obj);
|
|
126
|
-
} else {
|
|
127
|
-
message = `${prefix} ${msg}`;
|
|
128
|
-
log(prefix, msg);
|
|
129
198
|
}
|
|
130
199
|
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
200
|
+
if (
|
|
201
|
+
ConsoleLogger.CLOUD_LOG_LEVEL != null &&
|
|
202
|
+
!cloudWatchExcludeList.includes(this.name)
|
|
203
|
+
) {
|
|
204
|
+
const cloudMessage = generateCloudMessage(msg);
|
|
205
|
+
for (const plugin of this._pluggables) {
|
|
206
|
+
const logger_level = LOG_LEVELS[ConsoleLogger.CLOUD_LOG_LEVEL];
|
|
207
|
+
const type_level = LOG_LEVELS[type];
|
|
208
|
+
|
|
209
|
+
const logEvent: InputLogEvent = {
|
|
210
|
+
message: cloudMessage,
|
|
211
|
+
timestamp: Date.now(),
|
|
212
|
+
};
|
|
213
|
+
|
|
214
|
+
if (type_level >= logger_level) {
|
|
215
|
+
plugin.pushLogs([logEvent]);
|
|
216
|
+
} else {
|
|
217
|
+
plugin.pushLogs([]);
|
|
218
|
+
}
|
|
219
|
+
}
|
|
134
220
|
}
|
|
135
221
|
}
|
|
136
222
|
|
|
@@ -195,9 +281,8 @@ export class ConsoleLogger implements Logger {
|
|
|
195
281
|
}
|
|
196
282
|
|
|
197
283
|
addPluggable(pluggable: LoggingProvider) {
|
|
198
|
-
if (pluggable && pluggable.getCategoryName()
|
|
284
|
+
if (pluggable && COMPATIBLE_PLUGINS.includes(pluggable.getCategoryName())) {
|
|
199
285
|
this._pluggables.push(pluggable);
|
|
200
|
-
pluggable.configure(this._config);
|
|
201
286
|
}
|
|
202
287
|
}
|
|
203
288
|
|
package/src/Platform/version.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// generated by genversion
|
|
2
|
-
export const version = '4.3.
|
|
2
|
+
export const version = '4.3.14';
|
|
@@ -39,6 +39,7 @@ import {
|
|
|
39
39
|
AWSCloudWatchProviderOptions,
|
|
40
40
|
CloudWatchDataTracker,
|
|
41
41
|
LoggingProvider,
|
|
42
|
+
AmplifyConfigure,
|
|
42
43
|
} from '../types/types';
|
|
43
44
|
import { Credentials } from '../..';
|
|
44
45
|
import { ConsoleLogger as Logger } from '../Logger';
|
|
@@ -54,8 +55,15 @@ import {
|
|
|
54
55
|
RETRY_ERROR_CODES,
|
|
55
56
|
} from '../Util/Constants';
|
|
56
57
|
|
|
57
|
-
|
|
58
|
+
if (
|
|
59
|
+
typeof window === 'undefined' ||
|
|
60
|
+
(typeof window === 'object' && !window.TextEncoder)
|
|
61
|
+
) {
|
|
62
|
+
require('fast-text-encoding');
|
|
63
|
+
}
|
|
58
64
|
|
|
65
|
+
const logger = new Logger('AWSCloudWatch');
|
|
66
|
+
const INTERVAL = 30000;
|
|
59
67
|
class AWSCloudWatchProvider implements LoggingProvider {
|
|
60
68
|
static readonly PROVIDER_NAME = AWS_CLOUDWATCH_PROVIDER_NAME;
|
|
61
69
|
static readonly CATEGORY = AWS_CLOUDWATCH_CATEGORY;
|
|
@@ -65,17 +73,29 @@ class AWSCloudWatchProvider implements LoggingProvider {
|
|
|
65
73
|
private _currentLogBatch: InputLogEvent[];
|
|
66
74
|
private _timer;
|
|
67
75
|
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
|
+
};
|
|
68
90
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
logEvents: [],
|
|
74
|
-
};
|
|
75
|
-
this._currentLogBatch = [];
|
|
76
|
-
this._initiateLogPushInterval();
|
|
91
|
+
this._currentLogBatch = [];
|
|
92
|
+
this._initiateLogPushInterval();
|
|
93
|
+
this._initialized = true;
|
|
94
|
+
}
|
|
77
95
|
}
|
|
78
96
|
|
|
97
|
+
// public static instance: AWSCloudWatchProvider;
|
|
98
|
+
|
|
79
99
|
public getProviderName(): string {
|
|
80
100
|
return AWSCloudWatchProvider.PROVIDER_NAME;
|
|
81
101
|
}
|
|
@@ -88,9 +108,13 @@ class AWSCloudWatchProvider implements LoggingProvider {
|
|
|
88
108
|
return this._dataTracker.logEvents;
|
|
89
109
|
}
|
|
90
110
|
|
|
91
|
-
public
|
|
92
|
-
|
|
93
|
-
|
|
111
|
+
public setPreFlightCheck(cb): void {
|
|
112
|
+
if (typeof cb === 'function') {
|
|
113
|
+
this._preFlightCheck = cb;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
public configure(config?: AmplifyConfigure): AWSCloudWatchProviderOptions {
|
|
94
118
|
if (!config) return this._config || {};
|
|
95
119
|
|
|
96
120
|
const conf = Object.assign(
|
|
@@ -217,8 +241,25 @@ class AWSCloudWatchProvider implements LoggingProvider {
|
|
|
217
241
|
}
|
|
218
242
|
|
|
219
243
|
public pushLogs(logs: InputLogEvent[]): void {
|
|
220
|
-
logger.debug('pushing log events to Cloudwatch
|
|
221
|
-
this._dataTracker.logEvents =
|
|
244
|
+
logger.debug('pushing log events to Cloudwatch buffer');
|
|
245
|
+
this._dataTracker.logEvents = this._dataTracker.logEvents.concat(logs);
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
public pause() {
|
|
249
|
+
this._processing = false;
|
|
250
|
+
if (this._timer) {
|
|
251
|
+
clearInterval(this._timer);
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
public resume() {
|
|
256
|
+
this._processing = true;
|
|
257
|
+
this._initiateLogPushInterval();
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
public clear() {
|
|
261
|
+
this._dataTracker.logEvents = [];
|
|
262
|
+
this._currentLogBatch = [];
|
|
222
263
|
}
|
|
223
264
|
|
|
224
265
|
private async _validateLogGroupExistsAndCreate(
|
|
@@ -394,6 +435,11 @@ class AWSCloudWatchProvider implements LoggingProvider {
|
|
|
394
435
|
* We also need to ensure that the logs in the batch are sorted in chronological order.
|
|
395
436
|
* https://docs.aws.amazon.com/AmazonCloudWatchLogs/latest/APIReference/API_PutLogEvents.html
|
|
396
437
|
*/
|
|
438
|
+
if (!(await this._preFlightCheck())) {
|
|
439
|
+
this.clear();
|
|
440
|
+
return;
|
|
441
|
+
}
|
|
442
|
+
|
|
397
443
|
const seqToken = await this._getNextSequenceToken();
|
|
398
444
|
const logBatch =
|
|
399
445
|
this._currentLogBatch.length === 0
|
|
@@ -509,8 +555,9 @@ class AWSCloudWatchProvider implements LoggingProvider {
|
|
|
509
555
|
logger.error(
|
|
510
556
|
`error when calling _safeUploadLogEvents in the timer interval - ${err}`
|
|
511
557
|
);
|
|
558
|
+
this.pause();
|
|
512
559
|
}
|
|
513
|
-
},
|
|
560
|
+
}, INTERVAL);
|
|
514
561
|
}
|
|
515
562
|
|
|
516
563
|
private _getDocUploadPermissibility(): boolean {
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { AmazonKinesisLoggerOptions, LoggingProvider } from '../types/types';
|
|
2
|
+
import { ConsoleLogger as Logger } from '../Logger';
|
|
3
|
+
import {
|
|
4
|
+
AMAZON_KINESIS_LOGGING_PROVIDER_NAME,
|
|
5
|
+
AMAZON_KINESIS_LOGGING_CATEGORY,
|
|
6
|
+
NO_CREDS_ERROR_STRING,
|
|
7
|
+
RETRY_ERROR_CODES,
|
|
8
|
+
} from '../Util/Constants';
|
|
9
|
+
|
|
10
|
+
const logger = new Logger('AmazonKinesisLoggingProvider');
|
|
11
|
+
|
|
12
|
+
export class AmazonKinesisLoggingProvider implements LoggingProvider {
|
|
13
|
+
static readonly PROVIDER_NAME = AMAZON_KINESIS_LOGGING_PROVIDER_NAME;
|
|
14
|
+
static readonly CATEGORY = AMAZON_KINESIS_LOGGING_CATEGORY;
|
|
15
|
+
|
|
16
|
+
private _config: AmazonKinesisLoggerOptions;
|
|
17
|
+
|
|
18
|
+
constructor(config?: AmazonKinesisLoggerOptions) {}
|
|
19
|
+
|
|
20
|
+
public getProviderName(): string {
|
|
21
|
+
return AmazonKinesisLoggingProvider.PROVIDER_NAME;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
public getCategoryName(): string {
|
|
25
|
+
return AmazonKinesisLoggingProvider.CATEGORY;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
public configure(
|
|
29
|
+
config?: AmazonKinesisLoggerOptions
|
|
30
|
+
): AmazonKinesisLoggerOptions {
|
|
31
|
+
if (!config) return this._config || {};
|
|
32
|
+
|
|
33
|
+
return this._config;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
public pushLogs(logs: any[]): void {
|
|
37
|
+
logger.debug('pushing log events to Kinesis...');
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
public pause() {}
|
|
41
|
+
|
|
42
|
+
public resume() {}
|
|
43
|
+
}
|
package/src/Util/Constants.ts
CHANGED
|
@@ -12,11 +12,16 @@
|
|
|
12
12
|
*/
|
|
13
13
|
|
|
14
14
|
// Logging constants
|
|
15
|
+
// Cloudwatch
|
|
15
16
|
const AWS_CLOUDWATCH_BASE_BUFFER_SIZE = 26;
|
|
16
17
|
const AWS_CLOUDWATCH_MAX_BATCH_EVENT_SIZE = 1048576;
|
|
17
18
|
const AWS_CLOUDWATCH_MAX_EVENT_SIZE = 256000;
|
|
18
19
|
const AWS_CLOUDWATCH_CATEGORY = 'Logging';
|
|
19
20
|
const AWS_CLOUDWATCH_PROVIDER_NAME = 'AWSCloudWatch';
|
|
21
|
+
|
|
22
|
+
const AMAZON_KINESIS_LOGGING_CATEGORY = 'KinesisLogging';
|
|
23
|
+
const AMAZON_KINESIS_LOGGING_PROVIDER_NAME = 'AmazonKinesisLogging';
|
|
24
|
+
|
|
20
25
|
const NO_CREDS_ERROR_STRING = 'No credentials';
|
|
21
26
|
const RETRY_ERROR_CODES = [
|
|
22
27
|
'ResourceNotFoundException',
|
|
@@ -31,4 +36,6 @@ export {
|
|
|
31
36
|
AWS_CLOUDWATCH_PROVIDER_NAME,
|
|
32
37
|
NO_CREDS_ERROR_STRING,
|
|
33
38
|
RETRY_ERROR_CODES,
|
|
39
|
+
AMAZON_KINESIS_LOGGING_PROVIDER_NAME,
|
|
40
|
+
AMAZON_KINESIS_LOGGING_CATEGORY,
|
|
34
41
|
};
|