@emartech/json-logger 5.0.0 → 5.0.1
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/README.md +1 -2
- package/dist/config.d.ts +10 -0
- package/dist/config.js +39 -0
- package/dist/enabled/enabled.d.ts +1 -0
- package/dist/enabled/enabled.js +33 -0
- package/dist/formatter/debug.d.ts +6 -0
- package/dist/formatter/debug.js +18 -0
- package/dist/formatter/index.d.ts +8 -0
- package/dist/formatter/index.js +11 -0
- package/dist/formatter/json.d.ts +1 -0
- package/dist/formatter/json.js +7 -0
- package/dist/formatter/logentries.d.ts +1 -0
- package/dist/formatter/logentries.js +24 -0
- package/dist/index.d.ts +16 -0
- package/dist/index.js +26 -0
- package/dist/logger/logger.d.ts +55 -0
- package/dist/logger/logger.js +121 -0
- package/dist/output/color-name/color-name.d.ts +11 -0
- package/dist/output/color-name/color-name.js +27 -0
- package/dist/output/console.d.ts +1 -0
- package/dist/output/console.js +7 -0
- package/dist/output/format-body/format-body.d.ts +1 -0
- package/dist/output/format-body/format-body.js +23 -0
- package/dist/output/format-time/format-time.d.ts +5 -0
- package/dist/output/format-time/format-time.js +21 -0
- package/dist/output/stringify-level/stringify-level.d.ts +1 -0
- package/dist/output/stringify-level/stringify-level.js +8 -0
- package/dist/timer/timer.d.ts +15 -0
- package/dist/timer/timer.js +38 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
# @emartech/json-logger
|
|
2
2
|
|
|
3
3
|
A tiny and fast logging library that outputs logs in JSON format.
|
|
4
|
-
It has the same namespace based enabling/disabling mechanism as [debug]
|
|
5
|
-
and has the same log levels as [bunyan].
|
|
4
|
+
It has the same namespace based enabling/disabling mechanism as [debug].
|
|
6
5
|
|
|
7
6
|
### Installation
|
|
8
7
|
|
package/dist/config.d.ts
ADDED
package/dist/config.js
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
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.config = void 0;
|
|
7
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
8
|
+
const levels = {
|
|
9
|
+
trace: {
|
|
10
|
+
number: 10,
|
|
11
|
+
name: 'TRACE'
|
|
12
|
+
},
|
|
13
|
+
debug: {
|
|
14
|
+
number: 20,
|
|
15
|
+
name: 'DEBUG'
|
|
16
|
+
},
|
|
17
|
+
info: {
|
|
18
|
+
number: 30,
|
|
19
|
+
name: 'INFO'
|
|
20
|
+
},
|
|
21
|
+
warn: {
|
|
22
|
+
number: 40,
|
|
23
|
+
name: chalk_1.default.yellow('WARN')
|
|
24
|
+
},
|
|
25
|
+
error: {
|
|
26
|
+
number: 50,
|
|
27
|
+
name: chalk_1.default.red('ERROR')
|
|
28
|
+
},
|
|
29
|
+
fatal: {
|
|
30
|
+
number: 60,
|
|
31
|
+
name: chalk_1.default.red('FATAL')
|
|
32
|
+
},
|
|
33
|
+
};
|
|
34
|
+
const availableLevels = Object.keys(levels);
|
|
35
|
+
const coloredNames = {};
|
|
36
|
+
availableLevels.forEach((levelName) => {
|
|
37
|
+
coloredNames[levels[levelName].number] = levels[levelName].name;
|
|
38
|
+
});
|
|
39
|
+
exports.config = { levels, availableLevels, coloredNames };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function isNamespaceEnabled(availableNamespace: string, namespace: string): boolean;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isNamespaceEnabled = void 0;
|
|
4
|
+
function isNamespaceEnabled(availableNamespace, namespace) {
|
|
5
|
+
const availableNamespaces = availableNamespace.split(/[\s,]+/);
|
|
6
|
+
let enabled = false;
|
|
7
|
+
const adds = [];
|
|
8
|
+
const skips = [];
|
|
9
|
+
availableNamespaces.forEach(function (name) {
|
|
10
|
+
if (!name) {
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
name = name.replace(/\*/g, '.*?');
|
|
14
|
+
if (name[0] === '-') {
|
|
15
|
+
skips.push(new RegExp('^' + name.substr(1) + '$'));
|
|
16
|
+
}
|
|
17
|
+
else {
|
|
18
|
+
adds.push(new RegExp('^' + name + '$'));
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
adds.forEach(function (addRegexp) {
|
|
22
|
+
if (addRegexp.test(namespace)) {
|
|
23
|
+
enabled = true;
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
skips.forEach(function (addRegexp) {
|
|
27
|
+
if (addRegexp.test(namespace)) {
|
|
28
|
+
enabled = false;
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
return enabled;
|
|
32
|
+
}
|
|
33
|
+
exports.isNamespaceEnabled = isNamespaceEnabled;
|
|
@@ -0,0 +1,18 @@
|
|
|
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
|
+
;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { jsonFormatter } from './json';
|
|
2
|
+
import { logentriesFormatter } from './logentries';
|
|
3
|
+
import { debugFormatter } from './debug';
|
|
4
|
+
export declare const formatter: {
|
|
5
|
+
json: typeof jsonFormatter;
|
|
6
|
+
debug: typeof debugFormatter;
|
|
7
|
+
logentries: typeof logentriesFormatter;
|
|
8
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.formatter = void 0;
|
|
4
|
+
const json_1 = require("./json");
|
|
5
|
+
const logentries_1 = require("./logentries");
|
|
6
|
+
const debug_1 = require("./debug");
|
|
7
|
+
exports.formatter = {
|
|
8
|
+
json: json_1.jsonFormatter,
|
|
9
|
+
debug: debug_1.debugFormatter,
|
|
10
|
+
logentries: logentries_1.logentriesFormatter
|
|
11
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function jsonFormatter(log: unknown): string;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function logentriesFormatter(data: Record<string, unknown>): string;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.logentriesFormatter = void 0;
|
|
4
|
+
const isNumeric = (value) => !isNaN(parseFloat(value)) && isFinite(value);
|
|
5
|
+
const isString = (value) => typeof value === 'string' || value instanceof String;
|
|
6
|
+
const convertToTag = (value, key) => {
|
|
7
|
+
if (isString(value)) {
|
|
8
|
+
value = JSON.stringify(value);
|
|
9
|
+
}
|
|
10
|
+
else if (isNumeric(value)) {
|
|
11
|
+
value = value.toString();
|
|
12
|
+
}
|
|
13
|
+
else {
|
|
14
|
+
value = '"' + JSON.stringify(value) + '"';
|
|
15
|
+
}
|
|
16
|
+
return key + '=' + value;
|
|
17
|
+
};
|
|
18
|
+
function logentriesFormatter(data) {
|
|
19
|
+
return Object
|
|
20
|
+
.keys(data)
|
|
21
|
+
.map(key => convertToTag(data[key], key))
|
|
22
|
+
.join(' ');
|
|
23
|
+
}
|
|
24
|
+
exports.logentriesFormatter = logentriesFormatter;
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Logger, LoggerConfig } from './logger/logger';
|
|
2
|
+
export { Logger, LoggerConfig } from './logger/logger';
|
|
3
|
+
export { Timer } from './timer/timer';
|
|
4
|
+
export declare function logFactory(namespace: string): Logger;
|
|
5
|
+
export declare namespace logFactory {
|
|
6
|
+
var Logger: typeof import("./logger/logger").Logger;
|
|
7
|
+
var Timer: typeof import("./timer/timer").Timer;
|
|
8
|
+
var getNamespaces: () => string;
|
|
9
|
+
var configure: (options: LoggerConfig) => void;
|
|
10
|
+
var formatter: {
|
|
11
|
+
json: typeof import("./formatter/json").jsonFormatter;
|
|
12
|
+
debug: typeof import("./formatter/debug").debugFormatter;
|
|
13
|
+
logentries: typeof import("./formatter/logentries").logentriesFormatter;
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
export default logFactory;
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.logFactory = exports.Timer = exports.Logger = void 0;
|
|
4
|
+
const logger_1 = require("./logger/logger");
|
|
5
|
+
var logger_2 = require("./logger/logger");
|
|
6
|
+
Object.defineProperty(exports, "Logger", { enumerable: true, get: function () { return logger_2.Logger; } });
|
|
7
|
+
const timer_1 = require("./timer/timer");
|
|
8
|
+
var timer_2 = require("./timer/timer");
|
|
9
|
+
Object.defineProperty(exports, "Timer", { enumerable: true, get: function () { return timer_2.Timer; } });
|
|
10
|
+
const enabled_1 = require("./enabled/enabled");
|
|
11
|
+
const formatter_1 = require("./formatter");
|
|
12
|
+
function logFactory(namespace) {
|
|
13
|
+
return new logger_1.Logger(namespace, (0, enabled_1.isNamespaceEnabled)(logFactory.getNamespaces(), namespace));
|
|
14
|
+
}
|
|
15
|
+
exports.logFactory = logFactory;
|
|
16
|
+
logFactory.Logger = logger_1.Logger;
|
|
17
|
+
logFactory.Timer = timer_1.Timer;
|
|
18
|
+
logFactory.getNamespaces = function () {
|
|
19
|
+
return process.env.DEBUG || '';
|
|
20
|
+
};
|
|
21
|
+
logFactory.configure = function (options) {
|
|
22
|
+
logger_1.Logger.configure(options);
|
|
23
|
+
};
|
|
24
|
+
logFactory.formatter = formatter_1.formatter;
|
|
25
|
+
exports.default = logFactory;
|
|
26
|
+
module.exports = logFactory;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { Timer } from '../timer/timer';
|
|
2
|
+
interface AxiosError extends Error {
|
|
3
|
+
isAxiosError: boolean;
|
|
4
|
+
config: {
|
|
5
|
+
method: string;
|
|
6
|
+
url: string;
|
|
7
|
+
};
|
|
8
|
+
response?: {
|
|
9
|
+
status: number;
|
|
10
|
+
statusText: string;
|
|
11
|
+
data: string;
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
export interface LoggerConfig {
|
|
15
|
+
formatter: Function;
|
|
16
|
+
output: Function;
|
|
17
|
+
transformers: Function[];
|
|
18
|
+
}
|
|
19
|
+
export declare class Logger {
|
|
20
|
+
_namespace: string;
|
|
21
|
+
_enabled: boolean;
|
|
22
|
+
constructor(namespace: string, enabled: boolean);
|
|
23
|
+
static configure(options: LoggerConfig): void;
|
|
24
|
+
static _validate(options: LoggerConfig): void;
|
|
25
|
+
static config: LoggerConfig;
|
|
26
|
+
isEnabled(): boolean;
|
|
27
|
+
trace(action: string, data?: unknown): void;
|
|
28
|
+
debug(action: string, data?: unknown): void;
|
|
29
|
+
info(action: string, data?: unknown): void;
|
|
30
|
+
warn(action: string, data?: unknown): void;
|
|
31
|
+
error(action: string, data?: unknown): void;
|
|
32
|
+
fatal(action: string, data?: unknown): void;
|
|
33
|
+
_log(level: string, action: string, data: unknown): void;
|
|
34
|
+
customError(severity: string, action: string, error: Error, data?: unknown): void;
|
|
35
|
+
fromError(action: string, error: Error, data?: unknown): void;
|
|
36
|
+
warnFromError(action: string, error: Error, data?: unknown): void;
|
|
37
|
+
timer(): Timer;
|
|
38
|
+
_shortenStackTrace(stack: string): string | undefined;
|
|
39
|
+
_shortenData(data: unknown): string | undefined;
|
|
40
|
+
_getErrorDetails(error: Error): {};
|
|
41
|
+
_getAxiosErrorDetails(error: AxiosError): {
|
|
42
|
+
request_method?: undefined;
|
|
43
|
+
request_url?: undefined;
|
|
44
|
+
response_status?: undefined;
|
|
45
|
+
response_status_text?: undefined;
|
|
46
|
+
response_data?: undefined;
|
|
47
|
+
} | {
|
|
48
|
+
request_method: string;
|
|
49
|
+
request_url: string;
|
|
50
|
+
response_status: number | undefined;
|
|
51
|
+
response_status_text: string | undefined;
|
|
52
|
+
response_data: string | undefined;
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
export {};
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Logger = void 0;
|
|
4
|
+
const config_1 = require("../config");
|
|
5
|
+
const STACK_TRACE_LIMIT = 3000;
|
|
6
|
+
const DATA_LIMIT = 3000;
|
|
7
|
+
const timer_1 = require("../timer/timer");
|
|
8
|
+
const json_1 = require("../formatter/json");
|
|
9
|
+
const console_1 = require("../output/console");
|
|
10
|
+
const allowedKeys = ['output', 'formatter', 'transformers'];
|
|
11
|
+
class Logger {
|
|
12
|
+
constructor(namespace, enabled) {
|
|
13
|
+
this._namespace = namespace;
|
|
14
|
+
this._enabled = enabled;
|
|
15
|
+
}
|
|
16
|
+
static configure(options) {
|
|
17
|
+
this._validate(options);
|
|
18
|
+
Object.assign(Logger.config, options);
|
|
19
|
+
}
|
|
20
|
+
static _validate(options) {
|
|
21
|
+
Object.keys(options).forEach(key => {
|
|
22
|
+
if (!allowedKeys.includes(key)) {
|
|
23
|
+
throw new Error('Only the following keys are allowed: formatter, output');
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
isEnabled() {
|
|
28
|
+
return this._enabled;
|
|
29
|
+
}
|
|
30
|
+
trace(action, data = {}) {
|
|
31
|
+
this._log('trace', action, data);
|
|
32
|
+
}
|
|
33
|
+
debug(action, data = {}) {
|
|
34
|
+
this._log('debug', action, data);
|
|
35
|
+
}
|
|
36
|
+
info(action, data = {}) {
|
|
37
|
+
this._log('info', action, data);
|
|
38
|
+
}
|
|
39
|
+
warn(action, data = {}) {
|
|
40
|
+
this._log('warn', action, data);
|
|
41
|
+
}
|
|
42
|
+
error(action, data = {}) {
|
|
43
|
+
this._log('error', action, data);
|
|
44
|
+
}
|
|
45
|
+
fatal(action, data = {}) {
|
|
46
|
+
this._log('fatal', action, data);
|
|
47
|
+
}
|
|
48
|
+
_log(level, action, data) {
|
|
49
|
+
if (!this._enabled) {
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
let dataToLog = Object.assign({
|
|
53
|
+
name: this._namespace,
|
|
54
|
+
action: action,
|
|
55
|
+
level: config_1.config.levels[level].number,
|
|
56
|
+
time: new Date().toISOString()
|
|
57
|
+
}, data);
|
|
58
|
+
Logger.config.transformers.forEach((transform) => {
|
|
59
|
+
dataToLog = transform(dataToLog);
|
|
60
|
+
});
|
|
61
|
+
Logger.config.output(Logger.config.formatter(dataToLog));
|
|
62
|
+
}
|
|
63
|
+
customError(severity, action, error, data = {}) {
|
|
64
|
+
this._log(severity, action, Object.assign(this._getErrorDetails(error), data));
|
|
65
|
+
}
|
|
66
|
+
fromError(action, error, data = {}) {
|
|
67
|
+
this.customError('error', action, error, data);
|
|
68
|
+
}
|
|
69
|
+
warnFromError(action, error, data = {}) {
|
|
70
|
+
this.customError('warn', action, error, data);
|
|
71
|
+
}
|
|
72
|
+
timer() {
|
|
73
|
+
return new timer_1.Timer(this);
|
|
74
|
+
}
|
|
75
|
+
_shortenStackTrace(stack) {
|
|
76
|
+
if (!stack) {
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
return stack.length > STACK_TRACE_LIMIT
|
|
80
|
+
? stack.substring(0, STACK_TRACE_LIMIT) + ' ...'
|
|
81
|
+
: stack;
|
|
82
|
+
}
|
|
83
|
+
_shortenData(data) {
|
|
84
|
+
if (typeof data === 'undefined') {
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
const stringifiedData = typeof data === 'object' ? JSON.stringify(data) : data;
|
|
88
|
+
return stringifiedData.length > DATA_LIMIT
|
|
89
|
+
? stringifiedData.substring(0, DATA_LIMIT) + ' ...'
|
|
90
|
+
: stringifiedData;
|
|
91
|
+
}
|
|
92
|
+
_getErrorDetails(error) {
|
|
93
|
+
if (!(error instanceof Object)) {
|
|
94
|
+
return {};
|
|
95
|
+
}
|
|
96
|
+
const baseDetails = {
|
|
97
|
+
error_name: error.name,
|
|
98
|
+
error_stack: this._shortenStackTrace(error.stack || ''),
|
|
99
|
+
error_message: error.message,
|
|
100
|
+
error_data: this._shortenData(error.data)
|
|
101
|
+
};
|
|
102
|
+
return Object.assign(baseDetails, this._getAxiosErrorDetails(error));
|
|
103
|
+
}
|
|
104
|
+
_getAxiosErrorDetails(error) {
|
|
105
|
+
if (!error.isAxiosError)
|
|
106
|
+
return {};
|
|
107
|
+
return {
|
|
108
|
+
request_method: error.config.method,
|
|
109
|
+
request_url: error.config.url,
|
|
110
|
+
response_status: error.response ? error.response.status : undefined,
|
|
111
|
+
response_status_text: error.response ? error.response.statusText : undefined,
|
|
112
|
+
response_data: error.response ? this._shortenData(error.response.data) : undefined
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
exports.Logger = Logger;
|
|
117
|
+
Logger.config = {
|
|
118
|
+
formatter: json_1.jsonFormatter,
|
|
119
|
+
output: console_1.consoleOutput,
|
|
120
|
+
transformers: []
|
|
121
|
+
};
|
|
@@ -0,0 +1,27 @@
|
|
|
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 = {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function consoleOutput(formattedLog: unknown): void;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function formatBody(logBody: any): string;
|
|
@@ -0,0 +1,23 @@
|
|
|
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;
|
|
@@ -0,0 +1,21 @@
|
|
|
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;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function stringifyLevel(level: string): string;
|
|
@@ -0,0 +1,8 @@
|
|
|
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;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Logger } from '../logger/logger';
|
|
2
|
+
export declare class Timer {
|
|
3
|
+
_logger: Logger;
|
|
4
|
+
_start: number;
|
|
5
|
+
constructor(logger: Logger);
|
|
6
|
+
trace(action: string, data?: unknown): void;
|
|
7
|
+
debug(action: string, data?: unknown): void;
|
|
8
|
+
info(action: string, data?: unknown): void;
|
|
9
|
+
warn(action: string, data?: unknown): void;
|
|
10
|
+
error(action: string, data?: unknown): void;
|
|
11
|
+
fatal(action: string, data?: unknown): void;
|
|
12
|
+
fromError(action: string, error: Error, data?: unknown): void;
|
|
13
|
+
warnFromError(action: string, error: Error, data?: unknown): void;
|
|
14
|
+
_duration(): number;
|
|
15
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Timer = void 0;
|
|
4
|
+
class Timer {
|
|
5
|
+
constructor(logger) {
|
|
6
|
+
this._logger = logger;
|
|
7
|
+
this._start = new Date().getTime();
|
|
8
|
+
}
|
|
9
|
+
trace(action, data = {}) {
|
|
10
|
+
this._logger.trace(action, Object.assign({ duration: this._duration() }, data));
|
|
11
|
+
}
|
|
12
|
+
debug(action, data = {}) {
|
|
13
|
+
this._logger.debug(action, Object.assign({ duration: this._duration() }, data));
|
|
14
|
+
}
|
|
15
|
+
info(action, data = {}) {
|
|
16
|
+
this._logger.info(action, Object.assign({ duration: this._duration() }, data));
|
|
17
|
+
}
|
|
18
|
+
warn(action, data = {}) {
|
|
19
|
+
this._logger.warn(action, Object.assign({ duration: this._duration() }, data));
|
|
20
|
+
}
|
|
21
|
+
error(action, data = {}) {
|
|
22
|
+
this._logger.error(action, Object.assign({ duration: this._duration() }, data));
|
|
23
|
+
}
|
|
24
|
+
fatal(action, data = {}) {
|
|
25
|
+
this._logger.fatal(action, Object.assign({ duration: this._duration() }, data));
|
|
26
|
+
}
|
|
27
|
+
fromError(action, error, data = {}) {
|
|
28
|
+
this._logger.fromError(action, error, Object.assign({ duration: this._duration() }, data));
|
|
29
|
+
}
|
|
30
|
+
warnFromError(action, error, data = {}) {
|
|
31
|
+
this._logger.warnFromError(action, error, Object.assign({ duration: this._duration() }, data));
|
|
32
|
+
}
|
|
33
|
+
_duration() {
|
|
34
|
+
const end = new Date().getTime();
|
|
35
|
+
return end - this._start;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
exports.Timer = Timer;
|