mynth-logger 2.0.4 → 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.
@@ -1,7 +1,4 @@
1
- "use strict";
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 (0, json_1.stringify)(item);
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
- exports.format = format;
35
+ export { format };
package/dist/src/index.js CHANGED
@@ -1,17 +1 @@
1
- "use strict";
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";
@@ -1,18 +1,12 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
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 = (0, consola_1.createConsola)({ fancy: true, level: 5 });
5
+ const consola = createConsola({ fancy: true, level: 5 });
12
6
  if (process.env.NODE_ENV === "production")
13
- consola.setReporters([datadog_js_1.default]);
14
- consola.setReporters([discord_js_1.default, ...consola.options.reporters]);
7
+ consola.setReporters([DatadogReporter]);
8
+ consola.setReporters([DiscordReporter, ...consola.options.reporters]);
15
9
  consola.wrapConsole();
16
10
  return consola;
17
11
  };
18
- exports.setupLogging = setupLogging;
12
+ export { setupLogging };
@@ -1,6 +1,4 @@
1
- "use strict";
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: (0, format_js_1.format)(logObj.args),
14
+ message: format(logObj.args),
17
15
  });
18
16
  process.stdout.write(`${message}\n`);
19
17
  },
20
18
  };
21
- exports.default = Reporter;
19
+ export default Reporter;
@@ -1,38 +1,10 @@
1
- "use strict";
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 __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
- console.trace(arktype_1.type);
34
- const Discord = (0, arktype_1.type)({
35
- 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),
36
8
  color: "string",
37
9
  title: "string",
38
10
  webhookUrl: "string",
@@ -43,7 +15,7 @@ const Reporter = {
43
15
  const [discord, args] = getDiscord(logObj.args);
44
16
  if (!discord.discord)
45
17
  return;
46
- sendToDiscord((0, format_js_1.format)(args), discord);
18
+ sendToDiscord(format(args), discord);
47
19
  // Filter Discord data before the other reporters
48
20
  // process the message
49
21
  logObj.args = args;
@@ -52,17 +24,17 @@ const Reporter = {
52
24
  const getDiscord = (args) => {
53
25
  for (let i = 0; i < args.length; i++) {
54
26
  const discord = Discord(args[i]);
55
- if (discord instanceof arktype_1.type.errors)
27
+ if (discord instanceof type.errors)
56
28
  continue;
57
29
  return [discord, args.filter((_, j) => j !== i)];
58
30
  }
59
31
  return [NullDiscord, args];
60
32
  };
61
33
  const sendToDiscord = async (description, options) => {
62
- const axiosInstance = axios_1.default.create();
63
- (0, axios_retry_1.default)(axiosInstance, {
34
+ const axiosInstance = axios.create();
35
+ axiosRetry(axiosInstance, {
64
36
  retries: 3,
65
- retryDelay: axios_retry_1.exponentialDelay,
37
+ retryDelay: exponentialDelay,
66
38
  });
67
39
  try {
68
40
  await axiosInstance.post(options.webhookUrl, {
@@ -79,4 +51,4 @@ const sendToDiscord = async (description, options) => {
79
51
  console.error("Unable to send message to Discord", error);
80
52
  }
81
53
  };
82
- exports.default = Reporter;
54
+ export default Reporter;
package/dist/tests/app.js CHANGED
@@ -1,8 +1,6 @@
1
- "use strict";
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
- (0, mynth_logger_1.setupLogging)();
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");
@@ -1,18 +1,13 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
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
- ava_1.default.serial("logs display to terminal", (t) => {
6
+ test.serial("logs display to terminal", (t) => {
12
7
  console.debug("Hello ava");
13
8
  t.pass();
14
9
  });
15
- ava_1.default.serial("can log various objects", (t) => {
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.4",
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/tsconfig.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "compilerOptions": {
3
3
  "baseUrl": "./src",
4
4
  "target": "es2022",
5
- "module": "CommonJS",
5
+ "module": "es2022",
6
6
  "moduleResolution": "Node",
7
7
  "strict": true,
8
8
  "esModuleInterop": true,