@hg-ts/logger 0.1.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.
Files changed (55) hide show
  1. package/.eslintcache +1 -0
  2. package/.eslintrc.json +1 -0
  3. package/README.md +1 -0
  4. package/dist/colors.d.ts +10 -0
  5. package/dist/colors.d.ts.map +1 -0
  6. package/dist/colors.js +21 -0
  7. package/dist/colors.js.map +1 -0
  8. package/dist/console.logger.d.ts +21 -0
  9. package/dist/console.logger.d.ts.map +1 -0
  10. package/dist/console.logger.js +132 -0
  11. package/dist/console.logger.js.map +1 -0
  12. package/dist/index.d.ts +4 -0
  13. package/dist/index.d.ts.map +1 -0
  14. package/dist/index.js +10 -0
  15. package/dist/index.js.map +1 -0
  16. package/dist/logger.d.ts +13 -0
  17. package/dist/logger.d.ts.map +1 -0
  18. package/dist/logger.js +7 -0
  19. package/dist/logger.js.map +1 -0
  20. package/dist/mock.logger.d.ts +13 -0
  21. package/dist/mock.logger.d.ts.map +1 -0
  22. package/dist/mock.logger.js +17 -0
  23. package/dist/mock.logger.js.map +1 -0
  24. package/dist/syslog.logger.d.ts +20 -0
  25. package/dist/syslog.logger.d.ts.map +1 -0
  26. package/dist/syslog.logger.js +132 -0
  27. package/dist/syslog.logger.js.map +1 -0
  28. package/dist-esm/colors.d.ts +10 -0
  29. package/dist-esm/colors.d.ts.map +1 -0
  30. package/dist-esm/colors.js +17 -0
  31. package/dist-esm/colors.js.map +1 -0
  32. package/dist-esm/console.logger.d.ts +21 -0
  33. package/dist-esm/console.logger.d.ts.map +1 -0
  34. package/dist-esm/console.logger.js +127 -0
  35. package/dist-esm/console.logger.js.map +1 -0
  36. package/dist-esm/index.d.ts +4 -0
  37. package/dist-esm/index.d.ts.map +1 -0
  38. package/dist-esm/index.js +4 -0
  39. package/dist-esm/index.js.map +1 -0
  40. package/dist-esm/logger.d.ts +13 -0
  41. package/dist-esm/logger.d.ts.map +1 -0
  42. package/dist-esm/logger.js +3 -0
  43. package/dist-esm/logger.js.map +1 -0
  44. package/dist-esm/mock.logger.d.ts +13 -0
  45. package/dist-esm/mock.logger.d.ts.map +1 -0
  46. package/dist-esm/mock.logger.js +13 -0
  47. package/dist-esm/mock.logger.js.map +1 -0
  48. package/package.json +39 -0
  49. package/src/colors.ts +18 -0
  50. package/src/console.logger.ts +166 -0
  51. package/src/index.ts +3 -0
  52. package/src/logger.ts +12 -0
  53. package/src/mock.logger.ts +14 -0
  54. package/tsconfig.esm.json +9 -0
  55. package/tsconfig.json +9 -0
