dynamoose-logger 3.0.0-alpha.1 → 3.0.0-beta.8
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/emitter.js +2 -2
- package/lib/.eslintrc.js +5 -0
- package/lib/emitter.ts +54 -0
- package/lib/index.ts +7 -0
- package/lib/internal_providers/console.ts +23 -0
- package/lib/internal_providers/index.ts +5 -0
- package/lib/providers.ts +41 -0
- package/lib/status.ts +13 -0
- package/package.json +13 -68
- package/tsconfig.json +7 -0
package/dist/emitter.js
CHANGED
|
@@ -37,12 +37,12 @@ module.exports = (event) => {
|
|
|
37
37
|
}
|
|
38
38
|
}
|
|
39
39
|
if (provider.filter.category) {
|
|
40
|
-
if (!dynamoose_utils_1.wildcard_allowed_check(Array.isArray(provider.filter.category) ? provider.filter.category : [provider.filter.category], event.category, { "splitString": ":", "prefixesDisallowed": false })) {
|
|
40
|
+
if (!(0, dynamoose_utils_1.wildcard_allowed_check)(Array.isArray(provider.filter.category) ? provider.filter.category : [provider.filter.category], event.category, { "splitString": ":", "prefixesDisallowed": false })) {
|
|
41
41
|
return;
|
|
42
42
|
}
|
|
43
43
|
}
|
|
44
44
|
}
|
|
45
|
-
emitProvider.log(emitProvider.type === "string" ? event.message : Object.assign({ "id": uuid_1.v4(), "timestamp": ts, "metadata": {} }, event));
|
|
45
|
+
emitProvider.log(emitProvider.type === "string" ? event.message : Object.assign({ "id": (0, uuid_1.v4)(), "timestamp": ts, "metadata": {} }, event));
|
|
46
46
|
});
|
|
47
47
|
}
|
|
48
48
|
};
|
package/lib/.eslintrc.js
ADDED
package/lib/emitter.ts
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import status = require("./status");
|
|
2
|
+
import providers = require("./providers");
|
|
3
|
+
import {wildcard_allowed_check, CustomError} from "dynamoose-utils";
|
|
4
|
+
import {v4 as uuid} from "uuid";
|
|
5
|
+
|
|
6
|
+
const validLevels = ["fatal", "error", "warn", "info", "debug", "trace"];
|
|
7
|
+
|
|
8
|
+
export = (event): void => {
|
|
9
|
+
if (status.status() === "active") {
|
|
10
|
+
if (!event.message || !validLevels.includes(event.level)) {
|
|
11
|
+
throw new CustomError.InvalidParameter("You must pass in a valid message, level, and category into your event object.");
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
if (typeof event.category === "undefined" || event.category === null) {
|
|
15
|
+
event.category = "";
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const ts = new Date();
|
|
19
|
+
providers.list().forEach((provider) => {
|
|
20
|
+
const emitProvider = provider.provider || provider;
|
|
21
|
+
if (provider.filter) {
|
|
22
|
+
if (provider.filter.level) {
|
|
23
|
+
if (Array.isArray(provider.filter.level)) {
|
|
24
|
+
if (!provider.filter.level.includes(event.level)) {
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
} else {
|
|
28
|
+
if (provider.filter.level.endsWith("+") || provider.filter.level.endsWith("-")) {
|
|
29
|
+
const baseLevel = provider.filter.level.substring(0, provider.filter.level.length - 1);
|
|
30
|
+
const index = validLevels.findIndex((level) => level === baseLevel);
|
|
31
|
+
const newArray = validLevels.filter((a, i) => provider.filter.level.endsWith("+") ? i <= index : i >= index);
|
|
32
|
+
if (!newArray.includes(event.level)) {
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
} else if (provider.filter.level !== event.level) {
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
if (provider.filter.category) {
|
|
41
|
+
if (!wildcard_allowed_check(Array.isArray(provider.filter.category) ? provider.filter.category : [provider.filter.category], event.category, {"splitString": ":", "prefixesDisallowed": false})) {
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
emitProvider.log(emitProvider.type === "string" ? event.message : {
|
|
47
|
+
"id": uuid(),
|
|
48
|
+
"timestamp": ts,
|
|
49
|
+
"metadata": {},
|
|
50
|
+
...event
|
|
51
|
+
});
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
};
|
package/lib/index.ts
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export class ConsoleProvider {
|
|
2
|
+
log (message): void {
|
|
3
|
+
let method: (message: string) => void;
|
|
4
|
+
switch (message.level) {
|
|
5
|
+
case "fatal":
|
|
6
|
+
case "error":
|
|
7
|
+
method = console.error;
|
|
8
|
+
break;
|
|
9
|
+
case "warn":
|
|
10
|
+
method = console.warn;
|
|
11
|
+
break;
|
|
12
|
+
case "info":
|
|
13
|
+
method = console.info;
|
|
14
|
+
break;
|
|
15
|
+
case "debug":
|
|
16
|
+
case "trace":
|
|
17
|
+
method = console.log;
|
|
18
|
+
break;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
method(message.category ? `${message.category} - ${message.message}` : message.message);
|
|
22
|
+
}
|
|
23
|
+
}
|
package/lib/providers.ts
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import objectutils = require("js-object-utilities");
|
|
2
|
+
import internalProviders = require("./internal_providers");
|
|
3
|
+
let providers = [];
|
|
4
|
+
|
|
5
|
+
// This method takes the provider and converts it to an internal provider if exists (ex. `console`)
|
|
6
|
+
const normalizeProvider = (provider): any => {
|
|
7
|
+
if (provider === console) {
|
|
8
|
+
return new internalProviders.console();
|
|
9
|
+
} else {
|
|
10
|
+
return provider;
|
|
11
|
+
}
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
export = {
|
|
15
|
+
"set": (provider): void => {
|
|
16
|
+
if (typeof provider === "undefined" || provider === null) {
|
|
17
|
+
provider = [];
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
providers = (Array.isArray(provider) ? provider : [provider]).map(normalizeProvider);
|
|
21
|
+
},
|
|
22
|
+
"clear": (): void => {
|
|
23
|
+
providers = [];
|
|
24
|
+
},
|
|
25
|
+
"add": (provider): void => {
|
|
26
|
+
const newProviders = (Array.isArray(provider) ? provider : [provider]).map(normalizeProvider);
|
|
27
|
+
providers.push(...newProviders);
|
|
28
|
+
},
|
|
29
|
+
"delete": (id: string | string[]): void => {
|
|
30
|
+
const deleteFunction = (id: string): void => {
|
|
31
|
+
const index = providers.findIndex((provider) => provider.id === id);
|
|
32
|
+
objectutils.delete(providers, index);
|
|
33
|
+
};
|
|
34
|
+
if (Array.isArray(id)) {
|
|
35
|
+
id.forEach((id) => deleteFunction(id));
|
|
36
|
+
} else {
|
|
37
|
+
deleteFunction(id);
|
|
38
|
+
}
|
|
39
|
+
},
|
|
40
|
+
"list": (): any[] => providers
|
|
41
|
+
};
|
package/lib/status.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
let status = true; // Indicated if log events are being emitted to log providers or not
|
|
2
|
+
|
|
3
|
+
export = {
|
|
4
|
+
"pause": (): void => {
|
|
5
|
+
status = false;
|
|
6
|
+
},
|
|
7
|
+
"resume": (): void => {
|
|
8
|
+
status = true;
|
|
9
|
+
},
|
|
10
|
+
"status": (): "active" | "paused" => {
|
|
11
|
+
return status ? "active" : "paused";
|
|
12
|
+
}
|
|
13
|
+
};
|
package/package.json
CHANGED
|
@@ -1,63 +1,28 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dynamoose-logger",
|
|
3
|
-
"version": "3.0.0-
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "3.0.0-beta.8",
|
|
4
|
+
"description": "Dynamoose is a modeling tool for Amazon's DynamoDB (inspired by Mongoose)",
|
|
5
|
+
"homepage": "https://dynamoosejs.com",
|
|
5
6
|
"main": "dist/index.js",
|
|
6
7
|
"types": "dist/index.d.ts",
|
|
7
|
-
"scripts": {
|
|
8
|
-
"prepare": "npm run build:clean && npm run build",
|
|
9
|
-
"build": "tsc",
|
|
10
|
-
"build:sourcemap": "tsc --sourceMap",
|
|
11
|
-
"build:clean": "rimraf dist",
|
|
12
|
-
"build:watch": "npm run build -- -w",
|
|
13
|
-
"lint": "eslint . --ext .ts,.js --max-warnings 0",
|
|
14
|
-
"lint:fix": "npm run lint -- --fix"
|
|
15
|
-
},
|
|
16
8
|
"repository": {
|
|
17
9
|
"type": "git",
|
|
18
|
-
"url": "git+https://github.com/dynamoose/dynamoose
|
|
10
|
+
"url": "git+https://github.com/dynamoose/dynamoose.git"
|
|
19
11
|
},
|
|
20
12
|
"author": {
|
|
21
13
|
"name": "Charlie Fish",
|
|
22
14
|
"email": "fishcharlie.code@gmail.com",
|
|
23
15
|
"url": "https://charlie.fish"
|
|
24
16
|
},
|
|
25
|
-
"
|
|
26
|
-
|
|
27
|
-
"name": "Brandon Goode"
|
|
28
|
-
}
|
|
29
|
-
],
|
|
30
|
-
"license": "Unlicense",
|
|
31
|
-
"keywords": [
|
|
32
|
-
"dynamodb",
|
|
33
|
-
"dynamo",
|
|
34
|
-
"mongoose",
|
|
35
|
-
"aws",
|
|
36
|
-
"amazon",
|
|
37
|
-
"document",
|
|
38
|
-
"model",
|
|
39
|
-
"schema",
|
|
40
|
-
"database",
|
|
41
|
-
"data",
|
|
42
|
-
"datastore",
|
|
43
|
-
"query",
|
|
44
|
-
"scan",
|
|
45
|
-
"nosql",
|
|
46
|
-
"db",
|
|
47
|
-
"nosql",
|
|
48
|
-
"store",
|
|
49
|
-
"document store",
|
|
50
|
-
"table",
|
|
51
|
-
"json",
|
|
52
|
-
"object",
|
|
53
|
-
"storage"
|
|
54
|
-
],
|
|
55
|
-
"engines": {
|
|
56
|
-
"node": ">=10.0.0"
|
|
17
|
+
"scripts": {
|
|
18
|
+
"build": "tsc"
|
|
57
19
|
},
|
|
58
|
-
"
|
|
59
|
-
"
|
|
60
|
-
|
|
20
|
+
"dependencies": {
|
|
21
|
+
"dynamoose-utils": "^3.0.0-beta.8",
|
|
22
|
+
"js-object-utilities": "^2.1.0",
|
|
23
|
+
"uuid": "^8.3.2"
|
|
24
|
+
},
|
|
25
|
+
"license": "Unlicense",
|
|
61
26
|
"funding": [
|
|
62
27
|
{
|
|
63
28
|
"type": "github-sponsors",
|
|
@@ -68,25 +33,5 @@
|
|
|
68
33
|
"url": "https://opencollective.com/dynamoose"
|
|
69
34
|
}
|
|
70
35
|
],
|
|
71
|
-
"
|
|
72
|
-
"url": "https://github.com/dynamoose/dynamoose-logger/issues"
|
|
73
|
-
},
|
|
74
|
-
"homepage": "https://dynamoosejs.com",
|
|
75
|
-
"peerDependencies": {
|
|
76
|
-
"dynamoose": "^3.0.0-alpha.1"
|
|
77
|
-
},
|
|
78
|
-
"dependencies": {
|
|
79
|
-
"dynamoose-utils": "^3.0.0-alpha.1",
|
|
80
|
-
"js-object-utilities": "^2.0.0",
|
|
81
|
-
"uuid": "^8.3.2"
|
|
82
|
-
},
|
|
83
|
-
"devDependencies": {
|
|
84
|
-
"@types/node": "^14.14.35",
|
|
85
|
-
"@typescript-eslint/eslint-plugin": "^4.18.0",
|
|
86
|
-
"@typescript-eslint/parser": "^4.18.0",
|
|
87
|
-
"eslint": "^7.22.0",
|
|
88
|
-
"nyc": "^15.1.0",
|
|
89
|
-
"rimraf": "^3.0.2",
|
|
90
|
-
"typescript": "^4.2.3"
|
|
91
|
-
}
|
|
36
|
+
"gitHead": "d8455c3a245067a35ec829031db0da4e4f7562eb"
|
|
92
37
|
}
|