@emartech/json-logger 7.0.3 → 7.2.0

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.
@@ -0,0 +1,55 @@
1
+ name: Initialize build
2
+
3
+ on:
4
+ workflow_call:
5
+
6
+ outputs:
7
+ NODE_VERSION:
8
+ value: ${{ jobs.init.outputs.NODE_VERSION }}
9
+ NODE_CACHE_KEY:
10
+ value: ${{ jobs.init.outputs.NODE_CACHE_KEY }}
11
+
12
+ jobs:
13
+ init:
14
+ name: Initialize build
15
+ runs-on: ubuntu-latest
16
+
17
+ outputs:
18
+ NODE_VERSION: ${{ steps.node-version.outputs.NODE_VERSION }}
19
+ NODE_CACHE_KEY: ${{ steps.node-cache-key.outputs.NODE_CACHE_KEY }}
20
+
21
+ steps:
22
+ - name: Checkout code
23
+ uses: actions/checkout@v3
24
+ with:
25
+ fetch-depth: 0
26
+
27
+ - name: Get node version
28
+ id: node-version
29
+ run: echo ::set-output name=NODE_VERSION::$(cat .nvmrc)
30
+
31
+ - name: Get node cache key
32
+ id: node-cache-key
33
+ run: echo ::set-output name=NODE_CACHE_KEY::npm-${{ steps.node-version.outputs.NODE_VERSION }}-${{ hashFiles('**/package.json') }}
34
+
35
+ - name: Cache dependencies
36
+ id: cache-node-modules
37
+ uses: actions/cache@v3
38
+ with:
39
+ path: node_modules
40
+ key: ${{ steps.node-cache-key.outputs.NODE_CACHE_KEY }}
41
+
42
+ - name: Setup node
43
+ if: steps.cache-node-modules.outputs.cache-hit != 'true'
44
+ uses: actions/setup-node@v3
45
+ with:
46
+ node-version: '${{ steps.node-version.outputs.NODE_VERSION }}'
47
+
48
+ - name: Install dependencies
49
+ if: steps.cache-node-modules.outputs.cache-hit != 'true'
50
+ run: npm install
51
+
52
+ - name: Log results
53
+ run: |
54
+ echo "NODE_VERSION: ${{ steps.node-version.outputs.NODE_VERSION }}"
55
+ echo "NODE_CACHE_KEY: ${{ steps.node-cache-key.outputs.NODE_CACHE_KEY }}"
@@ -0,0 +1,46 @@
1
+ name: Release package
2
+
3
+ on:
4
+ workflow_call:
5
+ inputs:
6
+ NODE_VERSION:
7
+ type: string
8
+ required: true
9
+ NODE_CACHE_KEY:
10
+ type: string
11
+ required: true
12
+
13
+ secrets:
14
+ SEMANTIC_RELEASE_NPM_TOKEN:
15
+ required: true
16
+ SEMANTIC_RELEASE_GH_TOKEN:
17
+ required: true
18
+
19
+ jobs:
20
+ test:
21
+ name: Release package
22
+ runs-on: ubuntu-latest
23
+
24
+ steps:
25
+ - name: Checkout code
26
+ uses: actions/checkout@v3
27
+
28
+ - name: Load dependencies from cache
29
+ uses: actions/cache@v3
30
+ with:
31
+ path: node_modules
32
+ key: ${{ inputs.NODE_CACHE_KEY }}
33
+
34
+ - name: Setup node
35
+ uses: actions/setup-node@v3
36
+ with:
37
+ node-version: '${{ inputs.NODE_VERSION }}'
38
+
39
+ - name: Run build
40
+ run: npm run build
41
+
42
+ - name: Run release
43
+ run: npm run release
44
+ env:
45
+ NPM_TOKEN: ${{ secrets.SEMANTIC_RELEASE_NPM_TOKEN }}
46
+ GH_TOKEN: ${{ secrets.SEMANTIC_RELEASE_GH_TOKEN }}
@@ -0,0 +1,39 @@
1
+ name: Run tests
2
+
3
+ on:
4
+ workflow_call:
5
+ inputs:
6
+ NODE_VERSION:
7
+ type: string
8
+ required: true
9
+ NODE_CACHE_KEY:
10
+ type: string
11
+ required: true
12
+
13
+ jobs:
14
+ test:
15
+ name: Run tests
16
+ runs-on: ubuntu-latest
17
+
18
+ strategy:
19
+ fail-fast: false
20
+ matrix:
21
+ test: [lint, test]
22
+
23
+ steps:
24
+ - name: Checkout code
25
+ uses: actions/checkout@v3
26
+
27
+ - name: Load dependencies from cache
28
+ uses: actions/cache@v3
29
+ with:
30
+ path: node_modules
31
+ key: ${{ inputs.NODE_CACHE_KEY }}
32
+
33
+ - name: Setup node
34
+ uses: actions/setup-node@v3
35
+ with:
36
+ node-version: '${{ inputs.NODE_VERSION }}'
37
+
38
+ - name: Run ${{ matrix.test }} test
39
+ run: npm run ${{ matrix.test }}
@@ -0,0 +1,20 @@
1
+ name: Development
2
+
3
+ on:
4
+ push:
5
+ branches: [ '*', '*/*', '**', '!master', '!main' ]
6
+ pull_request:
7
+ branches: [ master, main ]
8
+
9
+ jobs:
10
+ init:
11
+ name: Init
12
+ uses: ./.github/workflows/_init.yml
13
+
14
+ test:
15
+ name: Test
16
+ uses: ./.github/workflows/_test.yml
17
+ needs: [ init ]
18
+ with:
19
+ NODE_VERSION: ${{ needs.init.outputs.NODE_VERSION }}
20
+ NODE_CACHE_KEY: ${{ needs.init.outputs.NODE_CACHE_KEY }}
@@ -0,0 +1,29 @@
1
+ name: Release
2
+
3
+ on:
4
+ push:
5
+ branches: [ master, main ]
6
+
7
+ jobs:
8
+ init:
9
+ name: Init
10
+ uses: ./.github/workflows/_init.yml
11
+
12
+ test:
13
+ name: Test
14
+ uses: ./.github/workflows/_test.yml
15
+ needs: [ init ]
16
+ with:
17
+ NODE_VERSION: ${{ needs.init.outputs.NODE_VERSION }}
18
+ NODE_CACHE_KEY: ${{ needs.init.outputs.NODE_CACHE_KEY }}
19
+
20
+ release:
21
+ name: Release
22
+ uses: ./.github/workflows/_release.yml
23
+ needs: [ init, test ]
24
+ with:
25
+ NODE_VERSION: ${{ needs.init.outputs.NODE_VERSION }}
26
+ NODE_CACHE_KEY: ${{ needs.init.outputs.NODE_CACHE_KEY }}
27
+ secrets:
28
+ SEMANTIC_RELEASE_NPM_TOKEN: ${{ secrets.SEMANTIC_RELEASE_NPM_TOKEN }}
29
+ SEMANTIC_RELEASE_GH_TOKEN: ${{ secrets.SEMANTIC_RELEASE_GH_TOKEN }}
package/README.md CHANGED
@@ -9,6 +9,8 @@ It has the same namespace based enabling/disabling mechanism as [debug].
9
9
  npm install @emartech/json-logger
