mynth-logger 2.0.3 → 2.0.5
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/src/format.js +3 -6
- package/dist/src/index.js +1 -17
- package/dist/src/logging.js +7 -13
- package/dist/src/reporters/datadog.js +3 -5
- package/dist/src/reporters/discord.js +13 -40
- package/dist/tests/app.js +2 -4
- package/dist/tests/index.test.js +6 -11
- package/package.json +2 -1
- package/src/reporters/discord.ts +2 -0
- package/tsconfig.json +1 -1
package/dist/src/format.js
CHANGED
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.format = void 0;
|
|
4
|
-
const json_1 = require("@ungap/structured-clone/json");
|
|
1
|
+
import { stringify } from "@ungap/structured-clone/json";
|
|
5
2
|
const formatItem = (item) => {
|
|
6
3
|
if (typeof item === "undefined") {
|
|
7
4
|
return "undefined";
|
|
@@ -22,7 +19,7 @@ const formatItem = (item) => {
|
|
|
22
19
|
return item;
|
|
23
20
|
const stringified = (() => {
|
|
24
21
|
try {
|
|
25
|
-
return
|
|
22
|
+
return stringify(item);
|
|
26
23
|
}
|
|
27
24
|
catch {
|
|
28
25
|
return String(item);
|
|
@@ -35,4 +32,4 @@ const format = (items) => {
|
|
|
35
32
|
.map((item) => formatItem(item))
|
|
36
33
|
.join(" ");
|
|
37
34
|
};
|
|
38
|
-
|
|
35
|
+
export { format };
|
package/dist/src/index.js
CHANGED
|
@@ -1,17 +1 @@
|
|
|
1
|
-
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./logging.js"), exports);
|
|
1
|
+
export * from "./logging.js";
|
package/dist/src/logging.js
CHANGED
|
@@ -1,18 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.setupLogging = void 0;
|
|
7
|
-
const consola_1 = require("consola");
|
|
8
|
-
const datadog_js_1 = __importDefault(require("./reporters/datadog.js"));
|
|
9
|
-
const discord_js_1 = __importDefault(require("./reporters/discord.js"));
|
|
1
|
+
import { createConsola } from "consola";
|
|
2
|
+
import DatadogReporter from "./reporters/datadog.js";
|
|
3
|
+
import DiscordReporter from "./reporters/discord.js";
|
|
10
4
|
const setupLogging = () => {
|
|
11
|
-
const consola =
|
|
5
|
+
const consola = createConsola({ fancy: true, level: 5 });
|
|
12
6
|
if (process.env.NODE_ENV === "production")
|
|
13
|
-
consola.setReporters([
|
|
14
|
-
consola.setReporters([
|
|
7
|
+
consola.setReporters([DatadogReporter]);
|
|
8
|
+
consola.setReporters([DiscordReporter, ...consola.options.reporters]);
|
|
15
9
|
consola.wrapConsole();
|
|
16
10
|
return consola;
|
|
17
11
|
};
|
|
18
|
-
|
|
12
|
+
export { setupLogging };
|
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const format_js_1 = require("../format.js");
|
|
1
|
+
import { format } from "../format.js";
|
|
4
2
|
const levelMap = {
|
|
5
3
|
0: "error",
|
|
6
4
|
1: "warn",
|
|
@@ -13,9 +11,9 @@ const Reporter = {
|
|
|
13
11
|
log: (logObj) => {
|
|
14
12
|
const message = JSON.stringify({
|
|
15
13
|
level: levelMap[logObj.level] || "debug",
|
|
16
|
-
message:
|
|
14
|
+
message: format(logObj.args),
|
|
17
15
|
});
|
|
18
16
|
process.stdout.write(`${message}\n`);
|
|
19
17
|
},
|
|
20
18
|
};
|
|
21
|
-
|
|
19
|
+
export default Reporter;
|
|
@@ -1,37 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
-
};
|
|
28
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
-
const format_js_1 = require("../format.js");
|
|
30
|
-
const arktype_1 = require("arktype");
|
|
31
|
-
const axios_1 = __importDefault(require("axios"));
|
|
32
|
-
const axios_retry_1 = __importStar(require("axios-retry"));
|
|
33
|
-
const Discord = (0, arktype_1.type)({
|
|
34
|
-
discord: (0, arktype_1.type)("boolean").narrow((v) => v),
|
|
1
|
+
import { format } from "../format.js";
|
|
2
|
+
import { type } from "arktype";
|
|
3
|
+
import axios from "axios";
|
|
4
|
+
import axiosRetry, { exponentialDelay } from "axios-retry";
|
|
5
|
+
console.trace(type);
|
|
6
|
+
const Discord = type({
|
|
7
|
+
discord: type("boolean").narrow((v) => v),
|
|
35
8
|
color: "string",
|
|
36
9
|
title: "string",
|
|
37
10
|
webhookUrl: "string",
|
|
@@ -42,7 +15,7 @@ const Reporter = {
|
|
|
42
15
|
const [discord, args] = getDiscord(logObj.args);
|
|
43
16
|
if (!discord.discord)
|
|
44
17
|
return;
|
|
45
|
-
sendToDiscord(
|
|
18
|
+
sendToDiscord(format(args), discord);
|
|
46
19
|
// Filter Discord data before the other reporters
|
|
47
20
|
// process the message
|
|
48
21
|
logObj.args = args;
|
|
@@ -51,17 +24,17 @@ const Reporter = {
|
|
|
51
24
|
const getDiscord = (args) => {
|
|
52
25
|
for (let i = 0; i < args.length; i++) {
|
|
53
26
|
const discord = Discord(args[i]);
|
|
54
|
-
if (discord instanceof
|
|
27
|
+
if (discord instanceof type.errors)
|
|
55
28
|
continue;
|
|
56
29
|
return [discord, args.filter((_, j) => j !== i)];
|
|
57
30
|
}
|
|
58
31
|
return [NullDiscord, args];
|
|
59
32
|
};
|
|
60
33
|
const sendToDiscord = async (description, options) => {
|
|
61
|
-
const axiosInstance =
|
|
62
|
-
(
|
|
34
|
+
const axiosInstance = axios.create();
|
|
35
|
+
axiosRetry(axiosInstance, {
|
|
63
36
|
retries: 3,
|
|
64
|
-
retryDelay:
|
|
37
|
+
retryDelay: exponentialDelay,
|
|
65
38
|
});
|
|
66
39
|
try {
|
|
67
40
|
await axiosInstance.post(options.webhookUrl, {
|
|
@@ -78,4 +51,4 @@ const sendToDiscord = async (description, options) => {
|
|
|
78
51
|
console.error("Unable to send message to Discord", error);
|
|
79
52
|
}
|
|
80
53
|
};
|
|
81
|
-
|
|
54
|
+
export default Reporter;
|
package/dist/tests/app.js
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const mynth_logger_1 = require("mynth-logger");
|
|
1
|
+
import { setupLogging } from "mynth-logger";
|
|
4
2
|
const run = async () => {
|
|
5
|
-
|
|
3
|
+
setupLogging();
|
|
6
4
|
console.log("Hello, this is a log");
|
|
7
5
|
console.info("Hello, this is an info log");
|
|
8
6
|
console.debug("Hello, this is a debug log");
|
package/dist/tests/index.test.js
CHANGED
|
@@ -1,18 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const ava_1 = __importDefault(require("ava"));
|
|
7
|
-
const mynth_logger_1 = require("mynth-logger");
|
|
8
|
-
ava_1.default.before(() => {
|
|
9
|
-
(0, mynth_logger_1.setupLogging)();
|
|
1
|
+
import test from "ava";
|
|
2
|
+
import { setupLogging } from "mynth-logger";
|
|
3
|
+
test.before(() => {
|
|
4
|
+
setupLogging();
|
|
10
5
|
});
|
|
11
|
-
|
|
6
|
+
test.serial("logs display to terminal", (t) => {
|
|
12
7
|
console.debug("Hello ava");
|
|
13
8
|
t.pass();
|
|
14
9
|
});
|
|
15
|
-
|
|
10
|
+
test.serial("can log various objects", (t) => {
|
|
16
11
|
console.debug("Message", { message: true });
|
|
17
12
|
console.debug(undefined);
|
|
18
13
|
console.debug("bigint", 100n);
|
package/package.json
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mynth-logger",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.5",
|
|
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",
|
|
7
|
+
"type": "module",
|
|
7
8
|
"scripts": {
|
|
8
9
|
"build": "rm -rf dist && npx tsc",
|
|
9
10
|
"test": "npx ava",
|
package/src/reporters/discord.ts
CHANGED