@emartech/json-logger 5.0.2 → 7.0.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.
- package/.eslintrc +25 -0
- package/.github/workflows/main.yml +33 -0
- package/README.md +60 -12
- package/dist/config.d.ts +0 -1
- package/dist/config.js +5 -13
- package/dist/formatter/index.d.ts +0 -2
- package/dist/formatter/index.js +0 -2
- package/dist/formatter/logentries.js +1 -1
- package/dist/index.d.ts +2 -6
- package/dist/index.js +9 -14
- package/dist/logger/logger.js +8 -7
- package/package.json +10 -6
- package/dist/formatter/debug.d.ts +0 -6
- package/dist/formatter/debug.js +0 -18
- package/dist/output/color-name/color-name.d.ts +0 -11
- package/dist/output/color-name/color-name.js +0 -27
- package/dist/output/format-body/format-body.d.ts +0 -1
- package/dist/output/format-body/format-body.js +0 -23
- package/dist/output/format-time/format-time.d.ts +0 -5
- package/dist/output/format-time/format-time.js +0 -21
- package/dist/output/stringify-level/stringify-level.d.ts +0 -1
- package/dist/output/stringify-level/stringify-level.js +0 -8
package/.eslintrc
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
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
|
package/README.md
CHANGED
|
@@ -11,10 +11,13 @@ npm install @emartech/json-logger
|
|
|
11
11
|
|
|
12
12
|
### Usage
|
|
13
13
|
|
|
14
|
+
#### Script
|
|
15
|
+
|
|
14
16
|
```javascript
|
|
15
17
|
process.env.DEBUG = 'redis';
|
|
16
|
-
const
|
|
17
|
-
const
|
|
18
|
+
const { createLogger } = require('@emartech/json-logger');
|
|
19
|
+
const mongoLogger = createLogger('mongo');
|
|
20
|
+
const redisLogger = createLogger('redis');
|
|
18
21
|
|
|
19
22
|
redisLogger.info('connected', { domain: 'yahoo' });
|
|
20
23
|
// {"name":"redis","action":"connected","level":30,"time":"2016-08-15T08:50:23.566Z","domain":"yahoo"}
|
|
@@ -26,6 +29,47 @@ redisLogger.fromError('query', new Error('Unauthorized'), { problem: 'missmatch'
|
|
|
26
29
|
// {"name":"redis","action":"query","level":50,"time":"2016-08-15T08:50:23.569Z","error_name":"Error","error_stack":"Error: Unauthorized\n at Object.<anonymous> (/home/blacksonic/workspace/bunyan-debug/example.js:15:32)\n at Module._compile (module.js:541:32)\n at Object.Module._extensions..js (module.js:550:10)\n at Module.load (module.js:458:32)\n at tryModuleLoad (module.js:417:12)\n at Function.Module._load (module.js:409:3)\n at Module.runMain (module.js:575:10)\n at run (bootstrap_node.js:352:7)\n at startup (bootstrap_node.js:144:9)\n at bootstrap_node.js:467:3","error_message":"Unauthorized","problem":"missmatch"}
|
|
27
30
|
```
|
|
28
31
|
|
|
32
|
+
#### Class
|
|
33
|
+
|
|
34
|
+
```javascript
|
|
35
|
+
const { createLogger } = require('@emartech/json-logger');
|
|
36
|
+
const logger = createLogger('Exporter');
|
|
37
|
+
|
|
38
|
+
class Exporter {
|
|
39
|
+
export() {
|
|
40
|
+
mongoLogger.info('export', { customer_id: 123 });
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
```typescript
|
|
46
|
+
import { createLogger } from '@emartech/json-logger';
|
|
47
|
+
const logger = createLogger('Exporter');
|
|
48
|
+
|
|
49
|
+
class Exporter {
|
|
50
|
+
export() {
|
|
51
|
+
mongoLogger.info('export', { customer_id: 123 });
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
#### Tests
|
|
57
|
+
|
|
58
|
+
```javascript
|
|
59
|
+
import { Logger } from '@emartech/json-logger';
|
|
60
|
+
|
|
61
|
+
describe('Exporter', () => {
|
|
62
|
+
it('should log', () => {
|
|
63
|
+
jest.spyOn(Logger.prototype, 'info').mockReturnValue();
|
|
64
|
+
const exporter = new Exporter();
|
|
65
|
+
|
|
66
|
+
exporter.export();
|
|
67
|
+
|
|
68
|
+
expect(Logger.prototype.info).toHaveBeenCalledWith('export', { customer_id: 123 });
|
|
69
|
+
})
|
|
70
|
+
});
|
|
71
|
+
```
|
|
72
|
+
|
|
29
73
|
More examples can be found in the `examples` directory.
|
|
30
74
|
|
|
31
75
|
### API
|
|
@@ -39,11 +83,12 @@ Disabled instances output no logs.
|
|
|
39
83
|
|
|
40
84
|
```javascript
|
|
41
85
|
process.env.DEBUG = 'redis,mysql';
|
|
86
|
+
const { createLogger } = require('@emartech/json-logger');
|
|
42
87
|
|
|
43
|
-
const mongoLogger =
|
|
88
|
+
const mongoLogger = createLogger('mongo');
|
|
44
89
|
// mongo instance will be disabled
|
|
45
90
|
|
|
46
|
-
const redisLogger =
|
|
91
|
+
const redisLogger = createLogger('redis');
|
|
47
92
|
// redis instance will be enabled
|
|
48
93
|
```
|
|
49
94
|
|
|
@@ -52,7 +97,8 @@ const redisLogger = require('@emartech/json-logger')('redis');
|
|
|
52
97
|
Prints the provided data to the console in JSON format.
|
|
53
98
|
|
|
54
99
|
```javascript
|
|
55
|
-
const
|
|
100
|
+
const { createLogger } = require('@emartech/json-logger');
|
|
101
|
+
const redisLogger = createLogger('redis');
|
|
56
102
|
|
|
57
103
|
redisLogger.info('connected', { domain: 'yahoo' });
|
|
58
104
|
// {"name":"redis","action":"connected","level":30,"time":"2016-08-15T08:50:23.566Z","domain":"yahoo"}
|
|
@@ -92,7 +138,8 @@ The displayed line contains the stack trace, the name and the message of the err
|
|
|
92
138
|
The log level defaults to error.
|
|
93
139
|
|
|
94
140
|
```javascript
|
|
95
|
-
const
|
|
141
|
+
const { createLogger } = require('@emartech/json-logger');
|
|
142
|
+
const redisLogger = createLogger('redis');
|
|
96
143
|
|
|
97
144
|
redisLogger.fromError('query', new Error('Unauthorized'), { problem: 'missmatch' });
|
|
98
145
|
// {"name":"redis","action":"query","level":50,"time":"2016-08-15T08:50:23.569Z","error_name":"Error","error_stack":"Error: Unauthorized\n at Object.<anonymous> (/home/blacksonic/workspace/bunyan-debug/example.js:15:32)\n at Module._compile (module.js:541:32)\n at Object.Module._extensions..js (module.js:550:10)\n at Module.load (module.js:458:32)\n at tryModuleLoad (module.js:417:12)\n at Function.Module._load (module.js:409:3)\n at Module.runMain (module.js:575:10)\n at run (bootstrap_node.js:352:7)\n at startup (bootstrap_node.js:144:9)\n at bootstrap_node.js:467:3","error_message":"Unauthorized","problem":"missmatch"}
|
|
@@ -109,7 +156,8 @@ but also logs the elapsed time in milliseconds from the creation of the instance
|
|
|
109
156
|
The elapsed time will be logged into the `duration` field.
|
|
110
157
|
|
|
111
158
|
```javascript
|
|
112
|
-
const
|
|
159
|
+
const { createLogger } = require('@emartech/json-logger');
|
|
160
|
+
const redisLogger = createLogger('redis');
|
|
113
161
|
|
|
114
162
|
const timer = redisLogger.timer();
|
|
115
163
|
|
|
@@ -127,9 +175,9 @@ With transformers we can alter the data to be logged before passing to the forma
|
|
|
127
175
|
It is a perfect place to add the name of the machine is running on or the request id associated with the current thread stored on a continuation local storage.
|
|
128
176
|
|
|
129
177
|
```javascript
|
|
130
|
-
const
|
|
178
|
+
const { createLogger } = require('@emartech/json-logger');
|
|
131
179
|
|
|
132
|
-
|
|
180
|
+
createLogger.configure({
|
|
133
181
|
formatter: JSON.stringify,
|
|
134
182
|
output: console.log,
|
|
135
183
|
transformers: []
|
|
@@ -160,11 +208,11 @@ For automating
|
|
|
160
208
|
|
|
161
209
|
```javascript
|
|
162
210
|
const Koa = require('koa');
|
|
163
|
-
const
|
|
211
|
+
const { createLogger } = require('@emartech/json-logger');
|
|
164
212
|
const clsAdapter = require('@emartech/cls-adapter');
|
|
165
|
-
const logger =
|
|
213
|
+
const logger = createLogger('redis');
|
|
166
214
|
|
|
167
|
-
|
|
215
|
+
createLogger.configure({
|
|
168
216
|
transformers: [
|
|
169
217
|
clsAdapter.addContextStorageToInput()
|
|
170
218
|
]
|
package/dist/config.d.ts
CHANGED
package/dist/config.js
CHANGED
|
@@ -1,10 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
3
|
exports.config = void 0;
|
|
7
|
-
const chalk_1 = __importDefault(require("chalk"));
|
|
8
4
|
const levels = {
|
|
9
5
|
trace: {
|
|
10
6
|
number: 10,
|
|
@@ -20,20 +16,16 @@ const levels = {
|
|
|
20
16
|
},
|
|
21
17
|
warn: {
|
|
22
18
|
number: 40,
|
|
23
|
-
name:
|
|
19
|
+
name: 'WARN'
|
|
24
20
|
},
|
|
25
21
|
error: {
|
|
26
22
|
number: 50,
|
|
27
|
-
name:
|
|
23
|
+
name: 'ERROR'
|
|
28
24
|
},
|
|
29
25
|
fatal: {
|
|
30
26
|
number: 60,
|
|
31
|
-
name:
|
|
32
|
-
}
|
|
27
|
+
name: 'FATAL'
|
|
28
|
+
}
|
|
33
29
|
};
|
|
34
30
|
const availableLevels = Object.keys(levels);
|
|
35
|
-
|
|
36
|
-
availableLevels.forEach((levelName) => {
|
|
37
|
-
coloredNames[levels[levelName].number] = levels[levelName].name;
|
|
38
|
-
});
|
|
39
|
-
exports.config = { levels, availableLevels, coloredNames };
|
|
31
|
+
exports.config = { levels, availableLevels };
|
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
import { jsonFormatter } from './json';
|
|
2
2
|
import { logentriesFormatter } from './logentries';
|
|
3
|
-
import { debugFormatter } from './debug';
|
|
4
3
|
export declare const formatter: {
|
|
5
4
|
json: typeof jsonFormatter;
|
|
6
|
-
debug: typeof debugFormatter;
|
|
7
5
|
logentries: typeof logentriesFormatter;
|
|
8
6
|
};
|
package/dist/formatter/index.js
CHANGED
|
@@ -3,9 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.formatter = void 0;
|
|
4
4
|
const json_1 = require("./json");
|
|
5
5
|
const logentries_1 = require("./logentries");
|
|
6
|
-
const debug_1 = require("./debug");
|
|
7
6
|
exports.formatter = {
|
|
8
7
|
json: json_1.jsonFormatter,
|
|
9
|
-
debug: debug_1.debugFormatter,
|
|
10
8
|
logentries: logentries_1.logentriesFormatter
|
|
11
9
|
};
|
package/dist/index.d.ts
CHANGED
|
@@ -1,16 +1,12 @@
|
|
|
1
1
|
import { Logger, LoggerConfig } from './logger/logger';
|
|
2
2
|
export { Logger, LoggerConfig } from './logger/logger';
|
|
3
3
|
export { Timer } from './timer/timer';
|
|
4
|
-
export declare function
|
|
5
|
-
export declare namespace
|
|
6
|
-
var Logger: typeof import("./logger/logger").Logger;
|
|
7
|
-
var Timer: typeof import("./timer/timer").Timer;
|
|
4
|
+
export declare function createLogger(namespace: string): Logger;
|
|
5
|
+
export declare namespace createLogger {
|
|
8
6
|
var getNamespaces: () => string;
|
|
9
7
|
var configure: (options: LoggerConfig) => void;
|
|
10
8
|
var formatter: {
|
|
11
9
|
json: typeof import("./formatter/json").jsonFormatter;
|
|
12
|
-
debug: typeof import("./formatter/debug").debugFormatter;
|
|
13
10
|
logentries: typeof import("./formatter/logentries").logentriesFormatter;
|
|
14
11
|
};
|
|
15
12
|
}
|
|
16
|
-
export default logFactory;
|
package/dist/index.js
CHANGED
|
@@ -1,26 +1,21 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.createLogger = exports.Timer = exports.Logger = void 0;
|
|
4
4
|
const logger_1 = require("./logger/logger");
|
|
5
5
|
var logger_2 = require("./logger/logger");
|
|
6
6
|
Object.defineProperty(exports, "Logger", { enumerable: true, get: function () { return logger_2.Logger; } });
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
Object.defineProperty(exports, "Timer", { enumerable: true, get: function () { return timer_2.Timer; } });
|
|
7
|
+
var timer_1 = require("./timer/timer");
|
|
8
|
+
Object.defineProperty(exports, "Timer", { enumerable: true, get: function () { return timer_1.Timer; } });
|
|
10
9
|
const enabled_1 = require("./enabled/enabled");
|
|
11
10
|
const formatter_1 = require("./formatter");
|
|
12
|
-
function
|
|
13
|
-
return new logger_1.Logger(namespace, (0, enabled_1.isNamespaceEnabled)(
|
|
11
|
+
function createLogger(namespace) {
|
|
12
|
+
return new logger_1.Logger(namespace, (0, enabled_1.isNamespaceEnabled)(createLogger.getNamespaces(), namespace));
|
|
14
13
|
}
|
|
15
|
-
exports.
|
|
16
|
-
|
|
17
|
-
logFactory.Timer = timer_1.Timer;
|
|
18
|
-
logFactory.getNamespaces = function () {
|
|
14
|
+
exports.createLogger = createLogger;
|
|
15
|
+
createLogger.getNamespaces = function () {
|
|
19
16
|
return process.env.DEBUG || '';
|
|
20
17
|
};
|
|
21
|
-
|
|
18
|
+
createLogger.configure = function (options) {
|
|
22
19
|
logger_1.Logger.configure(options);
|
|
23
20
|
};
|
|
24
|
-
|
|
25
|
-
exports.default = logFactory;
|
|
26
|
-
module.exports = logFactory;
|
|
21
|
+
createLogger.formatter = formatter_1.formatter;
|
package/dist/logger/logger.js
CHANGED
|
@@ -76,18 +76,18 @@ class Logger {
|
|
|
76
76
|
if (!stack) {
|
|
77
77
|
return;
|
|
78
78
|
}
|
|
79
|
-
return stack.length > STACK_TRACE_LIMIT
|
|
80
|
-
|
|
81
|
-
|
|
79
|
+
return stack.length > STACK_TRACE_LIMIT ?
|
|
80
|
+
stack.substring(0, STACK_TRACE_LIMIT) + ' ...' :
|
|
81
|
+
stack;
|
|
82
82
|
}
|
|
83
83
|
_shortenData(data) {
|
|
84
84
|
if (typeof data === 'undefined') {
|
|
85
85
|
return;
|
|
86
86
|
}
|
|
87
87
|
const stringifiedData = typeof data === 'object' ? JSON.stringify(data) : data;
|
|
88
|
-
return stringifiedData.length > DATA_LIMIT
|
|
89
|
-
|
|
90
|
-
|
|
88
|
+
return stringifiedData.length > DATA_LIMIT ?
|
|
89
|
+
stringifiedData.substring(0, DATA_LIMIT) + ' ...' :
|
|
90
|
+
stringifiedData;
|
|
91
91
|
}
|
|
92
92
|
_getErrorDetails(error) {
|
|
93
93
|
if (!(error instanceof Object)) {
|
|
@@ -102,8 +102,9 @@ class Logger {
|
|
|
102
102
|
return Object.assign(baseDetails, this._getAxiosErrorDetails(error));
|
|
103
103
|
}
|
|
104
104
|
_getAxiosErrorDetails(error) {
|
|
105
|
-
if (!error.isAxiosError)
|
|
105
|
+
if (!error.isAxiosError) {
|
|
106
106
|
return {};
|
|
107
|
+
}
|
|
107
108
|
return {
|
|
108
109
|
request_method: error.config.method,
|
|
109
110
|
request_url: error.config.url,
|
package/package.json
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@emartech/json-logger",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "7.0.0",
|
|
4
4
|
"description": "Tiny and fast json logger with namespace support",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"scripts": {
|
|
7
|
-
"test": "mocha --require ts-node/register ./src
|
|
8
|
-
"test:watch": "mocha --require ts-node/register ./src
|
|
7
|
+
"test": "mocha --require ts-node/register ./src --recursive",
|
|
8
|
+
"test:watch": "mocha --require ts-node/register ./src --recursive --watch",
|
|
9
|
+
"lint": "eslint ./src/**/*.{ts,js}",
|
|
9
10
|
"build": "rm -rf dist && tsc --project ./tsconfig.json",
|
|
10
11
|
"semantic-release": "CI=true semantic-release",
|
|
11
12
|
"example-js": "DEBUG=* node examples/index-js.js",
|
|
@@ -27,13 +28,16 @@
|
|
|
27
28
|
"debug",
|
|
28
29
|
"json"
|
|
29
30
|
],
|
|
30
|
-
"dependencies": {
|
|
31
|
-
"chalk": "4.1.2"
|
|
32
|
-
},
|
|
31
|
+
"dependencies": {},
|
|
33
32
|
"devDependencies": {
|
|
34
33
|
"@emartech/cls-adapter": "1.3.0",
|
|
35
34
|
"@types/node": "18.7.2",
|
|
35
|
+
"@typescript-eslint/parser": "5.35.1",
|
|
36
36
|
"chai": "4.3.6",
|
|
37
|
+
"eslint": "7.21.0",
|
|
38
|
+
"eslint-config-emarsys": "5.1.0",
|
|
39
|
+
"eslint-plugin-no-only-tests": "2.4.0",
|
|
40
|
+
"eslint-plugin-security": "1.4.0",
|
|
37
41
|
"express": "4.18.1",
|
|
38
42
|
"koa": "2.13.4",
|
|
39
43
|
"mocha": "10.0.0",
|
package/dist/formatter/debug.js
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.debugFormatter = void 0;
|
|
4
|
-
const color_name_1 = require("../output/color-name/color-name");
|
|
5
|
-
const stringify_level_1 = require("../output/stringify-level/stringify-level");
|
|
6
|
-
const format_time_1 = require("../output/format-time/format-time");
|
|
7
|
-
const format_body_1 = require("../output/format-body/format-body");
|
|
8
|
-
const formatTime = new format_time_1.FormatTime();
|
|
9
|
-
function debugFormatter(log) {
|
|
10
|
-
return [
|
|
11
|
-
color_name_1.ColorName.addColor(log.name),
|
|
12
|
-
(0, stringify_level_1.stringifyLevel)(log.level),
|
|
13
|
-
formatTime.elapsedTime(),
|
|
14
|
-
(0, format_body_1.formatBody)(log)
|
|
15
|
-
].join(' ');
|
|
16
|
-
}
|
|
17
|
-
exports.debugFormatter = debugFormatter;
|
|
18
|
-
;
|
|
@@ -1,27 +0,0 @@
|
|
|
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.ColorName = void 0;
|
|
7
|
-
const chalk_1 = __importDefault(require("chalk"));
|
|
8
|
-
const colors = ['cyan', 'magenta', 'grey', 'blue', 'green', 'yellow', 'white', 'red'];
|
|
9
|
-
class ColorName {
|
|
10
|
-
static addColor(name) {
|
|
11
|
-
if (!this.names[name]) {
|
|
12
|
-
this.names[name] = { color: this.counter % colors.length };
|
|
13
|
-
this.counter++;
|
|
14
|
-
}
|
|
15
|
-
const color = colors[this.names[name].color];
|
|
16
|
-
// @ts-ignore
|
|
17
|
-
return chalk_1.default[color](name);
|
|
18
|
-
}
|
|
19
|
-
static reset() {
|
|
20
|
-
this.counter = 0;
|
|
21
|
-
this.names = {};
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
exports.ColorName = ColorName;
|
|
25
|
-
ColorName.counter = 0;
|
|
26
|
-
ColorName.colors = colors;
|
|
27
|
-
ColorName.names = {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function formatBody(logBody: any): string;
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.formatBody = void 0;
|
|
4
|
-
function formatBody(logBody) {
|
|
5
|
-
const log = Object.assign({}, logBody);
|
|
6
|
-
delete log.name;
|
|
7
|
-
delete log.level;
|
|
8
|
-
delete log.v;
|
|
9
|
-
delete log.pid;
|
|
10
|
-
delete log.hostname;
|
|
11
|
-
delete log.time;
|
|
12
|
-
if (!log.msg) {
|
|
13
|
-
delete log.msg;
|
|
14
|
-
}
|
|
15
|
-
const keys = Object.keys(log);
|
|
16
|
-
return keys
|
|
17
|
-
.sort()
|
|
18
|
-
.map(function (key) {
|
|
19
|
-
return key + '=' + JSON.stringify(log[key]);
|
|
20
|
-
})
|
|
21
|
-
.join(' ');
|
|
22
|
-
}
|
|
23
|
-
exports.formatBody = formatBody;
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.FormatTime = void 0;
|
|
4
|
-
class FormatTime {
|
|
5
|
-
constructor() {
|
|
6
|
-
this.lastLog = 0;
|
|
7
|
-
}
|
|
8
|
-
elapsedTime() {
|
|
9
|
-
const current = this.getCurrentTime();
|
|
10
|
-
let elapsed = 0;
|
|
11
|
-
if (this.lastLog) {
|
|
12
|
-
elapsed = current - this.lastLog;
|
|
13
|
-
}
|
|
14
|
-
this.lastLog = current;
|
|
15
|
-
return '+' + elapsed + 'ms';
|
|
16
|
-
}
|
|
17
|
-
getCurrentTime() {
|
|
18
|
-
return new Date().getTime();
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
exports.FormatTime = FormatTime;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function stringifyLevel(level: string): string;
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.stringifyLevel = void 0;
|
|
4
|
-
const config_1 = require("../../config");
|
|
5
|
-
function stringifyLevel(level) {
|
|
6
|
-
return config_1.config.coloredNames[level];
|
|
7
|
-
}
|
|
8
|
-
exports.stringifyLevel = stringifyLevel;
|