10
10
  ```
11
11
 
12
+
13
+
12
14
  ### Usage
13
15
 
14
16
  #### Script
@@ -1 +1 @@
1
- export declare function isNamespaceEnabled(availableNamespace: string, namespace: string): boolean;
1
+ export declare const isNamespaceEnabled: (availableNamespace: string, namespace: string) => boolean;
@@ -1,12 +1,12 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.isNamespaceEnabled = void 0;
4
- function isNamespaceEnabled(availableNamespace, namespace) {
4
+ const isNamespaceEnabled = (availableNamespace, namespace) => {
5
5
  const availableNamespaces = availableNamespace.split(/[\s,]+/);
6
6
  let enabled = false;
7
7
  const adds = [];
8
8
  const skips = [];
9
- availableNamespaces.forEach(function (name) {
9
+ availableNamespaces.forEach((name) => {
10
10
  if (!name) {
11
11
  return;
12
12
  }
@@ -18,16 +18,16 @@ function isNamespaceEnabled(availableNamespace, namespace) {
18
18
  adds.push(new RegExp('^' + name + '$'));
19
19
  }
20
20
  });
21
- adds.forEach(function (addRegexp) {
21
+ adds.forEach((addRegexp) => {
22
22
  if (addRegexp.test(namespace)) {
23
23
  enabled = true;
24
24
  }
25
25
  });
26
- skips.forEach(function (addRegexp) {
26
+ skips.forEach((addRegexp) => {
27
27
  if (addRegexp.test(namespace)) {
28
28
  enabled = false;
29
29
  }
30
30
  });
31
31
  return enabled;
32
- }
32
+ };
33
33
  exports.isNamespaceEnabled = isNamespaceEnabled;
@@ -1,6 +1,4 @@
1
- import { jsonFormatter } from './json';
2
- import { logentriesFormatter } from './logentries';
3
1
  export declare const formatter: {
4
- json: typeof jsonFormatter;
5
- logentries: typeof logentriesFormatter;
2
+ json: (log: unknown) => string;
3
+ logentries: (data: Record<string, unknown>) => string;
6
4
  };
@@ -5,5 +5,5 @@ const json_1 = require("./json");
5
5
  const logentries_1 = require("./logentries");
6
6
  exports.formatter = {
7
7
  json: json_1.jsonFormatter,
8
- logentries: logentries_1.logentriesFormatter
8
+ logentries: logentries_1.logentriesFormatter,
9
9
  };
@@ -1 +1 @@
1
- export declare function jsonFormatter(log: unknown): string;
1
+ export declare const jsonFormatter: (log: unknown) => string;
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.jsonFormatter = void 0;
4
- function jsonFormatter(log) {
4
+ const jsonFormatter = (log) => {
5
5
  return JSON.stringify(log);
6
- }
6
+ };
7
7
  exports.jsonFormatter = jsonFormatter;
@@ -1 +1 @@
1
- export declare function logentriesFormatter(data: Record<string, unknown>): string;
1
+ export declare const logentriesFormatter: (data: Record<string, unknown>) => string;
@@ -15,10 +15,9 @@ const convertToTag = (value, key) => {
15
15
  }
16
16
  return key + '=' + value;
17
17
  };
18
- function logentriesFormatter(data) {
19
- return Object
20
- .keys(data)
21
- .map(key => convertToTag(data[key], key))
18
+ const logentriesFormatter = (data) => {
19
+ return Object.keys(data)
20
+ .map((key) => convertToTag(data[key], key))
22
21
  .join(' ');
23
- }
22
+ };
24
23
  exports.logentriesFormatter = logentriesFormatter;
package/dist/index.d.ts CHANGED
@@ -6,7 +6,7 @@ export declare namespace createLogger {
6
6
  var getNamespaces: () => string;
7
7
  var configure: (options: LoggerConfig) => void;
8
8
  var formatter: {
9
- json: typeof import("./formatter/json").jsonFormatter;
10
- logentries: typeof import("./formatter/logentries").logentriesFormatter;
9
+ json: (log: unknown) => string;
10
+ logentries: (data: Record<string, unknown>) => string;
11
11
  };
12
12
  }
@@ -20,8 +20,8 @@ export declare class Logger {
20
20
  _namespace: string;
21
21
  _enabled: boolean;
22
22
  constructor(namespace: string, enabled: boolean);
23
- static configure(options: LoggerConfig): void;
24
- static _validate(options: LoggerConfig): void;
23
+ static configure(options: Partial<LoggerConfig>): void;
24
+ static _validate(options: Partial<LoggerConfig>): void;
25
25
  static config: LoggerConfig;
26
26
  isEnabled(): boolean;
27
27
  trace(action: string, data?: unknown): void;
@@ -18,7 +18,7 @@ class Logger {
18
18
  Object.assign(Logger.config, options);
19
19
  }
20
20
  static _validate(options) {
21
- Object.keys(options).forEach(key => {
21
+ Object.keys(options).forEach((key) => {
22
22
  if (!allowedKeys.includes(key)) {
23
23
  throw new Error('Only the following keys are allowed: formatter, output');
24
24
  }
@@ -53,7 +53,7 @@ class Logger {
53
53
  name: this._namespace,
54
54
  action: action,
55
55
  level: config_1.config.levels[level].number,
56
- time: new Date().toISOString()
56
+ time: new Date().toISOString(),
57
57
  }, data);
58
58
  Logger.config.transformers.forEach((transform) => {
59
59
  dataToLog = transform(dataToLog);
@@ -76,18 +76,14 @@ class Logger {
76
76
  if (!stack) {
77
77
  return;
78
78
  }
79
- return stack.length > STACK_TRACE_LIMIT ?
80
- stack.substring(0, STACK_TRACE_LIMIT) + ' ...' :
81
- stack;
79
+ return stack.length > STACK_TRACE_LIMIT ? stack.substring(0, STACK_TRACE_LIMIT) + ' ...' : stack;
82
80
  }
83
81
  _shortenData(data) {
84
82
  if (typeof data === 'undefined') {
85
83
  return;
86
84
  }
87
85
  const stringifiedData = typeof data === 'object' ? JSON.stringify(data) : data;
88
- return stringifiedData.length > DATA_LIMIT ?
89
- stringifiedData.substring(0, DATA_LIMIT) + ' ...' :
90
- stringifiedData;
86
+ return stringifiedData.length > DATA_LIMIT ? stringifiedData.substring(0, DATA_LIMIT) + ' ...' : stringifiedData;
91
87
  }
92
88
  _getErrorDetails(error) {
93
89
  if (!(error instanceof Object)) {
@@ -97,7 +93,7 @@ class Logger {
97
93
  error_name: error.name,
98
94
  error_stack: this._shortenStackTrace(error.stack || ''),
99
95
  error_message: error.message,
100
- error_data: this._shortenData(error.data)
96
+ error_data: this._shortenData(error.data),
101
97
  };
102
98
  return Object.assign(baseDetails, this._getAxiosErrorDetails(error));
103
99
  }
@@ -110,7 +106,7 @@ class Logger {
110
106
  request_url: error.config.url,
111
107
  response_status: error.response ? error.response.status : undefined,
112
108
  response_status_text: error.response ? error.response.statusText : undefined,
113
- response_data: error.response ? this._shortenData(error.response.data) : undefined
109
+ response_data: error.response ? this._shortenData(error.response.data) : undefined,
114
110
  };
115
111
  }
116
112
  }
@@ -118,5 +114,5 @@ exports.Logger = Logger;
118
114
  Logger.config = {
119
115
  formatter: json_1.jsonFormatter,
120
116
  output: console_1.consoleOutput,
121
- transformers: []
117
+ transformers: [],
122
118
  };
@@ -1 +1 @@
1
- export declare function consoleOutput(formattedLog: unknown): void;
1
+ export declare const consoleOutput: (formattedLog: unknown) => void;
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.consoleOutput = void 0;
4
- function consoleOutput(formattedLog) {
4
+ const consoleOutput = (formattedLog) => {
5
5
  console.log(formattedLog);
6
- }
6
+ };
7
7
  exports.consoleOutput = consoleOutput;
package/main.yml ADDED
@@ -0,0 +1,30 @@
1
+ name: Test and Release
2
+
3
+ on:
4
+ push:
5
+ branches: [ master, main ]
6
+
7
+ env:
8
+ NPM_TOKEN: ${{ secrets.SEMANTIC_RELEASE_NPM_TOKEN }}
9
+ GH_TOKEN: ${{ secrets.SEMANTIC_RELEASE_GH_TOKEN }}
10
+
11
+ jobs:
12
+ init:
13
+ name: Init
14
+ uses: ./.github/workflows/_init.yml
15
+
16
+ test:
17
+ name: Test
18
+ uses: ./.github/workflows/_test.yml
19
+ needs: [ init ]
20
+ with:
21
+ NODE_VERSION: ${{ needs.init.outputs.NODE_VERSION }}
22
+ NODE_CACHE_KEY: ${{ needs.init.outputs.NODE_CACHE_KEY }}
23
+
24
+ deploy:
25
+ name: Test
26
+ uses: ./.github/workflows/_deploy.yml
27
+ needs: [ init, test ]
28
+ with:
29
+ NODE_VERSION: ${{ needs.init.outputs.NODE_VERSION }}
30
+ NODE_CACHE_KEY: ${{ needs.init.outputs.NODE_CACHE_KEY }}
package/package.json CHANGED
@@ -3,15 +3,14 @@
3
3
  "description": "Tiny and fast json logger with namespace support",
4
4
  "main": "dist/index.js",
5
5
  "scripts": {
6
- "test": "mocha --require ts-node/register ./src --recursive",
7
- "test:watch": "mocha --require ts-node/register ./src --recursive --watch",
8
- "lint": "eslint ./src/**/*.{ts,js}",
6
+ "test": "mocha --require ts-node/register --extension ts ./src --recursive",
7
+ "test:watch": "mocha --require ts-node/register --extension ts ./src --recursive --watch",
8
+ "lint": "eslint ./src/**/*.ts",
9
+ "lint:fix": "eslint ./src/**/*.ts --fix",
9
10
  "build": "rm -rf dist && tsc --project ./tsconfig.json",
10
- "semantic-release": "CI=true semantic-release",
11
+ "release": "CI=true semantic-release",
11
12
  "example-js": "DEBUG=* node examples/index-js.js",
12
- "example-ts": "DEBUG=* ts-node examples/index-ts.ts",
13
- "koa-example": "DEBUG=* node examples/koa.js",
14
- "express-example": "DEBUG=* node examples/express.js"
13
+ "example-ts": "DEBUG=* ts-node examples/index-ts.ts"
15
14
  },
16
15
  "publishConfig": {
17
16
  "access": "public"
@@ -27,21 +26,31 @@
27
26
  "debug",
28
27
  "json"
29
28
  ],
30
- "dependencies": {},
31
29
  "devDependencies": {
32
- "@types/node": "18.7.14",
33
- "@typescript-eslint/parser": "5.36.1",
30
+ "@types/chai": "4.3.3",
31
+ "@types/mocha": "10.0.0",
32
+ "@types/node": "18.7.23",
33
+ "@types/sinon": "10.0.13",
34
+ "@types/sinon-chai": "3.2.8",
35
+ "@typescript-eslint/eslint-plugin": "5.38.1",
36
+ "@typescript-eslint/parser": "5.38.1",
37
+ "axios": "0.27.2",
34
38
  "chai": "4.3.6",
35
- "eslint": "8.23.0",
39
+ "eslint": "8.24.0",
36
40
  "eslint-config-emarsys": "5.1.0",
41
+ "eslint-config-prettier": "8.5.0",
37
42
  "eslint-plugin-no-only-tests": "3.0.0",
43
+ "eslint-plugin-prettier": "4.2.1",
38
44
  "eslint-plugin-security": "1.5.0",
45
+ "install": "0.13.0",
39
46
  "mocha": "10.0.0",
47
+ "npm": "8.19.2",
48
+ "prettier": "2.7.1",
40
49
  "semantic-release": "19.0.5",
41
50
  "sinon": "14.0.0",
42
51
  "sinon-chai": "3.7.0",
43
52
  "ts-node": "10.9.1",
44
- "typescript": "4.8.2"
53
+ "typescript": "4.8.4"
45
54
  },
46
55
  "repository": {
47
56
  "type": "git",
@@ -51,5 +60,5 @@
51
60
  "url": "https://github.com/emartech/json-logger-js/issues"
52
61
  },
53
62
  "homepage": "https://github.com/emartech/json-logger-js#readme",
54
- "version": "7.0.3"
63
+ "version": "7.2.0"
55
64
  }
package/tsconfig.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
- "exclude": ["dist", "node_modules", "src/**/*.js"],
3
- "include": ["src/**/*.ts", "src/**/*.js"],
2
+ "exclude": ["dist", "node_modules"],
3
+ "include": ["src/**/*.ts"],
4
4
  "compilerOptions": {
5
5
  /* Visit https://aka.ms/tsconfig to read more about this file */
6
6
 
@@ -41,7 +41,7 @@
41
41
  // "noResolve": true, /* Disallow 'import's, 'require's or '<reference>'s from expanding the number of files TypeScript should add to a project. */
42
42
 
43
43
  /* JavaScript Support */
44
- "allowJs": true, /* Allow JavaScript files to be a part of your program. Use the 'checkJS' option to get errors from these files. */
44
+ "allowJs": false, /* Allow JavaScript files to be a part of your program. Use the 'checkJS' option to get errors from these files. */
45
45
  // "checkJs": true, /* Enable error reporting in type-checked JavaScript files. */
46
46
  // "maxNodeModuleJsDepth": 1, /* Specify the maximum folder depth used for checking JavaScript files from 'node_modules'. Only applicable with 'allowJs'. */
47
47
 
package/.eslintrc DELETED
@@ -1,25 +0,0 @@
1
- {
2
- "env": {
3
- "node": true,
4
- "mocha": true,
5
- "es6": true
6
- },
7
- "parser": "@typescript-eslint/parser",
8
- "parserOptions": {
9
- "ecmaFeatures": {
10
- "impliedStrict": true
11
- }
12
- },
13
- "globals": {
14
- "expect": true
15
- },
16
- "rules": {
17
- "security/detect-object-injection": 0,
18
- "security/detect-non-literal-regexp": 0,
19
- "no-unused-expressions": 0,
20
- "func-style": 0
21
- },
22
- "extends": [
23
- "emarsys"
24
- ]
25
- }
@@ -1,33 +0,0 @@
1
- name: CI
2
-
3
- on:
4
- push:
5
- branches: [ master, main ]
6
-
7
- env:
8
- NPM_TOKEN: ${{ secrets.SEMANTIC_RELEASE_NPM_TOKEN }}
9
- GH_TOKEN: ${{ secrets.SEMANTIC_RELEASE_GH_TOKEN }}
10
-
11
- jobs:
12
- test:
13
- runs-on: ubuntu-latest
14
-
15
- steps:
16
- - uses: actions/checkout@v3
17
- - name: Node version
18
- id: engines
19
- run: echo "##[set-output name=NODE_VERSION;]$(cat .nvmrc)"
20
- - name: Use Node.js ${{ steps.engines.outputs.NODE_VERSION }}
21
- uses: actions/setup-node@v3
22
- with:
23
- node-version: ${{ steps.engines.outputs.NODE_VERSION }}
24
- - name: Install
25
- run: npm install
26
- - name: Lint
27
- run: npm run lint
28
- - name: Test
29
- run: npm run test
30
- - name: Build
31
- run: npm run build
32
- - name: Release
33
- run: npm run semantic-release