package/.eslintcache ADDED
@@ -0,0 +1 @@
1
+ [{"/Volumes/Work/ts/hg/framework/packages/exception/src/consts.ts":"1","/Volumes/Work/ts/hg/framework/packages/exception/src/exceptions/aggregate-error.exception.ts":"2","/Volumes/Work/ts/hg/framework/packages/exception/src/exceptions/base.aggregate.exception.ts":"3","/Volumes/Work/ts/hg/framework/packages/exception/src/exceptions/base.exception.ts":"4","/Volumes/Work/ts/hg/framework/packages/exception/src/exceptions/error.exception.ts":"5","/Volumes/Work/ts/hg/framework/packages/exception/src/exceptions/forbidden.exception.ts":"6","/Volumes/Work/ts/hg/framework/packages/exception/src/exceptions/index.ts":"7","/Volumes/Work/ts/hg/framework/packages/exception/src/exceptions/not-implemented.exception.ts":"8","/Volumes/Work/ts/hg/framework/packages/exception/src/exceptions/unknown.exception.ts":"9","/Volumes/Work/ts/hg/framework/packages/exception/src/exceptions/will-never-happened.exception.ts":"10","/Volumes/Work/ts/hg/framework/packages/exception/src/index.ts":"11","/Volumes/Work/ts/hg/framework/packages/exception/src/tests/serialization.test-suite.ts":"12","/Volumes/Work/ts/hg/framework/packages/exception/src/tests/test.aggregate-exception.ts":"13","/Volumes/Work/ts/hg/framework/packages/exception/src/tests/test.exception.ts":"14","/Volumes/Work/ts/hg/framework/packages/exception/src/utils/index.ts":"15","/Volumes/Work/ts/hg/framework/packages/exception/src/utils/stack-trace.formatter.ts":"16","/Volumes/Work/ts/hg/framework/packages/ioc/src/index.ts":"17","/Volumes/Work/ts/hg/framework/packages/logger/src/index.ts":"18","/Volumes/Work/ts/hg/framework/packages/logger/src/colors.ts":"19","/Volumes/Work/ts/hg/framework/packages/logger/src/console.logger.ts":"20","/Volumes/Work/ts/hg/framework/packages/logger/src/logger.ts":"21","/Volumes/Work/ts/hg/framework/packages/logger/src/mock.logger.ts":"22"},{"size":73,"mtime":1659719206461,"results":"23","hashOfConfig":"24"},{"size":656,"mtime":1631395128717,"results":"25","hashOfConfig":"24"},{"size":1377,"mtime":1660867889450,"results":"26","hashOfConfig":"24"},{"size":3220,"mtime":1664331682837,"results":"27","hashOfConfig":"24"},{"size":375,"mtime":1658005568468,"results":"28","hashOfConfig":"24"},{"size":108,"mtime":1643091718782,"results":"29","hashOfConfig":"24"},{"size":418,"mtime":1643091718779,"results":"30","hashOfConfig":"24"},{"size":169,"mtime":1626299896345,"results":"31","hashOfConfig":"24"},{"size":167,"mtime":1626299896345,"results":"32","hashOfConfig":"24"},{"size":177,"mtime":1626299896345,"results":"33","hashOfConfig":"24"},{"size":53,"mtime":1665300013469,"results":"34","hashOfConfig":"24"},{"size":3373,"mtime":1665300013444,"results":"35","hashOfConfig":"24"},{"size":430,"mtime":1660867792014,"results":"36","hashOfConfig":"24"},{"size":186,"mtime":1657995065457,"results":"37","hashOfConfig":"24"},{"size":41,"mtime":1626299896346,"results":"38","hashOfConfig":"24"},{"size":930,"mtime":1659719246420,"results":"39","hashOfConfig":"24"},{"size":86,"mtime":1672804565919,"results":"40","hashOfConfig":"41"},{"size":129,"mtime":1698022585983,"results":"42","hashOfConfig":"43"},{"size":331,"mtime":1688235091950,"results":"44","hashOfConfig":"43"},{"size":3987,"mtime":1688235091950,"results":"45","hashOfConfig":"43"},{"size":537,"mtime":1688235091951,"results":"46","hashOfConfig":"43"},{"size":319,"mtime":1688235091951,"results":"47","hashOfConfig":"43"},{"filePath":"48","messages":"49","suppressedMessages":"50","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},"1hmldtr",{"filePath":"51","messages":"52","suppressedMessages":"53","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"54","messages":"55","suppressedMessages":"56","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"57","messages":"58","suppressedMessages":"59","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"60","messages":"61","suppressedMessages":"62","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"63","messages":"64","suppressedMessages":"65","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"66","messages":"67","suppressedMessages":"68","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"69","messages":"70","suppressedMessages":"71","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"72","messages":"73","suppressedMessages":"74","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"75","messages":"76","suppressedMessages":"77","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"78","messages":"79","suppressedMessages":"80","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"81","messages":"82","suppressedMessages":"83","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"84","messages":"85","suppressedMessages":"86","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"87","messages":"88","suppressedMessages":"89","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"90","messages":"91","suppressedMessages":"92","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"93","messages":"94","suppressedMessages":"95","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"96","messages":"97","suppressedMessages":"98","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},"59fpe9",{"filePath":"99","messages":"100","suppressedMessages":"101","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},"urvkzr",{"filePath":"102","messages":"103","suppressedMessages":"104","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"105","messages":"106","suppressedMessages":"107","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"108","messages":"109","suppressedMessages":"110","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"111","messages":"112","suppressedMessages":"113","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},"/Volumes/Work/ts/hg/framework/packages/exception/src/consts.ts",[],[],"/Volumes/Work/ts/hg/framework/packages/exception/src/exceptions/aggregate-error.exception.ts",[],[],"/Volumes/Work/ts/hg/framework/packages/exception/src/exceptions/base.aggregate.exception.ts",[],[],"/Volumes/Work/ts/hg/framework/packages/exception/src/exceptions/base.exception.ts",[],[],"/Volumes/Work/ts/hg/framework/packages/exception/src/exceptions/error.exception.ts",[],["114"],"/Volumes/Work/ts/hg/framework/packages/exception/src/exceptions/forbidden.exception.ts",[],[],"/Volumes/Work/ts/hg/framework/packages/exception/src/exceptions/index.ts",[],[],"/Volumes/Work/ts/hg/framework/packages/exception/src/exceptions/not-implemented.exception.ts",[],[],"/Volumes/Work/ts/hg/framework/packages/exception/src/exceptions/unknown.exception.ts",[],[],"/Volumes/Work/ts/hg/framework/packages/exception/src/exceptions/will-never-happened.exception.ts",[],[],"/Volumes/Work/ts/hg/framework/packages/exception/src/index.ts",[],[],"/Volumes/Work/ts/hg/framework/packages/exception/src/tests/serialization.test-suite.ts",[],[],"/Volumes/Work/ts/hg/framework/packages/exception/src/tests/test.aggregate-exception.ts",[],[],"/Volumes/Work/ts/hg/framework/packages/exception/src/tests/test.exception.ts",[],[],"/Volumes/Work/ts/hg/framework/packages/exception/src/utils/index.ts",[],[],"/Volumes/Work/ts/hg/framework/packages/exception/src/utils/stack-trace.formatter.ts",[],[],"/Volumes/Work/ts/hg/framework/packages/ioc/src/index.ts",[],[],"/Volumes/Work/ts/hg/framework/packages/logger/src/index.ts",[],[],"/Volumes/Work/ts/hg/framework/packages/logger/src/colors.ts",[],[],"/Volumes/Work/ts/hg/framework/packages/logger/src/console.logger.ts",[],[],"/Volumes/Work/ts/hg/framework/packages/logger/src/logger.ts",[],[],"/Volumes/Work/ts/hg/framework/packages/logger/src/mock.logger.ts",[],[],{"ruleId":"115","severity":2,"message":"116","line":11,"column":7,"nodeType":"117","messageId":"118","endLine":11,"endColumn":16,"suppressions":"119"},"no-undefined","Unexpected use of undefined.","Identifier","unexpectedUndefined",["120"],{"kind":"121","justification":"122"},"directive",""]
package/.eslintrc.json ADDED
@@ -0,0 +1 @@
1
+ { "extends": "@hg-ts-config/eslint-config" }
package/README.md ADDED
@@ -0,0 +1 @@
1
+ # @hg/exception
@@ -0,0 +1,10 @@
1
+ export declare enum COLOR {
2
+ ORANGE = "38;5;3",
3
+ GREEN = "32",
4
+ YELLOW = "33",
5
+ RED = "31",
6
+ MAGENTA_BRIGHT = "95",
7
+ CYAN_BRIGHT = "96"
8
+ }
9
+ export declare function colorize(color: COLOR, text: string): string;
10
+ //# sourceMappingURL=colors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"colors.d.ts","sourceRoot":"","sources":["../src/colors.ts"],"names":[],"mappings":"AAEA,oBAAY,KAAK;IAChB,MAAM,WAAW;IACjB,KAAK,OAAO;IACZ,MAAM,OAAO;IACb,GAAG,OAAO;IACV,cAAc,OAAO;IACrB,WAAW,OAAO;CAClB;AAED,wBAAgB,QAAQ,CAAC,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAM3D"}
package/dist/colors.js ADDED
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.colorize = exports.COLOR = void 0;
4
+ const isColorAllowed = !process.env['NO_COLOR'];
5
+ var COLOR;
6
+ (function (COLOR) {
7
+ COLOR["ORANGE"] = "38;5;3";
8
+ COLOR["GREEN"] = "32";
9
+ COLOR["YELLOW"] = "33";
10
+ COLOR["RED"] = "31";
11
+ COLOR["MAGENTA_BRIGHT"] = "95";
12
+ COLOR["CYAN_BRIGHT"] = "96";
13
+ })(COLOR || (exports.COLOR = COLOR = {}));
14
+ function colorize(color, text) {
15
+ if (!isColorAllowed) {
16
+ return text;
17
+ }
18
+ return `\x1B[${color}m${text}\x1B[39m`;
19
+ }
20
+ exports.colorize = colorize;
21
+ //# sourceMappingURL=colors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"colors.js","sourceRoot":"","sources":["../src/colors.ts"],"names":[],"mappings":";;;AAAA,MAAM,cAAc,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;AAEhD,IAAY,KAOX;AAPD,WAAY,KAAK;IAChB,0BAAiB,CAAA;IACjB,qBAAY,CAAA;IACZ,sBAAa,CAAA;IACb,mBAAU,CAAA;IACV,8BAAqB,CAAA;IACrB,2BAAkB,CAAA;AACnB,CAAC,EAPW,KAAK,qBAAL,KAAK,QAOhB;AAED,SAAgB,QAAQ,CAAC,KAAY,EAAE,IAAY;IAClD,IAAI,CAAC,cAAc,EAAE;QACpB,OAAO,IAAI,CAAC;KACZ;IAED,OAAO,QAAQ,KAAK,IAAI,IAAI,UAAU,CAAC;AACxC,CAAC;AAND,4BAMC"}
@@ -0,0 +1,21 @@
1
+ /// <reference types="@hg-ts/types" />
2
+ import { Logger } from './logger';
3
+ type LogLevel = keyof Omit<Logger, 'setContext'>;
4
+ export declare const logLevelPriority: readonly LogLevel[];
5
+ export declare class ConsoleLogger extends Logger {
6
+ protected context: Nullable<string>;
7
+ private readonly logger;
8
+ constructor();
9
+ debug(...messages: unknown[]): void;
10
+ info(...messages: unknown[]): void;
11
+ notice(...messages: unknown[]): void;
12
+ warning(...messages: unknown[]): void;
13
+ error(...messages: unknown[]): void;
14
+ critical(...messages: unknown[]): void;
15
+ alert(...messages: unknown[]): void;
16
+ emergency(...messages: unknown[]): void;
17
+ setContext(context: Nullable<string>): void;
18
+ private log;
19
+ }
20
+ export {};
21
+ //# sourceMappingURL=console.logger.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"console.logger.d.ts","sourceRoot":"","sources":["../src/console.logger.ts"],"names":[],"mappings":";AASA,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAElC,KAAK,QAAQ,GAAG,MAAM,IAAI,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC;AAoBjD,eAAO,MAAM,gBAAgB,EAAE,SAAS,QAAQ,EAStC,CAAC;AAkEX,qBAAa,aAAc,SAAQ,MAAM;IACxC,SAAS,CAAC,OAAO,EAAE,QAAQ,CAAC,MAAM,CAAC,CAAQ;IAC3C,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAiB;;IAmBjC,KAAK,CAAC,GAAG,QAAQ,EAAE,OAAO,EAAE,GAAG,IAAI;IAGnC,IAAI,CAAC,GAAG,QAAQ,EAAE,OAAO,EAAE,GAAG,IAAI;IAGlC,MAAM,CAAC,GAAG,QAAQ,EAAE,OAAO,EAAE,GAAG,IAAI;IAGpC,OAAO,CAAC,GAAG,QAAQ,EAAE,OAAO,EAAE,GAAG,IAAI;IAGrC,KAAK,CAAC,GAAG,QAAQ,EAAE,OAAO,EAAE,GAAG,IAAI;IAGnC,QAAQ,CAAC,GAAG,QAAQ,EAAE,OAAO,EAAE,GAAG,IAAI;IAGtC,KAAK,CAAC,GAAG,QAAQ,EAAE,OAAO,EAAE,GAAG,IAAI;IAGnC,SAAS,CAAC,GAAG,QAAQ,EAAE,OAAO,EAAE,GAAG,IAAI;IAIvC,UAAU,CAAC,OAAO,EAAE,QAAQ,CAAC,MAAM,CAAC,GAAG,IAAI;IAIlD,OAAO,CAAC,GAAG;CASX"}
@@ -0,0 +1,132 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ConsoleLogger = exports.logLevelPriority = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const node_util_1 = require("node:util");
6
+ const winston_1 = tslib_1.__importDefault(require("winston"));
7
+ const triple_beam_1 = require("triple-beam");
8
+ const colors_1 = require("./colors");
9
+ const logger_1 = require("./logger");
10
+ const colorsMap = new Map()
11
+ .set('emergency', colors_1.COLOR.RED)
12
+ .set('alert', colors_1.COLOR.RED)
13
+ .set('critical', colors_1.COLOR.RED)
14
+ .set('error', colors_1.COLOR.RED)
15
+ .set('warning', colors_1.COLOR.YELLOW)
16
+ .set('notice', colors_1.COLOR.GREEN)
17
+ .set('info', colors_1.COLOR.CYAN_BRIGHT)
18
+ .set('debug', colors_1.COLOR.MAGENTA_BRIGHT);
19
+ const syslogToLoggerMap = new Map()
20
+ .set('emerg', 'emergency')
21
+ .set('crit', 'critical');
22
+ const loggerToSyslogMap = new Map()
23
+ .set('emergency', 'emerg')
24
+ .set('critical', 'crit');
25
+ exports.logLevelPriority = [
26
+ 'emergency',
27
+ 'alert',
28
+ 'critical',
29
+ 'error',
30
+ 'warning',
31
+ 'notice',
32
+ 'info',
33
+ 'debug',
34
+ ];
35
+ const levelFormat = winston_1.default.format(info => {
36
+ info[triple_beam_1.LEVEL] = info.level;
37
+ const mappedLevel = syslogToLoggerMap.get(info[triple_beam_1.LEVEL]) ?? info[triple_beam_1.LEVEL];
38
+ const levelColor = colorsMap.get(mappedLevel);
39
+ info.level = `<${(0, colors_1.colorize)(levelColor, mappedLevel)}>`;
40
+ return info;
41
+ });
42
+ const contextFormat = winston_1.default.format(info => {
43
+ if (info['context']) {
44
+ info['context'] = (0, colors_1.colorize)(colors_1.COLOR.ORANGE, info['context']);
45
+ info['context'] = `[${info['context']}]`;
46
+ }
47
+ return info;
48
+ });
49
+ const colorizeFormat = winston_1.default.format(info => {
50
+ const mappedLevel = syslogToLoggerMap.get(info[triple_beam_1.LEVEL]) ?? info[triple_beam_1.LEVEL];
51
+ const levelColor = colorsMap.get(mappedLevel);
52
+ info[triple_beam_1.MESSAGE] = (0, colors_1.colorize)(levelColor, info.message);
53
+ return info;
54
+ });
55
+ const processInfoFormat = winston_1.default.format(info => {
56
+ if (process.title.endsWith('node')) {
57
+ info['process'] = `[pid: ${process.pid}]`;
58
+ }
59
+ else {
60
+ info['process'] = `[${process.title}: ${process.pid}]`;
61
+ }
62
+ return info;
63
+ });
64
+ const timeFormat = winston_1.default.format(info => {
65
+ info['timestamp'] = new Date().toLocaleString('ru-RU');
66
+ return info;
67
+ });
68
+ const customFormat = winston_1.default.format(info => {
69
+ const { process, timestamp, context, level, [triple_beam_1.MESSAGE]: message } = info;
70
+ const metaInfoItems = [timestamp, context, level, process];
71
+ const metaInfo = metaInfoItems.join(' ');
72
+ info[triple_beam_1.MESSAGE] = `${metaInfo}: ${message}`;
73
+ return info;
74
+ });
75
+ const consoleTransport = new winston_1.default.transports.Console({
76
+ format: winston_1.default.format.combine(levelFormat(), contextFormat(), processInfoFormat(), colorizeFormat(), timeFormat(), customFormat()),
77
+ });
78
+ class ConsoleLogger extends logger_1.Logger {
79
+ context = null;
80
+ logger;
81
+ constructor() {
82
+ super();
83
+ const logLevel = 'debug';
84
+ this.context = 'test';
85
+ this.logger = winston_1.default.createLogger({
86
+ level: logLevel,
87
+ levels: winston_1.default.config.syslog.levels,
88
+ format: customFormat(),
89
+ transports: [consoleTransport],
90
+ handleExceptions: true,
91
+ handleRejections: true,
92
+ exitOnError: false,
93
+ });
94
+ }
95
+ debug(...messages) {
96
+ this.log('debug', messages);
97
+ }
98
+ info(...messages) {
99
+ this.log('info', messages);
100
+ }
101
+ notice(...messages) {
102
+ this.log('notice', messages);
103
+ }
104
+ warning(...messages) {
105
+ this.log('warning', messages);
106
+ }
107
+ error(...messages) {
108
+ this.log('error', messages);
109
+ }
110
+ critical(...messages) {
111
+ this.log('critical', messages);
112
+ }
113
+ alert(...messages) {
114
+ this.log('alert', messages);
115
+ }
116
+ emergency(...messages) {
117
+ this.log('emergency', messages);
118
+ }
119
+ setContext(context) {
120
+ this.context = context;
121
+ }
122
+ log(level, messages) {
123
+ const mappedLevel = loggerToSyslogMap.get(level) ?? level;
124
+ this.logger.log({
125
+ level: mappedLevel,
126
+ message: (0, node_util_1.format)(...messages),
127
+ context: this.context,
128
+ });
129
+ }
130
+ }
131
+ exports.ConsoleLogger = ConsoleLogger;
132
+ //# sourceMappingURL=console.logger.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"console.logger.js","sourceRoot":"","sources":["../src/console.logger.ts"],"names":[],"mappings":";;;;AAAA,yCAAmC;AACnC,8DAA8B;AAC9B,6CAA6C;AAG7C,qCAGkB;AAClB,qCAAkC;AAIlC,MAAM,SAAS,GAAG,IAAI,GAAG,EAAmB;KAC1C,GAAG,CAAC,WAAW,EAAE,cAAK,CAAC,GAAG,CAAC;KAC3B,GAAG,CAAC,OAAO,EAAE,cAAK,CAAC,GAAG,CAAC;KACvB,GAAG,CAAC,UAAU,EAAE,cAAK,CAAC,GAAG,CAAC;KAC1B,GAAG,CAAC,OAAO,EAAE,cAAK,CAAC,GAAG,CAAC;KACvB,GAAG,CAAC,SAAS,EAAE,cAAK,CAAC,MAAM,CAAC;KAC5B,GAAG,CAAC,QAAQ,EAAE,cAAK,CAAC,KAAK,CAAC;KAC1B,GAAG,CAAC,MAAM,EAAE,cAAK,CAAC,WAAW,CAAC;KAC9B,GAAG,CA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GAAG,QAAmB;QACnC,IAAI,CAAC,GAAG,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC;IAC9B,CAAC;IACM,OAAO,CAAC,GAAG,QAAmB;QACpC,IAAI,CAAC,GAAG,CAAC,SAAS,EAAE,QAAQ,CAAC,CAAC;IAC/B,CAAC;IACM,KAAK,CAAC,GAAG,QAAmB;QAClC,IAAI,CAAC,GAAG,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC;IAC7B,CAAC;IACM,QAAQ,CAAC,GAAG,QAAmB;QACrC,IAAI,CAAC,GAAG,CAAC,UAAU,EAAE,QAAQ,CAAC,CAAC;IAChC,CAAC;IACM,KAAK,CAAC,GAAG,QAAmB;QAClC,IAAI,CAAC,GAAG,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC;IAC7B,CAAC;IACM,SAAS,CAAC,GAAG,QAAmB;QACtC,IAAI,CAAC,GAAG,CAAC,WAAW,EAAE,QAAQ,CAAC,CAAC;IACjC,CAAC;IAEM,UAAU,CAAC,OAAyB;QAC1C,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;IACxB,CAAC;IAEO,GAAG,CAAC,KAAe,EAAE,QAAmB;QAC/C,MAAM,WAAW,GAAG,iBAAiB,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,KAAK,CAAC;QAE1D,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC;YACf,KAAK,EAAE,WAAW;YAClB,OAAO,EAAE,IAAA,kBAAM,EAAC,GAAG,QAAQ,CAAC;YAC5B,OAAO,EAAE,IAAI,CAAC,OAAO;SACrB,CAAC,CAAC;IACJ,CAAC;CACD;AA3DD,sCA2DC"}
@@ -0,0 +1,4 @@
1
+ export { Logger } from './logger';
2
+ export { MockLogger } from './mock.logger';
3
+ export { ConsoleLogger } from './console.logger';
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAClC,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC3C,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ConsoleLogger = exports.MockLogger = exports.Logger = void 0;
4
+ var logger_1 = require("./logger");
5
+ Object.defineProperty(exports, "Logger", { enumerable: true, get: function () { return logger_1.Logger; } });
6
+ var mock_logger_1 = require("./mock.logger");
7
+ Object.defineProperty(exports, "MockLogger", { enumerable: true, get: function () { return mock_logger_1.MockLogger; } });
8
+ var console_logger_1 = require("./console.logger");
9
+ Object.defineProperty(exports, "ConsoleLogger", { enumerable: true, get: function () { return console_logger_1.ConsoleLogger; } });
10
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,mCAAkC;AAAzB,gGAAA,MAAM,OAAA;AACf,6CAA2C;AAAlC,yGAAA,UAAU,OAAA;AACnB,mDAAiD;AAAxC,+GAAA,aAAa,OAAA"}
@@ -0,0 +1,13 @@
1
+ /// <reference types="@hg-ts/types" />
2
+ export declare abstract class Logger {
3
+ abstract debug(...messages: unknown[]): void;
4
+ abstract info(...messages: unknown[]): void;
5
+ abstract notice(...messages: unknown[]): void;
6
+ abstract warning(...messages: unknown[]): void;
7
+ abstract error(...messages: unknown[]): void;
8
+ abstract critical(...messages: unknown[]): void;
9
+ abstract alert(...messages: unknown[]): void;
10
+ abstract emergency(...messages: unknown[]): void;
11
+ abstract setContext(context: Nullable<string>): void;
12
+ }
13
+ //# sourceMappingURL=logger.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../src/logger.ts"],"names":[],"mappings":";AAAA,8BAAsB,MAAM;aACX,KAAK,CAAC,GAAG,QAAQ,EAAE,OAAO,EAAE,GAAG,IAAI;aACnC,IAAI,CAAC,GAAG,QAAQ,EAAE,OAAO,EAAE,GAAG,IAAI;aAClC,MAAM,CAAC,GAAG,QAAQ,EAAE,OAAO,EAAE,GAAG,IAAI;aACpC,OAAO,CAAC,GAAG,QAAQ,EAAE,OAAO,EAAE,GAAG,IAAI;aACrC,KAAK,CAAC,GAAG,QAAQ,EAAE,OAAO,EAAE,GAAG,IAAI;aACnC,QAAQ,CAAC,GAAG,QAAQ,EAAE,OAAO,EAAE,GAAG,IAAI;aACtC,KAAK,CAAC,GAAG,QAAQ,EAAE,OAAO,EAAE,GAAG,IAAI;aACnC,SAAS,CAAC,GAAG,QAAQ,EAAE,OAAO,EAAE,GAAG,IAAI;aAEvC,UAAU,CAAC,OAAO,EAAE,QAAQ,CAAC,MAAM,CAAC,GAAG,IAAI;CAC3D"}
package/dist/logger.js ADDED
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Logger = void 0;
4
+ class Logger {
5
+ }
6
+ exports.Logger = Logger;
7
+ //# sourceMappingURL=logger.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"logger.js","sourceRoot":"","sources":["../src/logger.ts"],"names":[],"mappings":";;;AAAA,MAAsB,MAAM;CAW3B;AAXD,wBAWC"}
@@ -0,0 +1,13 @@
1
+ import { Logger } from './logger';
2
+ export declare class MockLogger extends Logger {
3
+ debug(): void;
4
+ info(): void;
5
+ notice(): void;
6
+ warning(): void;
7
+ error(): void;
8
+ critical(): void;
9
+ alert(): void;
10
+ emergency(): void;
11
+ setContext(): void;
12
+ }
13
+ //# sourceMappingURL=mock.logger.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mock.logger.d.ts","sourceRoot":"","sources":["../src/mock.logger.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAElC,qBAAa,UAAW,SAAQ,MAAM;IAC9B,KAAK,IAAI,IAAI;IACb,IAAI,IAAI,IAAI;IACZ,MAAM,IAAI,IAAI;IACd,OAAO,IAAI,IAAI;IACf,KAAK,IAAI,IAAI;IACb,QAAQ,IAAI,IAAI;IAChB,KAAK,IAAI,IAAI;IACb,SAAS,IAAI,IAAI;IAEjB,UAAU,IAAI,IAAI;CACzB"}
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MockLogger = void 0;
4
+ const logger_1 = require("./logger");
5
+ class MockLogger extends logger_1.Logger {
6
+ debug() { }
7
+ info() { }
8
+ notice() { }
9
+ warning() { }
10
+ error() { }
11
+ critical() { }
12
+ alert() { }
13
+ emergency() { }
14
+ setContext() { }
15
+ }
16
+ exports.MockLogger = MockLogger;
17
+ //# sourceMappingURL=mock.logger.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mock.logger.js","sourceRoot":"","sources":["../src/mock.logger.ts"],"names":[],"mappings":";;;AAAA,qCAAkC;AAElC,MAAa,UAAW,SAAQ,eAAM;IAC9B,KAAK,KAAU,CAAC;IAChB,IAAI,KAAU,CAAC;IACf,MAAM,KAAU,CAAC;IACjB,OAAO,KAAU,CAAC;IAClB,KAAK,KAAU,CAAC;IAChB,QAAQ,KAAU,CAAC;IACnB,KAAK,KAAU,CAAC;IAChB,SAAS,KAAU,CAAC;IAEpB,UAAU,KAAU,CAAC;CAC5B;AAXD,gCAWC"}
@@ -0,0 +1,20 @@
1
+ import { Logger } from './logger';
2
+ declare type LogLevel = keyof Omit<Logger, 'setContext'>;
3
+ export declare const logLevelPriority: readonly LogLevel[];
4
+ export declare class SyslogLogger extends Logger {
5
+ protected context: Nullable<string>;
6
+ private readonly logger;
7
+ constructor();
8
+ debug(...messages: unknown[]): void;
9
+ info(...messages: unknown[]): void;
10
+ notice(...messages: unknown[]): void;
11
+ warning(...messages: unknown[]): void;
12
+ error(...messages: unknown[]): void;
13
+ critical(...messages: unknown[]): void;
14
+ alert(...messages: unknown[]): void;
15
+ emergency(...messages: unknown[]): void;
16
+ setContext(context: Nullable<string>): void;
17
+ private log;
18
+ }
19
+ export {};
20
+ //# sourceMappingURL=syslog.logger.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"syslog.logger.d.ts","sourceRoot":"","sources":["../src/syslog.logger.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAElC,aAAK,QAAQ,GAAG,MAAM,IAAI,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC;AAoBjD,eAAO,MAAM,gBAAgB,EAAE,SAAS,QAAQ,EAStC,CAAC;AAkEX,qBAAa,YAAa,SAAQ,MAAM;IACvC,SAAS,CAAC,OAAO,EAAE,QAAQ,CAAC,MAAM,CAAC,CAAQ;IAC3C,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAiB;;IAmBjC,KAAK,CAAC,GAAG,QAAQ,EAAE,OAAO,EAAE,GAAG,IAAI;IAGnC,IAAI,CAAC,GAAG,QAAQ,EAAE,OAAO,EAAE,GAAG,IAAI;IAGlC,MAAM,CAAC,GAAG,QAAQ,EAAE,OAAO,EAAE,GAAG,IAAI;IAGpC,OAAO,CAAC,GAAG,QAAQ,EAAE,OAAO,EAAE,GAAG,IAAI;IAGrC,KAAK,CAAC,GAAG,QAAQ,EAAE,OAAO,EAAE,GAAG,IAAI;IAGnC,QAAQ,CAAC,GAAG,QAAQ,EAAE,OAAO,EAAE,GAAG,IAAI;IAGtC,KAAK,CAAC,GAAG,QAAQ,EAAE,OAAO,EAAE,GAAG,IAAI;IAGnC,SAAS,CAAC,GAAG,QAAQ,EAAE,OAAO,EAAE,GAAG,IAAI;IAIvC,UAAU,CAAC,OAAO,EAAE,QAAQ,CAAC,MAAM,CAAC,GAAG,IAAI;IAIlD,OAAO,CAAC,GAAG;CASX"}
@@ -0,0 +1,132 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SyslogLogger = exports.logLevelPriority = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const node_util_1 = require("node:util");
6
+ const winston_1 = tslib_1.__importDefault(require("winston"));
7
+ const triple_beam_1 = require("triple-beam");
8
+ const colors_1 = require("./colors");
9
+ const logger_1 = require("./logger");
10
+ const colorsMap = new Map()
11
+ .set('emergency', colors_1.COLOR.RED)
12
+ .set('alert', colors_1.COLOR.RED)
13
+ .set('critical', colors_1.COLOR.RED)
14
+ .set('error', colors_1.COLOR.RED)
15
+ .set('warning', colors_1.COLOR.YELLOW)
16
+ .set('notice', colors_1.COLOR.GREEN)
17
+ .set('info', colors_1.COLOR.CYAN_BRIGHT)
18
+ .set('debug', colors_1.COLOR.MAGENTA_BRIGHT);
19
+ const syslogToLoggerMap = new Map()
20
+ .set('emerg', 'emergency')
21
+ .set('crit', 'critical');
22
+ const loggerToSyslogMap = new Map()
23
+ .set('emergency', 'emerg')
24
+ .set('critical', 'crit');
25
+ exports.logLevelPriority = [
26
+ 'emergency',
27
+ 'alert',
28
+ 'critical',
29
+ 'error',
30
+ 'warning',
31
+ 'notice',
32
+ 'info',
33
+ 'debug',
34
+ ];
35
+ const levelFormat = winston_1.default.format(info => {
36
+ info[triple_beam_1.LEVEL] = info.level;
37
+ const mappedLevel = syslogToLoggerMap.get(info[triple_beam_1.LEVEL]) ?? info[triple_beam_1.LEVEL];
38
+ const levelColor = colorsMap.get(mappedLevel);
39
+ info.level = `<${(0, colors_1.colorize)(levelColor, mappedLevel)}>`;
40
+ return info;
41
+ });
42
+ const contextFormat = winston_1.default.format(info => {
43
+ if (info['context']) {
44
+ info['context'] = (0, colors_1.colorize)(colors_1.COLOR.ORANGE, info['context']);
45
+ info['context'] = `[${info['context']}]`;
46
+ }
47
+ return info;
48
+ });
49
+ const colorizeFormat = winston_1.default.format(info => {
50
+ const mappedLevel = syslogToLoggerMap.get(info[triple_beam_1.LEVEL]) ?? info[triple_beam_1.LEVEL];
51
+ const levelColor = colorsMap.get(mappedLevel);
52
+ info[triple_beam_1.MESSAGE] = (0, colors_1.colorize)(levelColor, info.message);
53
+ return info;
54
+ });
55
+ const processInfoFormat = winston_1.default.format(info => {
56
+ if (process.title.endsWith('node')) {
57
+ info['process'] = `[pid: ${process.pid}]`;
58
+ }
59
+ else {
60
+ info['process'] = `[${process.title}: ${process.pid}]`;
61
+ }
62
+ return info;
63
+ });
64
+ const timeFormat = winston_1.default.format(info => {
65
+ info['timestamp'] = new Date().toLocaleString('ru-RU');
66
+ return info;
67
+ });
68
+ const customFormat = winston_1.default.format(info => {
69
+ const { process, timestamp, context, level, [triple_beam_1.MESSAGE]: message } = info;
70
+ const metaInfoItems = [timestamp, context, level, process];
71
+ const metaInfo = metaInfoItems.join(' ');
72
+ info[triple_beam_1.MESSAGE] = `${metaInfo}: ${message}`;
73
+ return info;
74
+ });
75
+ const consoleTransport = new winston_1.default.transports.Console({
76
+ format: winston_1.default.format.combine(levelFormat(), contextFormat(), processInfoFormat(), colorizeFormat(), timeFormat(), customFormat()),
77
+ });
78
+ class SyslogLogger extends logger_1.Logger {
79
+ context = null;
80
+ logger;
81
+ constructor() {
82
+ super();
83
+ const logLevel = 'debug';
84
+ this.context = 'test';
85
+ this.logger = winston_1.default.createLogger({
86
+ level: logLevel,
87
+ levels: winston_1.default.config.syslog.levels,
88
+ format: customFormat(),
89
+ transports: [consoleTransport],
90
+ handleExceptions: true,
91
+ handleRejections: true,
92
+ exitOnError: false,
93
+ });
94
+ }
95
+ debug(...messages) {
96
+ this.log('debug', messages);
97
+ }
98
+ info(...messages) {
99
+ this.log('info', messages);
100
+ }
101
+ notice(...messages) {
102
+ this.log('notice', messages);
103
+ }
104
+ warning(...messages) {
105
+ this.log('warning', messages);
106
+ }
107
+ error(...messages) {
108
+ this.log('error', messages);
109
+ }
110
+ critical(...messages) {
111
+ this.log('critical', messages);
112
+ }
113
+ alert(...messages) {
114
+ this.log('alert', messages);
115
+ }
116
+ emergency(...messages) {
117
+ this.log('emergency', messages);
118
+ }
119
+ setContext(context) {
120
+ this.context = context;
121
+ }
122
+ log(level, messages) {
123
+ const mappedLevel = loggerToSyslogMap.get(level) ?? level;
124
+ this.logger.log({
125
+ level: mappedLevel,
126
+ message: (0, node_util_1.format)(...messages),
127
+ context: this.context,
128
+ });
129
+ }
130
+ }
131
+ exports.SyslogLogger = SyslogLogger;
132
+ //# sourceMappingURL=syslog.logger.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"syslog.logger.js","sourceRoot":"","sources":["../src/syslog.logger.ts"],"names":[],"mappings":";;;;AAAA,yCAAmC;AACnC,8DAA8B;AAC9B,6CAA6C;AAG7C,qCAGkB;AAClB,qCAAkC;AAIlC,MAAM,SAAS,GAAG,IAAI,GAAG,EAAmB;KAC1C,GAAG,CAAC,WAAW,EAAE,cAAK,CAAC,GAAG,CAAC;KAC3B,GAAG,CAAC,OAAO,EAAE,cAAK,CAAC,GAAG,CAAC;KACvB,GAAG,CAAC,UAAU,EAAE,cAAK,CAAC,GAAG,CAAC;KAC1B,GAAG,CAAC,OAAO,EAAE,cAAK,CAAC,GAAG,CAAC;KACvB,GAAG,CAAC,SAAS,EAAE,cAAK,CAAC,MAAM,CAAC;KAC5B,GAAG,CAAC,QAAQ,EAAE,cAAK,CAAC,KAAK,CAAC;KAC1B,GAAG,CAAC,MAAM,EAAE,cAAK,CAAC,WAAW,CAAC;KAC9B,GAAG,CAAC,OAAO,EAAE,cAAK,CAAC,cAAc,CAAC,CAAC;AAErC,MAAM,iBAAiB,GAAG,IAAI,GAAG,EAAoB;KACnD,GAAG,CAAC,OAAO,EAAE,WAAW,CAAC;KACzB,GAAG,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC;AAE1B,MAAM,iBAAiB,GAAG,IAAI,GAAG,EAAoB;KACnD,GAAG,CAAC,WAAW,EAAE,OAAO,CAAC;KACzB,GAAG,CAAC,UAAU,EAAE,MAAM,CAAC,CAAC;AAEb,QAAA,gBAAgB,GAAwB;IACpD,WAAW;IAC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AAU,EAAE,QAAQ,CAAC,CAAC;IAChC,CAAC;IACM,KAAK,CAAC,GAAG,QAAmB;QAClC,IAAI,CAAC,GAAG,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC;IAC7B,CAAC;IACM,SAAS,CAAC,GAAG,QAAmB;QACtC,IAAI,CAAC,GAAG,CAAC,WAAW,EAAE,QAAQ,CAAC,CAAC;IACjC,CAAC;IAEM,UAAU,CAAC,OAAyB;QAC1C,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;IACxB,CAAC;IAEO,GAAG,CAAC,KAAe,EAAE,QAAmB;QAC/C,MAAM,WAAW,GAAG,iBAAiB,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,KAAK,CAAC;QAE1D,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC;YACf,KAAK,EAAE,WAAW;YAClB,OAAO,EAAE,IAAA,kBAAM,EAAC,GAAG,QAAQ,CAAC;YAC5B,OAAO,EAAE,IAAI,CAAC,OAAO;SACrB,CAAC,CAAC;IACJ,CAAC;CACD;AA3DD,oCA2DC"}
@@ -0,0 +1,10 @@
1
+ export declare enum COLOR {
2
+ ORANGE = "38;5;3",
3
+ GREEN = "32",
4
+ YELLOW = "33",
5
+ RED = "31",
6
+ MAGENTA_BRIGHT = "95",
7
+ CYAN_BRIGHT = "96"
8
+ }
9
+ export declare function colorize(color: COLOR, text: string): string;
10
+ //# sourceMappingURL=colors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"colors.d.ts","sourceRoot":"","sources":["../src/colors.ts"],"names":[],"mappings":"AAEA,oBAAY,KAAK;IAChB,MAAM,WAAW;IACjB,KAAK,OAAO;IACZ,MAAM,OAAO;IACb,GAAG,OAAO;IACV,cAAc,OAAO;IACrB,WAAW,OAAO;CAClB;AAED,wBAAgB,QAAQ,CAAC,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAM3D"}
@@ -0,0 +1,17 @@
1
+ const isColorAllowed = !process.env['NO_COLOR'];
2
+ export var COLOR;
3
+ (function (COLOR) {
4
+ COLOR["ORANGE"] = "38;5;3";
5
+ COLOR["GREEN"] = "32";
6
+ COLOR["YELLOW"] = "33";
7
+ COLOR["RED"] = "31";
8
+ COLOR["MAGENTA_BRIGHT"] = "95";
9
+ COLOR["CYAN_BRIGHT"] = "96";
10
+ })(COLOR || (COLOR = {}));
11
+ export function colorize(color, text) {
12
+ if (!isColorAllowed) {
13
+ return text;
14
+ }
15
+ return `\x1B[${color}m${text}\x1B[39m`;
16
+ }
17
+ //# sourceMappingURL=colors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"colors.js","sourceRoot":"","sources":["../src/colors.ts"],"names":[],"mappings":"AAAA,MAAM,cAAc,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;AAEhD,MAAM,CAAN,IAAY,KAOX;AAPD,WAAY,KAAK;IAChB,0BAAiB,CAAA;IACjB,qBAAY,CAAA;IACZ,sBAAa,CAAA;IACb,mBAAU,CAAA;IACV,8BAAqB,CAAA;IACrB,2BAAkB,CAAA;AACnB,CAAC,EAPW,KAAK,KAAL,KAAK,QAOhB;AAED,MAAM,UAAU,QAAQ,CAAC,KAAY,EAAE,IAAY;IAClD,IAAI,CAAC,cAAc,EAAE;QACpB,OAAO,IAAI,CAAC;KACZ;IAED,OAAO,QAAQ,KAAK,IAAI,IAAI,UAAU,CAAC;AACxC,CAAC"}
@@ -0,0 +1,21 @@
1
+ /// <reference types="@hg-ts/types" />
2
+ import { Logger } from './logger';
3
+ type LogLevel = keyof Omit<Logger, 'setContext'>;
4
+ export declare const logLevelPriority: readonly LogLevel[];
5
+ export declare class ConsoleLogger extends Logger {
6
+ protected context: Nullable<string>;
7
+ private readonly logger;
8
+ constructor();
9
+ debug(...messages: unknown[]): void;
10
+ info(...messages: unknown[]): void;
11
+ notice(...messages: unknown[]): void;
12
+ warning(...messages: unknown[]): void;
13
+ error(...messages: unknown[]): void;
14
+ critical(...messages: unknown[]): void;
15
+ alert(...messages: unknown[]): void;
16
+ emergency(...messages: unknown[]): void;
17
+ setContext(context: Nullable<string>): void;
18
+ private log;
19
+ }
20
+ export {};
21
+ //# sourceMappingURL=console.logger.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"console.logger.d.ts","sourceRoot":"","sources":["../src/console.logger.ts"],"names":[],"mappings":";AASA,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAElC,KAAK,QAAQ,GAAG,MAAM,IAAI,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC;AAoBjD,eAAO,MAAM,gBAAgB,EAAE,SAAS,QAAQ,EAStC,CAAC;AAkEX,qBAAa,aAAc,SAAQ,MAAM;IACxC,SAAS,CAAC,OAAO,EAAE,QAAQ,CAAC,MAAM,CAAC,CAAQ;IAC3C,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAiB;;IAmBjC,KAAK,CAAC,GAAG,QAAQ,EAAE,OAAO,EAAE,GAAG,IAAI;IAGnC,IAAI,CAAC,GAAG,QAAQ,EAAE,OAAO,EAAE,GAAG,IAAI;IAGlC,MAAM,CAAC,GAAG,QAAQ,EAAE,OAAO,EAAE,GAAG,IAAI;IAGpC,OAAO,CAAC,GAAG,QAAQ,EAAE,OAAO,EAAE,GAAG,IAAI;IAGrC,KAAK,CAAC,GAAG,QAAQ,EAAE,OAAO,EAAE,GAAG,IAAI;IAGnC,QAAQ,CAAC,GAAG,QAAQ,EAAE,OAAO,EAAE,GAAG,IAAI;IAGtC,KAAK,CAAC,GAAG,QAAQ,EAAE,OAAO,EAAE,GAAG,IAAI;IAGnC,SAAS,CAAC,GAAG,QAAQ,EAAE,OAAO,EAAE,GAAG,IAAI;IAIvC,UAAU,CAAC,OAAO,EAAE,QAAQ,CAAC,MAAM,CAAC,GAAG,IAAI;IAIlD,OAAO,CAAC,GAAG;CASX"}
@@ -0,0 +1,127 @@
1
+ import { format } from 'node:util';
2
+ import winston from 'winston';
3
+ import { MESSAGE, LEVEL } from 'triple-beam';
4
+ import { COLOR, colorize, } from './colors';
5
+ import { Logger } from './logger';
6
+ const colorsMap = new Map()
7
+ .set('emergency', COLOR.RED)
8
+ .set('alert', COLOR.RED)
9
+ .set('critical', COLOR.RED)
10
+ .set('error', COLOR.RED)
11
+ .set('warning', COLOR.YELLOW)
12
+ .set('notice', COLOR.GREEN)
13
+ .set('info', COLOR.CYAN_BRIGHT)
14
+ .set('debug', COLOR.MAGENTA_BRIGHT);
15
+ const syslogToLoggerMap = new Map()
16
+ .set('emerg', 'emergency')
17
+ .set('crit', 'critical');
18
+ const loggerToSyslogMap = new Map()
19
+ .set('emergency', 'emerg')
20
+ .set('critical', 'crit');
21
+ export const logLevelPriority = [
22
+ 'emergency',
23
+ 'alert',
24
+ 'critical',
25
+ 'error',
26
+ 'warning',
27
+ 'notice',
28
+ 'info',
29
+ 'debug',
30
+ ];
31
+ const levelFormat = winston.format(info => {
32
+ info[LEVEL] = info.level;
33
+ const mappedLevel = syslogToLoggerMap.get(info[LEVEL]) ?? info[LEVEL];
34
+ const levelColor = colorsMap.get(mappedLevel);
35
+ info.level = `<${colorize(levelColor, mappedLevel)}>`;
36
+ return info;
37
+ });
38
+ const contextFormat = winston.format(info => {
39
+ if (info['context']) {
40
+ info['context'] = colorize(COLOR.ORANGE, info['context']);
41
+ info['context'] = `[${info['context']}]`;
42
+ }
43
+ return info;
44
+ });
45
+ const colorizeFormat = winston.format(info => {
46
+ const mappedLevel = syslogToLoggerMap.get(info[LEVEL]) ?? info[LEVEL];
47
+ const levelColor = colorsMap.get(mappedLevel);
48
+ info[MESSAGE] = colorize(levelColor, info.message);
49
+ return info;
50
+ });
51
+ const processInfoFormat = winston.format(info => {
52
+ if (process.title.endsWith('node')) {
53
+ info['process'] = `[pid: ${process.pid}]`;
54
+ }
55
+ else {
56
+ info['process'] = `[${process.title}: ${process.pid}]`;
57
+ }
58
+ return info;
59
+ });
60
+ const timeFormat = winston.format(info => {
61
+ info['timestamp'] = new Date().toLocaleString('ru-RU');
62
+ return info;
63
+ });
64
+ const customFormat = winston.format(info => {
65
+ const { process, timestamp, context, level, [MESSAGE]: message } = info;
66
+ const metaInfoItems = [timestamp, context, level, process];
67
+ const metaInfo = metaInfoItems.join(' ');
68
+ info[MESSAGE] = `${metaInfo}: ${message}`;
69
+ return info;
70
+ });
71
+ const consoleTransport = new winston.transports.Console({
72
+ format: winston.format.combine(levelFormat(), contextFormat(), processInfoFormat(), colorizeFormat(), timeFormat(), customFormat()),
73
+ });
74
+ export class ConsoleLogger extends Logger {
75
+ context = null;
76
+ logger;
77
+ constructor() {
78
+ super();
79
+ const logLevel = 'debug';
80
+ this.context = 'test';
81
+ this.logger = winston.createLogger({
82
+ level: logLevel,
83
+ levels: winston.config.syslog.levels,
84
+ format: customFormat(),
85
+ transports: [consoleTransport],
86
+ handleExceptions: true,
87
+ handleRejections: true,
88
+ exitOnError: false,
89
+ });
90
+ }
91
+ debug(...messages) {
92
+ this.log('debug', messages);
93
+ }
94
+ info(...messages) {
95
+ this.log('info', messages);
96
+ }
97
+ notice(...messages) {
98
+ this.log('notice', messages);
99
+ }
100
+ warning(...messages) {
101
+ this.log('warning', messages);
102
+ }
103
+ error(...messages) {
104
+ this.log('error', messages);
105
+ }
106
+ critical(...messages) {
107
+ this.log('critical', messages);
108
+ }
109
+ alert(...messages) {
110
+ this.log('alert', messages);
111
+ }
112
+ emergency(...messages) {
113
+ this.log('emergency', messages);
114
+ }
115
+ setContext(context) {
116
+ this.context = context;
117
+ }
118
+ log(level, messages) {
119
+ const mappedLevel = loggerToSyslogMap.get(level) ?? level;
120
+ this.logger.log({
121
+ level: mappedLevel,
122
+ message: format(...messages),
123
+ context: this.context,
124
+ });
125
+ }
126
+ }
127
+ //# sourceMappingURL=console.logger.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"console.logger.js","sourceRoot":"","sources":["../src/console.logger.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,WAAW,CA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jC,CAAC;IAEM,UAAU,CAAC,OAAyB;QAC1C,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;IACxB,CAAC;IAEO,GAAG,CAAC,KAAe,EAAE,QAAmB;QAC/C,MAAM,WAAW,GAAG,iBAAiB,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,KAAK,CAAC;QAE1D,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC;YACf,KAAK,EAAE,WAAW;YAClB,OAAO,EAAE,MAAM,CAAC,GAAG,QAAQ,CAAC;YAC5B,OAAO,EAAE,IAAI,CAAC,OAAO;SACrB,CAAC,CAAC;IACJ,CAAC;CACD"}
@@ -0,0 +1,4 @@
1
+ export { Logger } from './logger';
2
+ export { MockLogger } from './mock.logger';
3
+ export { ConsoleLogger } from './console.logger';
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAClC,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC3C,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC"}
@@ -0,0 +1,4 @@
1
+ export { Logger } from './logger';
2
+ export { MockLogger } from './mock.logger';
3
+ export { ConsoleLogger } from './console.logger';
4
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAClC,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC3C,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC"}
@@ -0,0 +1,13 @@
1
+ /// <reference types="@hg-ts/types" />
2
+ export declare abstract class Logger {
3
+ abstract debug(...messages: unknown[]): void;
4
+ abstract info(...messages: unknown[]): void;
5
+ abstract notice(...messages: unknown[]): void;
6
+ abstract warning(...messages: unknown[]): void;
7
+ abstract error(...messages: unknown[]): void;
8
+ abstract critical(...messages: unknown[]): void;
9
+ abstract alert(...messages: unknown[]): void;
10
+ abstract emergency(...messages: unknown[]): void;
11
+ abstract setContext(context: Nullable<string>): void;
12
+ }
13
+ //# sourceMappingURL=logger.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../src/logger.ts"],"names":[],"mappings":";AAAA,8BAAsB,MAAM;aACX,KAAK,CAAC,GAAG,QAAQ,EAAE,OAAO,EAAE,GAAG,IAAI;aACnC,IAAI,CAAC,GAAG,QAAQ,EAAE,OAAO,EAAE,GAAG,IAAI;aAClC,MAAM,CAAC,GAAG,QAAQ,EAAE,OAAO,EAAE,GAAG,IAAI;aACpC,OAAO,CAAC,GAAG,QAAQ,EAAE,OAAO,EAAE,GAAG,IAAI;aACrC,KAAK,CAAC,GAAG,QAAQ,EAAE,OAAO,EAAE,GAAG,IAAI;aACnC,QAAQ,CAAC,GAAG,QAAQ,EAAE,OAAO,EAAE,GAAG,IAAI;aACtC,KAAK,CAAC,GAAG,QAAQ,EAAE,OAAO,EAAE,GAAG,IAAI;aACnC,SAAS,CAAC,GAAG,QAAQ,EAAE,OAAO,EAAE,GAAG,IAAI;aAEvC,UAAU,CAAC,OAAO,EAAE,QAAQ,CAAC,MAAM,CAAC,GAAG,IAAI;CAC3D"}
@@ -0,0 +1,3 @@
1
+ export class Logger {
2
+ }
3
+ //# sourceMappingURL=logger.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"logger.js","sourceRoot":"","sources":["../src/logger.ts"],"names":[],"mappings":"AAAA,MAAM,OAAgB,MAAM;CAW3B"}
@@ -0,0 +1,13 @@
1
+ import { Logger } from './logger';
2
+ export declare class MockLogger extends Logger {
3
+ debug(): void;
4
+ info(): void;
5
+ notice(): void;
6
+ warning(): void;
7
+ error(): void;
8
+ critical(): void;
9
+ alert(): void;
10
+ emergency(): void;
11
+ setContext(): void;
12
+ }
13
+ //# sourceMappingURL=mock.logger.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mock.logger.d.ts","sourceRoot":"","sources":["../src/mock.logger.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAElC,qBAAa,UAAW,SAAQ,MAAM;IAC9B,KAAK,IAAI,IAAI;IACb,IAAI,IAAI,IAAI;IACZ,MAAM,IAAI,IAAI;IACd,OAAO,IAAI,IAAI;IACf,KAAK,IAAI,IAAI;IACb,QAAQ,IAAI,IAAI;IAChB,KAAK,IAAI,IAAI;IACb,SAAS,IAAI,IAAI;IAEjB,UAAU,IAAI,IAAI;CACzB"}
@@ -0,0 +1,13 @@
1
+ import { Logger } from './logger';
2
+ export class MockLogger extends Logger {
3
+ debug() { }
4
+ info() { }
5
+ notice() { }
6
+ warning() { }
7
+ error() { }
8
+ critical() { }
9
+ alert() { }
10
+ emergency() { }
11
+ setContext() { }
12
+ }
13
+ //# sourceMappingURL=mock.logger.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mock.logger.js","sourceRoot":"","sources":["../src/mock.logger.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAElC,MAAM,OAAO,UAAW,SAAQ,MAAM;IAC9B,KAAK,KAAU,CAAC;IAChB,IAAI,KAAU,CAAC;IACf,MAAM,KAAU,CAAC;IACjB,OAAO,KAAU,CAAC;IAClB,KAAK,KAAU,CAAC;IAChB,QAAQ,KAAU,CAAC;IACnB,KAAK,KAAU,CAAC;IAChB,SAAS,KAAU,CAAC;IAEpB,UAAU,KAAU,CAAC;CAC5B"}
package/package.json ADDED
@@ -0,0 +1,39 @@
1
+ {
2
+ "name": "@hg-ts/logger",
3
+ "version": "0.1.0",
4
+ "main": "dist/index.js",
5
+ "module": "dist-esm/index.js",
6
+ "repository": "git@gitlab.com:hyper-graph/framework.git",
7
+ "scripts": {
8
+ "prepack": "yarn build && yarn lint",
9
+ "build": "hg build",
10
+ "build:dev": "hg build:dev",
11
+ "lint": "hg lint",
12
+ "lint:fix": "hg lint:fix"
13
+ },
14
+ "devDependencies": {
15
+ "@hg-ts-config/eslint-config": "0.1.0",
16
+ "@hg-ts-config/typescript": "0.1.0",
17
+ "@hg-ts/cli": "0.1.0",
18
+ "@hg-ts/types": "0.1.0",
19
+ "@types/node": "20.8.7",
20
+ "@types/triple-beam": "1.3.4",
21
+ "@typescript-eslint/eslint-plugin": "6.8.0",
22
+ "@typescript-eslint/parser": "6.8.0",
23
+ "eslint": "8.52.0",
24
+ "reflect-metadata": "0.1.13",
25
+ "tsc-watch": "6.0.4",
26
+ "tslib": "2.6.2",
27
+ "typescript": "5.2.2"
28
+ },
29
+ "peerDependencies": {
30
+ "@hg-ts/types": "*",
31
+ "reflect-metadata": "*",
32
+ "tslib": "*"
33
+ },
34
+ "dependencies": {
35
+ "triple-beam": "1.4.1",
36
+ "winston": "3.11.0",
37
+ "winston-syslog": "2.7.0"
38
+ }
39
+ }
package/src/colors.ts ADDED
@@ -0,0 +1,18 @@
1
+ const isColorAllowed = !process.env['NO_COLOR'];
2
+
3
+ export enum COLOR {
4
+ ORANGE = '38;5;3',
5
+ GREEN = '32',
6
+ YELLOW = '33',
7
+ RED = '31',
8
+ MAGENTA_BRIGHT = '95',
9
+ CYAN_BRIGHT = '96',
10
+ }
11
+
12
+ export function colorize(color: COLOR, text: string): string {
13
+ if (!isColorAllowed) {
14
+ return text;
15
+ }
16
+
17
+ return `\x1B[${color}m${text}\x1B[39m`;
18
+ }
@@ -0,0 +1,166 @@
1
+ import { format } from 'node:util';
2
+ import winston from 'winston';
3
+ import { MESSAGE, LEVEL } from 'triple-beam';
4
+
5
+
6
+ import {
7
+ COLOR,
8
+ colorize,
9
+ } from './colors';
10
+ import { Logger } from './logger';
11
+
12
+ type LogLevel = keyof Omit<Logger, 'setContext'>;
13
+
14
+ const colorsMap = new Map<LogLevel, COLOR>()
15
+ .set('emergency', COLOR.RED)
16
+ .set('alert', COLOR.RED)
17
+ .set('critical', COLOR.RED)
18
+ .set('error', COLOR.RED)
19
+ .set('warning', COLOR.YELLOW)
20
+ .set('notice', COLOR.GREEN)
21
+ .set('info', COLOR.CYAN_BRIGHT)
22
+ .set('debug', COLOR.MAGENTA_BRIGHT);
23
+
24
+ const syslogToLoggerMap = new Map<string, LogLevel>()
25
+ .set('emerg', 'emergency')
26
+ .set('crit', 'critical');
27
+
28
+ const loggerToSyslogMap = new Map<LogLevel, string>()
29
+ .set('emergency', 'emerg')
30
+ .set('critical', 'crit');
31
+
32
+ export const logLevelPriority: readonly LogLevel[] = [
33
+ 'emergency',
34
+ 'alert',
35
+ 'critical',
36
+ 'error',
37
+ 'warning',
38
+ 'notice',
39
+ 'info',
40
+ 'debug',
41
+ ] as const;
42
+
43
+ const levelFormat = winston.format(info => {
44
+ info[LEVEL] = info.level;
45
+ const mappedLevel = syslogToLoggerMap.get(info[LEVEL]) ?? info[LEVEL];
46
+ const levelColor = colorsMap.get(mappedLevel as LogLevel)!;
47
+
48
+ info.level = `<${colorize(levelColor, mappedLevel)}>`;
49
+
50
+ return info;
51
+ });
52
+
53
+ const contextFormat = winston.format(info => {
54
+ if (info['context']) {
55
+ info['context'] = colorize(COLOR.ORANGE, info['context']);
56
+ info['context'] = `[${info['context'] as string}]`;
57
+ }
58
+
59
+ return info;
60
+ });
61
+
62
+ const colorizeFormat = winston.format(info => {
63
+ const mappedLevel = syslogToLoggerMap.get(info[LEVEL]!) ?? info[LEVEL];
64
+ const levelColor = colorsMap.get(mappedLevel as LogLevel)!;
65
+
66
+ info[MESSAGE] = colorize(levelColor, info.message);
67
+
68
+ return info;
69
+ });
70
+
71
+ const processInfoFormat = winston.format(info => {
72
+ if (process.title.endsWith('node')) {
73
+ info['process'] = `[pid: ${process.pid}]`;
74
+ } else {
75
+ info['process'] = `[${process.title}: ${process.pid}]`;
76
+ }
77
+ return info;
78
+ });
79
+
80
+ const timeFormat = winston.format(info => {
81
+ info['timestamp'] = new Date().toLocaleString('ru-RU');
82
+ return info;
83
+ });
84
+
85
+ const customFormat = winston.format(info => {
86
+ const { process, timestamp, context, level, [MESSAGE]: message } = info;
87
+ const metaInfoItems: string[] = [timestamp, context, level, process];
88
+
89
+ const metaInfo = metaInfoItems.join(' ');
90
+
91
+ info[MESSAGE] = `${metaInfo}: ${message as string}`;
92
+
93
+ return info;
94
+ });
95
+
96
+ const consoleTransport = new winston.transports.Console({
97
+ format: winston.format.combine(
98
+ levelFormat(),
99
+ contextFormat(),
100
+ processInfoFormat(),
101
+ colorizeFormat(),
102
+ timeFormat(),
103
+ customFormat(),
104
+ ),
105
+ });
106
+
107
+ export class ConsoleLogger extends Logger {
108
+ protected context: Nullable<string> = null;
109
+ private readonly logger: winston.Logger;
110
+
111
+ public constructor() {
112
+ super();
113
+
114
+ const logLevel: LogLevel = 'debug';
115
+ this.context = 'test';
116
+
117
+ this.logger = winston.createLogger({
118
+ level: logLevel,
119
+ levels: winston.config.syslog.levels,
120
+ format: customFormat(),
121
+ transports: [consoleTransport],
122
+ handleExceptions: true,
123
+ handleRejections: true,
124
+ exitOnError: false,
125
+ });
126
+ }
127
+
128
+ public debug(...messages: unknown[]): void {
129
+ this.log('debug', messages);
130
+ }
131
+ public info(...messages: unknown[]): void {
132
+ this.log('info', messages);
133
+ }
134
+ public notice(...messages: unknown[]): void {
135
+ this.log('notice', messages);
136
+ }
137
+ public warning(...messages: unknown[]): void {
138
+ this.log('warning', messages);
139
+ }
140
+ public error(...messages: unknown[]): void {
141
+ this.log('error', messages);
142
+ }
143
+ public critical(...messages: unknown[]): void {
144
+ this.log('critical', messages);
145
+ }
146
+ public alert(...messages: unknown[]): void {
147
+ this.log('alert', messages);
148
+ }
149
+ public emergency(...messages: unknown[]): void {
150
+ this.log('emergency', messages);
151
+ }
152
+
153
+ public setContext(context: Nullable<string>): void {
154
+ this.context = context;
155
+ }
156
+
157
+ private log(level: LogLevel, messages: unknown[]): void {
158
+ const mappedLevel = loggerToSyslogMap.get(level) ?? level;
159
+
160
+ this.logger.log({
161
+ level: mappedLevel,
162
+ message: format(...messages),
163
+ context: this.context,
164
+ });
165
+ }
166
+ }
package/src/index.ts ADDED
@@ -0,0 +1,3 @@
1
+ export { Logger } from './logger';
2
+ export { MockLogger } from './mock.logger';
3
+ export { ConsoleLogger } from './console.logger';
package/src/logger.ts ADDED
@@ -0,0 +1,12 @@
1
+ export abstract class Logger {
2
+ public abstract debug(...messages: unknown[]): void;
3
+ public abstract info(...messages: unknown[]): void;
4
+ public abstract notice(...messages: unknown[]): void;
5
+ public abstract warning(...messages: unknown[]): void;
6
+ public abstract error(...messages: unknown[]): void;
7
+ public abstract critical(...messages: unknown[]): void;
8
+ public abstract alert(...messages: unknown[]): void;
9
+ public abstract emergency(...messages: unknown[]): void;
10
+
11
+ public abstract setContext(context: Nullable<string>): void;
12
+ }
@@ -0,0 +1,14 @@
1
+ import { Logger } from './logger';
2
+
3
+ export class MockLogger extends Logger {
4
+ public debug(): void {}
5
+ public info(): void {}
6
+ public notice(): void {}
7
+ public warning(): void {}
8
+ public error(): void {}
9
+ public critical(): void {}
10
+ public alert(): void {}
11
+ public emergency(): void {}
12
+
13
+ public setContext(): void {}
14
+ }
@@ -0,0 +1,9 @@
1
+ {
2
+ "extends": "@hg-ts-config/typescript/esm",
3
+ "compilerOptions": {
4
+ "baseUrl": "src",
5
+ "rootDir": "src",
6
+ "outDir": "dist-esm"
7
+ },
8
+ "exclude": ["dist", "dist-esm"]
9
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,9 @@
1
+ {
2
+ "extends": "@hg-ts-config/typescript/commonjs",
3
+ "compilerOptions": {
4
+ "baseUrl": "src",
5
+ "rootDir": "src",
6
+ "outDir": "dist"
7
+ },
8
+ "exclude": ["dist", "dist-esm"]
9
+ }