mynth-logger 1.0.13 → 1.0.14
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/.eslintignore +1 -0
- package/.eslintrc.json +68 -0
- package/.github/workflows/CI.yaml +13 -4
- package/.github/workflows/npm-publish.yml +16 -3
- package/dist/src/index.js +22 -15
- package/package.json +6 -4
- package/src/index.ts +24 -17
package/.eslintignore
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
dist
|
package/.eslintrc.json
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
{
|
|
2
|
+
"parser": "@typescript-eslint/parser",
|
|
3
|
+
"extends": [
|
|
4
|
+
"eslint:recommended",
|
|
5
|
+
"plugin:ava/recommended",
|
|
6
|
+
"plugin:@typescript-eslint/recommended",
|
|
7
|
+
"plugin:import/errors",
|
|
8
|
+
"plugin:import/warnings",
|
|
9
|
+
"plugin:import/typescript"
|
|
10
|
+
],
|
|
11
|
+
"plugins": [
|
|
12
|
+
"ava",
|
|
13
|
+
"import",
|
|
14
|
+
"@typescript-eslint",
|
|
15
|
+
"file-extension-in-import-ts"
|
|
16
|
+
],
|
|
17
|
+
"settings": {
|
|
18
|
+
"import/resolver": {
|
|
19
|
+
"node": {
|
|
20
|
+
"paths": ["src"]
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
"rules": {
|
|
25
|
+
"padding-line-between-statements": [
|
|
26
|
+
"error",
|
|
27
|
+
{ "blankLine": "always", "prev": "*", "next": "block" },
|
|
28
|
+
{ "blankLine": "always", "prev": "block", "next": "*" },
|
|
29
|
+
{ "blankLine": "always", "prev": "*", "next": "block-like" },
|
|
30
|
+
{ "blankLine": "always", "prev": "block-like", "next": "*" }
|
|
31
|
+
],
|
|
32
|
+
"@typescript-eslint/no-unused-vars": [
|
|
33
|
+
"warn",
|
|
34
|
+
{
|
|
35
|
+
"argsIgnorePattern": "^_",
|
|
36
|
+
"varsIgnorePattern": "^_",
|
|
37
|
+
"caughtErrorsIgnorePattern": "^_"
|
|
38
|
+
}
|
|
39
|
+
],
|
|
40
|
+
"@typescript-eslint/naming-convention": [
|
|
41
|
+
"error",
|
|
42
|
+
{
|
|
43
|
+
"selector": ["parameter", "variable"],
|
|
44
|
+
"leadingUnderscore": "forbid",
|
|
45
|
+
"format": null
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
"selector": "parameter",
|
|
49
|
+
"leadingUnderscore": "require",
|
|
50
|
+
"format": null,
|
|
51
|
+
"modifiers": ["unused"]
|
|
52
|
+
}
|
|
53
|
+
],
|
|
54
|
+
"no-constant-condition": "off",
|
|
55
|
+
"file-extension-in-import-ts/file-extension-in-import-ts": "error",
|
|
56
|
+
"import/no-unresolved": ["error", { "ignore": ["\\.js$"] }],
|
|
57
|
+
"no-restricted-imports": ["error", { "patterns": ["src/*"] }]
|
|
58
|
+
},
|
|
59
|
+
"overrides": [
|
|
60
|
+
{
|
|
61
|
+
"files": ["tests/**/*.ts"],
|
|
62
|
+
"rules": {
|
|
63
|
+
"import/no-unresolved": "off",
|
|
64
|
+
"file-extension-in-import-ts/file-extension-in-import-ts": "off"
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
]
|
|
68
|
+
}
|
|
@@ -17,10 +17,11 @@ jobs:
|
|
|
17
17
|
- name: Set up Node.js
|
|
18
18
|
uses: actions/setup-node@v3
|
|
19
19
|
with:
|
|
20
|
-
node-version: 18
|
|
20
|
+
node-version: 18
|
|
21
|
+
check-latest: true
|
|
21
22
|
|
|
22
23
|
- name: Update npm
|
|
23
|
-
run: npm install -g npm@
|
|
24
|
+
run: npm install -g npm@latest
|
|
24
25
|
|
|
25
26
|
- name: Install dependencies
|
|
26
27
|
run: npm ci --include dev
|
|
@@ -39,7 +40,11 @@ jobs:
|
|
|
39
40
|
- name: Set up Node.js
|
|
40
41
|
uses: actions/setup-node@v3
|
|
41
42
|
with:
|
|
42
|
-
node-version: 18
|
|
43
|
+
node-version: 18
|
|
44
|
+
check-latest: true
|
|
45
|
+
|
|
46
|
+
- name: Update npm
|
|
47
|
+
run: npm install -g npm@latest
|
|
43
48
|
|
|
44
49
|
- name: Install dependencies
|
|
45
50
|
run: npm install --include dev
|
|
@@ -58,7 +63,11 @@ jobs:
|
|
|
58
63
|
- name: Set up Node.js
|
|
59
64
|
uses: actions/setup-node@v3
|
|
60
65
|
with:
|
|
61
|
-
node-version: 18
|
|
66
|
+
node-version: 18
|
|
67
|
+
check-latest: true
|
|
68
|
+
|
|
69
|
+
- name: Update npm
|
|
70
|
+
run: npm install -g npm@latest
|
|
62
71
|
|
|
63
72
|
- name: Install dependencies
|
|
64
73
|
run: npm install --include dev
|
|
@@ -16,21 +16,34 @@ jobs:
|
|
|
16
16
|
ref: ${{ github.head_ref }}
|
|
17
17
|
fetch-depth: 0
|
|
18
18
|
token: ${{ secrets.PAT }}
|
|
19
|
+
|
|
19
20
|
- uses: actions/setup-node@v3
|
|
20
21
|
with:
|
|
21
|
-
node-version: 18
|
|
22
|
+
node-version: 18
|
|
23
|
+
check-latest: true
|
|
22
24
|
registry-url: https://registry.npmjs.org/
|
|
23
|
-
|
|
24
|
-
-
|
|
25
|
+
|
|
26
|
+
- name: Update npm
|
|
27
|
+
run: npm install -g npm@latest
|
|
28
|
+
|
|
29
|
+
- name: Install dependencies
|
|
30
|
+
run: npm ci --include dev
|
|
31
|
+
|
|
32
|
+
- name: Build
|
|
33
|
+
run: npm run build
|
|
34
|
+
|
|
25
35
|
- name: Git configuration
|
|
26
36
|
run: |
|
|
27
37
|
git config --local user.email "github-actions[bot]@users.noreply.github.com"
|
|
28
38
|
git config --local user.name "github-actions[bot]"
|
|
39
|
+
|
|
29
40
|
- run: npm version --commit-hooks true patch
|
|
41
|
+
|
|
30
42
|
- name: Git commit and push
|
|
31
43
|
env:
|
|
32
44
|
GITHUB_TOKEN: ${{ secrets.PAT }}
|
|
33
45
|
run: git push origin
|
|
46
|
+
|
|
34
47
|
- run: npm publish
|
|
35
48
|
env:
|
|
36
49
|
NODE_AUTH_TOKEN: ${{ secrets.NPM_AUTH_TOKEN }}
|
package/dist/src/index.js
CHANGED
|
@@ -39,12 +39,14 @@ const pinoSettings = {
|
|
|
39
39
|
},
|
|
40
40
|
};
|
|
41
41
|
exports.pinoSettings = pinoSettings;
|
|
42
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
42
43
|
const formatItem = (item) => {
|
|
43
44
|
if (typeof item === "undefined") {
|
|
44
45
|
return "undefined";
|
|
45
46
|
}
|
|
46
47
|
// Remove colors from strings
|
|
47
48
|
if (typeof item === "string") {
|
|
49
|
+
// eslint-disable-next-line no-control-regex
|
|
48
50
|
return item.replace(/\x1b\[[0-9;]*m/g, "");
|
|
49
51
|
}
|
|
50
52
|
let stringified = "";
|
|
@@ -54,36 +56,41 @@ const formatItem = (item) => {
|
|
|
54
56
|
catch {
|
|
55
57
|
stringified = String(item);
|
|
56
58
|
}
|
|
57
|
-
return stringified.replace(
|
|
59
|
+
return stringified.replace(/^'|'$/g, "");
|
|
58
60
|
};
|
|
61
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
59
62
|
const format = (items) => {
|
|
60
63
|
return Array.from(items)
|
|
61
64
|
.map((item) => formatItem(item))
|
|
62
65
|
.join(" ");
|
|
63
66
|
};
|
|
64
67
|
const overrideConsole = (logger) => {
|
|
65
|
-
console.log = function () {
|
|
66
|
-
logger.info(format(Array.from(
|
|
68
|
+
console.log = function (...args) {
|
|
69
|
+
logger.info(format(Array.from(args)));
|
|
67
70
|
};
|
|
68
|
-
console.info = function () {
|
|
69
|
-
logger.info(format(Array.from(
|
|
71
|
+
console.info = function (...args) {
|
|
72
|
+
logger.info(format(Array.from(args)));
|
|
70
73
|
};
|
|
71
|
-
console.warn = function () {
|
|
72
|
-
logger.warn(format(Array.from(
|
|
74
|
+
console.warn = function (...args) {
|
|
75
|
+
logger.warn(format(Array.from(args)));
|
|
73
76
|
};
|
|
74
|
-
console.error = function () {
|
|
75
|
-
logger.error(format(Array.from(
|
|
77
|
+
console.error = function (...args) {
|
|
78
|
+
logger.error(format(Array.from(args)));
|
|
76
79
|
};
|
|
77
|
-
console.debug = function () {
|
|
78
|
-
logger.debug(format(Array.from(
|
|
80
|
+
console.debug = function (...args) {
|
|
81
|
+
logger.debug(format(Array.from(args)));
|
|
79
82
|
};
|
|
80
83
|
};
|
|
81
|
-
const
|
|
82
|
-
let pretty;
|
|
84
|
+
const loadPretty = async () => {
|
|
83
85
|
try {
|
|
84
|
-
|
|
86
|
+
return await Promise.resolve().then(() => __importStar(require("pino-pretty")));
|
|
87
|
+
}
|
|
88
|
+
catch {
|
|
89
|
+
return null;
|
|
85
90
|
}
|
|
86
|
-
|
|
91
|
+
};
|
|
92
|
+
const setupLogging = async (settings = pinoSettings) => {
|
|
93
|
+
const pretty = await loadPretty();
|
|
87
94
|
const logger = pretty
|
|
88
95
|
? (0, pino_1.default)(settings, pretty.default({ colorize: true }))
|
|
89
96
|
: (0, pino_1.default)(settings);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mynth-logger",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.14",
|
|
4
4
|
"description": "Package to format logs for mynth microservices.",
|
|
5
5
|
"main": "dist/src/index.js",
|
|
6
6
|
"typings": "dist/src/index.d.ts",
|
|
@@ -8,22 +8,24 @@
|
|
|
8
8
|
"test": "npx ava",
|
|
9
9
|
"build": "npx tsc",
|
|
10
10
|
"prettier": "npx prettier -w '**/*.{js,jsx,ts,tsx,json,yml.j2,yml,yaml,.*}'",
|
|
11
|
-
"lint": "concurrently \"npx prettier --check '**/*.{js,jsx,ts,tsx,json,yml.j2,yml,yaml,.*}'\" \"npx eslint --max-warnings=0\""
|
|
11
|
+
"lint": "concurrently \"npx prettier --check '**/*.{js,jsx,ts,tsx,json,yml.j2,yml,yaml,.*}'\" \"npx eslint . --max-warnings=0\""
|
|
12
12
|
},
|
|
13
13
|
"repository": {
|
|
14
14
|
"type": "git",
|
|
15
15
|
"url": "git@github.com-mynth:MynthAI/mynth-logger.git"
|
|
16
16
|
},
|
|
17
17
|
"dependencies": {
|
|
18
|
-
"ava": "^5.3.1",
|
|
19
|
-
"json5": "^2.2.3",
|
|
20
18
|
"pino": "^8.15.0"
|
|
21
19
|
},
|
|
22
20
|
"devDependencies": {
|
|
23
21
|
"@types/node": "^20.5.0",
|
|
22
|
+
"@typescript-eslint/eslint-plugin": "^6.8.0",
|
|
23
|
+
"ava": "^5.3.1",
|
|
24
24
|
"concurrently": "^8.2.0",
|
|
25
25
|
"eslint": "^8.47.0",
|
|
26
26
|
"eslint-plugin-ava": "^14.0.0",
|
|
27
|
+
"eslint-plugin-file-extension-in-import-ts": "^1.0.2",
|
|
28
|
+
"eslint-plugin-import": "^2.28.1",
|
|
27
29
|
"pino-pretty": "^10.2.0",
|
|
28
30
|
"prettier": "^3.0.2",
|
|
29
31
|
"tsx": "^3.12.7",
|
package/src/index.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import JSON5 from "json5";
|
|
2
1
|
import pino, { Logger, LoggerOptions } from "pino";
|
|
3
2
|
|
|
4
3
|
const pinoSettings: LoggerOptions = {
|
|
@@ -12,6 +11,7 @@ const pinoSettings: LoggerOptions = {
|
|
|
12
11
|
},
|
|
13
12
|
};
|
|
14
13
|
|
|
14
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
15
15
|
const formatItem = (item: any): string => {
|
|
16
16
|
if (typeof item === "undefined") {
|
|
17
17
|
return "undefined";
|
|
@@ -19,19 +19,22 @@ const formatItem = (item: any): string => {
|
|
|
19
19
|
|
|
20
20
|
// Remove colors from strings
|
|
21
21
|
if (typeof item === "string") {
|
|
22
|
+
// eslint-disable-next-line no-control-regex
|
|
22
23
|
return item.replace(/\x1b\[[0-9;]*m/g, "");
|
|
23
24
|
}
|
|
24
25
|
|
|
25
26
|
let stringified = "";
|
|
27
|
+
|
|
26
28
|
try {
|
|
27
29
|
stringified = JSON.stringify(item) || String(item);
|
|
28
30
|
} catch {
|
|
29
31
|
stringified = String(item);
|
|
30
32
|
}
|
|
31
33
|
|
|
32
|
-
return stringified.replace(
|
|
34
|
+
return stringified.replace(/^'|'$/g, "");
|
|
33
35
|
};
|
|
34
36
|
|
|
37
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
35
38
|
const format = (items: any[]): string => {
|
|
36
39
|
return Array.from(items)
|
|
37
40
|
.map((item) => formatItem(item))
|
|
@@ -39,35 +42,39 @@ const format = (items: any[]): string => {
|
|
|
39
42
|
};
|
|
40
43
|
|
|
41
44
|
const overrideConsole = (logger: Logger) => {
|
|
42
|
-
console.log = function () {
|
|
43
|
-
logger.info(format(Array.from(
|
|
45
|
+
console.log = function (...args) {
|
|
46
|
+
logger.info(format(Array.from(args)));
|
|
44
47
|
};
|
|
45
48
|
|
|
46
|
-
console.info = function () {
|
|
47
|
-
logger.info(format(Array.from(
|
|
49
|
+
console.info = function (...args) {
|
|
50
|
+
logger.info(format(Array.from(args)));
|
|
48
51
|
};
|
|
49
52
|
|
|
50
|
-
console.warn = function () {
|
|
51
|
-
logger.warn(format(Array.from(
|
|
53
|
+
console.warn = function (...args) {
|
|
54
|
+
logger.warn(format(Array.from(args)));
|
|
52
55
|
};
|
|
53
56
|
|
|
54
|
-
console.error = function () {
|
|
55
|
-
logger.error(format(Array.from(
|
|
57
|
+
console.error = function (...args) {
|
|
58
|
+
logger.error(format(Array.from(args)));
|
|
56
59
|
};
|
|
57
60
|
|
|
58
|
-
console.debug = function () {
|
|
59
|
-
logger.debug(format(Array.from(
|
|
61
|
+
console.debug = function (...args) {
|
|
62
|
+
logger.debug(format(Array.from(args)));
|
|
60
63
|
};
|
|
61
64
|
};
|
|
62
65
|
|
|
66
|
+
const loadPretty = async () => {
|
|
67
|
+
try {
|
|
68
|
+
return await import("pino-pretty");
|
|
69
|
+
} catch {
|
|
70
|
+
return null;
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
|
|
63
74
|
const setupLogging = async (
|
|
64
75
|
settings: LoggerOptions = pinoSettings
|
|
65
76
|
): Promise<Logger> => {
|
|
66
|
-
|
|
67
|
-
try {
|
|
68
|
-
pretty = await import("pino-pretty");
|
|
69
|
-
} catch {}
|
|
70
|
-
|
|
77
|
+
const pretty = await loadPretty();
|
|
71
78
|
const logger = pretty
|
|
72
79
|
? pino(settings, pretty.default({ colorize: true }))
|
|
73
80
|
: pino(settings);
|