mynth-logger 1.0.2 → 1.0.4

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/index.js ADDED
@@ -0,0 +1,68 @@
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
+ var json5_1 = __importDefault(require("json5"));
8
+ var pino_1 = __importDefault(require("pino"));
9
+ var isPinoPrettyInstalled = function () {
10
+ try {
11
+ (0, pino_1.default)({ transport: { target: "pino-pretty" } });
12
+ return true;
13
+ }
14
+ catch (_a) {
15
+ return false;
16
+ }
17
+ };
18
+ var pinoSettings = {
19
+ base: undefined,
20
+ timestamp: false,
21
+ level: "debug",
22
+ formatters: {
23
+ level: function (level) {
24
+ return { level: level };
25
+ },
26
+ },
27
+ };
28
+ if (isPinoPrettyInstalled() && process.env.NODE_ENV != "test") {
29
+ pinoSettings["transport"] = {
30
+ target: "pino-pretty",
31
+ options: {
32
+ colorize: true,
33
+ },
34
+ };
35
+ }
36
+ var logger = (0, pino_1.default)(pinoSettings);
37
+ var formatItem = function (item) {
38
+ // Remove colors from strings
39
+ if (typeof item === "string") {
40
+ return item.replace(/\x1b\[[0-9;]*m/g, "");
41
+ }
42
+ return json5_1.default.stringify(item).replace(/^\'|\'$/g, "");
43
+ };
44
+ var format = function (items) {
45
+ return Array.from(items)
46
+ .map(function (item) { return formatItem(item); })
47
+ .join(" ");
48
+ };
49
+ var setupLogging = function () {
50
+ if (typeof window !== "undefined")
51
+ return;
52
+ console.log = function () {
53
+ logger.info(format(Array.from(arguments)));
54
+ };
55
+ console.info = function () {
56
+ logger.info(format(Array.from(arguments)));
57
+ };
58
+ console.warn = function () {
59
+ logger.warn(format(Array.from(arguments)));
60
+ };
61
+ console.error = function () {
62
+ logger.error(format(Array.from(arguments)));
63
+ };
64
+ console.debug = function () {
65
+ logger.debug(format(Array.from(arguments)));
66
+ };
67
+ };
68
+ exports.setupLogging = setupLogging;
package/package.json CHANGED
@@ -1,11 +1,13 @@
1
1
  {
2
2
  "name": "mynth-logger",
3
- "version": "1.0.2",
3
+ "version": "1.0.4",
4
4
  "description": "Package to format logs for mynth microservices.",
5
- "main": "./src/index.ts",
5
+ "type": "module",
6
+ "main": "dist/src/index.js",
7
+ "module": "dist/src/index.js",
6
8
  "scripts": {
7
9
  "test": "npx ava",
8
- "build": "tsc",
10
+ "build": "npx tsc",
9
11
  "prettier": "npx prettier -w '**/*.{js,jsx,ts,tsx,json,yml.j2,yml,yaml,.*}'",
10
12
  "lint": "concurrently \"npx prettier --check '**/*.{js,jsx,ts,tsx,json,yml.j2,yml,yaml,.*}'\" \"npx eslint --max-warnings=0\""
11
13
  },
package/tsconfig.json CHANGED
@@ -7,6 +7,7 @@
7
7
  "strict": false,
8
8
  "esModuleInterop": true,
9
9
  "skipLibCheck": true,
10
+ "module": "CommonJS",
10
11
  "outDir": "./dist",
11
12
  "rootDir": "./src",
12
13
  "jsx": "react",