@celljs/logger 3.9.0 → 4.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.
- package/README.md +4 -0
- package/esm/node/winston-logger.d.ts +6 -3
- package/esm/node/winston-logger.js +19 -7
- package/esm/node/winston-logger.js.map +1 -1
- package/lib/node/winston-logger.d.ts +6 -3
- package/lib/node/winston-logger.d.ts.map +1 -1
- package/lib/node/winston-logger.js +19 -7
- package/lib/node/winston-logger.js.map +1 -1
- package/lib/node/winston-logger.spec.d.ts +2 -0
- package/lib/node/winston-logger.spec.d.ts.map +1 -0
- package/lib/node/winston-logger.spec.js +33 -0
- package/lib/node/winston-logger.spec.js.map +1 -0
- package/package.json +9 -7
- package/src/node/winston-logger.spec.ts +33 -0
- package/src/node/winston-logger.ts +20 -8
package/README.md
CHANGED
|
@@ -1 +1,5 @@
|
|
|
1
1
|
# Cell - Logger Component with winston
|
|
2
|
+
|
|
3
|
+
Replaces the default `Logger` of `@celljs/core` with one backed by [winston](https://github.com/winstonjs/winston).
|
|
4
|
+
|
|
5
|
+
The level comes from `cell.logger.level` (default `info`); `cell.logger.winstonConfig` is merged into the winston options. The per-request access log of `@celljs/web` is written at `debug`, so it is not printed by default; set `cell.logger.level: debug` (or `CELL_BACKEND__CELL__LOGGER__LEVEL=debug`) to see it.
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AbstractLogger } from '@celljs/core';
|
|
1
|
+
import { AbstractLogger, LogLevel } from '@celljs/core';
|
|
2
2
|
import { WinstonConfig, RawWinstonLogger } from './winston-logger-protocol.js';
|
|
3
3
|
export declare class WinstonLogger extends AbstractLogger {
|
|
4
4
|
protected readonly winstonConfig?: WinstonConfig;
|
|
@@ -10,6 +10,9 @@ export declare class WinstonLogger extends AbstractLogger {
|
|
|
10
10
|
warn(message: string, context?: string): void;
|
|
11
11
|
info(message: string, context?: string): void;
|
|
12
12
|
debug(message: string, context?: string): void;
|
|
13
|
-
|
|
14
|
-
|
|
13
|
+
/** winston decides, with its own level (winstonConfig may set one). */
|
|
14
|
+
isEnabled(level: LogLevel): boolean;
|
|
15
|
+
/** winston writes the time and the level itself. */
|
|
16
|
+
protected resolvePrefix(): string;
|
|
17
|
+
protected log(message: any, context?: string, logFn?: (...args: any[]) => void, level?: LogLevel): void;
|
|
15
18
|
}
|
|
@@ -31,22 +31,34 @@ let WinstonLogger = class WinstonLogger extends AbstractLogger {
|
|
|
31
31
|
return this.logger;
|
|
32
32
|
}
|
|
33
33
|
error(message, context) {
|
|
34
|
-
this.log(message, context, this.logger.error.bind(this.logger));
|
|
34
|
+
this.log(message, context, this.logger.error.bind(this.logger), 'error');
|
|
35
35
|
}
|
|
36
36
|
warn(message, context) {
|
|
37
|
-
this.
|
|
37
|
+
if (this.isEnabled('warn')) {
|
|
38
|
+
this.log(message, context, this.logger.warn.bind(this.logger), 'warn');
|
|
39
|
+
}
|
|
38
40
|
}
|
|
39
41
|
info(message, context) {
|
|
40
|
-
this.
|
|
42
|
+
if (this.isEnabled('info')) {
|
|
43
|
+
this.log(message, context, this.logger.info.bind(this.logger), 'info');
|
|
44
|
+
}
|
|
41
45
|
}
|
|
42
46
|
debug(message, context) {
|
|
43
|
-
this.
|
|
47
|
+
if (this.isEnabled('debug')) {
|
|
48
|
+
this.log(message, context, this.logger.debug.bind(this.logger), 'debug');
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
/** winston decides, with its own level (winstonConfig may set one). */
|
|
52
|
+
isEnabled(level) {
|
|
53
|
+
var _a;
|
|
54
|
+
return ((_a = this.logger) === null || _a === void 0 ? void 0 : _a.isLevelEnabled) ? this.logger.isLevelEnabled(level) : super.isEnabled(level);
|
|
44
55
|
}
|
|
45
|
-
|
|
56
|
+
/** winston writes the time and the level itself. */
|
|
57
|
+
resolvePrefix() {
|
|
46
58
|
return '';
|
|
47
59
|
}
|
|
48
|
-
log(message, context, logFn) {
|
|
49
|
-
super.log(message, context, logFn !== null && logFn !== void 0 ? logFn : this.logger.info.bind(this.logger));
|
|
60
|
+
log(message, context, logFn, level = 'info') {
|
|
61
|
+
super.log(message, context, logFn !== null && logFn !== void 0 ? logFn : this.logger.info.bind(this.logger), level);
|
|
50
62
|
}
|
|
51
63
|
};
|
|
52
64
|
__decorate([
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"winston-logger.js","sourceRoot":"","sources":["../../src/node/winston-logger.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,MAAM,EAAE,aAAa,EAAE,KAAK,EAAE,SAAS,EAAE,SAAS,EAAE,QAAQ,EAAE,cAAc,EAAE,aAAa,EAAE,KAAK,
|
|
1
|
+
{"version":3,"file":"winston-logger.js","sourceRoot":"","sources":["../../src/node/winston-logger.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,MAAM,EAAE,aAAa,EAAE,KAAK,EAAE,SAAS,EAAE,SAAS,EAAE,QAAQ,EAAE,cAAc,EAAE,aAAa,EAAE,KAAK,EAAY,MAAM,cAAc,CAAC;AAC5I,OAAO,EAAE,aAAa,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAC;AAC5E,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AAE3D,IAAI,OAAyB,CAAC;AAGvB,IAAM,aAAa,GAAnB,MAAM,aAAc,SAAQ,cAAc;IAcnC,IAAI;QACV,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC;YACf,IAAI,OAAO,EAAE,CAAC;gBACV,IAAI,CAAC,MAAM,GAAG,OAAO,CAAC;gBACtB,OAAO;YACX,CAAC;YACD,OAAO,GAAG,YAAY,CAAC;gBACnB,KAAK,EAAE,IAAI,CAAC,KAAK;gBACjB,MAAM,EAAE,MAAM,CAAC,OAAO,CAClB,MAAM,CAAC,SAAS,EAAE,EAClB,MAAM,CAAC,MAAM,CAAC,CAAC,EAAE,KAAK,EAAE,OAAO,EAAE,SAAS,EAAE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C,IAAI,CAAC,MAAM,CAAC,EAAE,OAAO,CAAC,CAAC;QAC7E,CAAC;IACL,CAAC;IAED,uEAAuE;IAC9D,SAAS,CAAC,KAAe;;QAC9B,OAAO,CAAA,MAAA,IAAI,CAAC,MAAM,0CAAE,cAAc,EAAC,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,cAAc,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;IACpG,CAAC;IAED,oDAAoD;IACjC,aAAa;QAC5B,OAAO,EAAE,CAAC;IACd,CAAC;IAEkB,GAAG,CAAC,OAAY,EAAE,OAAgB,EAAE,KAAgC,EAAE,KAAK,GAAa,MAAM;QAC7G,KAAK,CAAC,GAAG,CAAC,OAAO,EAAE,OAAO,EAAE,KAAK,aAAL,KAAK,cAAL,KAAK,GAAI,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,KAAK,CAAC,CAAC;IACpF,CAAC;CACJ,CAAA;AArEsB;IADlB,KAAK,CAAC,GAAG,aAAa,gBAAgB,CAAC;;oDACS;AAI9B;IAFlB,SAAS,CAAC,aAAa,CAAC;IACxB,QAAQ,EAAE;;qDACuC;AAIxC;IAFT,SAAS,CAAC,gBAAgB,CAAC;IAC3B,QAAQ,EAAE;;6CACwB;AAGzB;IADT,aAAa,EAAE;;;;yCAkBf;AA/BQ,aAAa;IADzB,SAAS,CAAC,EAAE,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,KAAK,CAAC,SAAS,EAAE,CAAC;GACnD,aAAa,CAwEzB"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AbstractLogger } from '@celljs/core';
|
|
1
|
+
import { AbstractLogger, LogLevel } from '@celljs/core';
|
|
2
2
|
import { WinstonConfig, RawWinstonLogger } from './winston-logger-protocol';
|
|
3
3
|
export declare class WinstonLogger extends AbstractLogger {
|
|
4
4
|
protected readonly winstonConfig?: WinstonConfig;
|
|
@@ -10,7 +10,10 @@ export declare class WinstonLogger extends AbstractLogger {
|
|
|
10
10
|
warn(message: string, context?: string): void;
|
|
11
11
|
info(message: string, context?: string): void;
|
|
12
12
|
debug(message: string, context?: string): void;
|
|
13
|
-
|
|
14
|
-
|
|
13
|
+
/** winston decides, with its own level (winstonConfig may set one). */
|
|
14
|
+
isEnabled(level: LogLevel): boolean;
|
|
15
|
+
/** winston writes the time and the level itself. */
|
|
16
|
+
protected resolvePrefix(): string;
|
|
17
|
+
protected log(message: any, context?: string, logFn?: (...args: any[]) => void, level?: LogLevel): void;
|
|
15
18
|
}
|
|
16
19
|
//# sourceMappingURL=winston-logger.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"winston-logger.d.ts","sourceRoot":"","sources":["../../src/node/winston-logger.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgE,cAAc,EAAwB,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"winston-logger.d.ts","sourceRoot":"","sources":["../../src/node/winston-logger.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgE,cAAc,EAAwB,QAAQ,EAAE,MAAM,cAAc,CAAC;AAC5I,OAAO,EAAE,aAAa,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAC;AAK5E,qBACa,aAAc,SAAQ,cAAc;IAG7C,SAAS,CAAC,QAAQ,CAAC,aAAa,CAAC,EAAE,aAAa,CAAC;IAIjD,SAAS,CAAC,QAAQ,CAAC,cAAc,CAAC,EAAE,aAAa,CAAC;IAIlD,SAAS,CAAC,MAAM,EAAE,gBAAgB,CAAC;IAGnC,SAAS,CAAC,IAAI,SAiBb;IAED,SAAS,qBAER;IAED,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,QAEtC;IAED,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,QAIrC;IAED,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,QAIrC;IAED,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,QAItC;IAED,uEAAuE;IAC9D,SAAS,CAAC,KAAK,EAAE,QAAQ,GAAG,OAAO,CAE3C;IAED,oDAAoD;IACpD,UAAmB,aAAa,IAAI,MAAM,CAEzC;IAED,UAAmB,GAAG,CAAC,OAAO,EAAE,GAAG,EAAE,OAAO,CAAC,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,IAAI,EAAE,KAAK,GAAE,QAAiB,GAAG,IAAI,CAEvH;CACJ"}
|
|
@@ -34,22 +34,34 @@ let WinstonLogger = class WinstonLogger extends core_1.AbstractLogger {
|
|
|
34
34
|
return this.logger;
|
|
35
35
|
}
|
|
36
36
|
error(message, context) {
|
|
37
|
-
this.log(message, context, this.logger.error.bind(this.logger));
|
|
37
|
+
this.log(message, context, this.logger.error.bind(this.logger), 'error');
|
|
38
38
|
}
|
|
39
39
|
warn(message, context) {
|
|
40
|
-
this.
|
|
40
|
+
if (this.isEnabled('warn')) {
|
|
41
|
+
this.log(message, context, this.logger.warn.bind(this.logger), 'warn');
|
|
42
|
+
}
|
|
41
43
|
}
|
|
42
44
|
info(message, context) {
|
|
43
|
-
this.
|
|
45
|
+
if (this.isEnabled('info')) {
|
|
46
|
+
this.log(message, context, this.logger.info.bind(this.logger), 'info');
|
|
47
|
+
}
|
|
44
48
|
}
|
|
45
49
|
debug(message, context) {
|
|
46
|
-
this.
|
|
50
|
+
if (this.isEnabled('debug')) {
|
|
51
|
+
this.log(message, context, this.logger.debug.bind(this.logger), 'debug');
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
/** winston decides, with its own level (winstonConfig may set one). */
|
|
55
|
+
isEnabled(level) {
|
|
56
|
+
var _a;
|
|
57
|
+
return ((_a = this.logger) === null || _a === void 0 ? void 0 : _a.isLevelEnabled) ? this.logger.isLevelEnabled(level) : super.isEnabled(level);
|
|
47
58
|
}
|
|
48
|
-
|
|
59
|
+
/** winston writes the time and the level itself. */
|
|
60
|
+
resolvePrefix() {
|
|
49
61
|
return '';
|
|
50
62
|
}
|
|
51
|
-
log(message, context, logFn) {
|
|
52
|
-
super.log(message, context, logFn !== null && logFn !== void 0 ? logFn : this.logger.info.bind(this.logger));
|
|
63
|
+
log(message, context, logFn, level = 'info') {
|
|
64
|
+
super.log(message, context, logFn !== null && logFn !== void 0 ? logFn : this.logger.info.bind(this.logger), level);
|
|
53
65
|
}
|
|
54
66
|
};
|
|
55
67
|
exports.WinstonLogger = WinstonLogger;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"winston-logger.js","sourceRoot":"","sources":["../../src/node/winston-logger.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,
|
|
1
|
+
{"version":3,"file":"winston-logger.js","sourceRoot":"","sources":["../../src/node/winston-logger.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,uCAA4I;AAC5I,uEAA4E;AAC5E,qCAA2D;AAE3D,IAAI,OAAyB,CAAC;AAGvB,IAAM,aAAa,GAAnB,MAAM,aAAc,SAAQ,qBAAc;IAcnC,IAAI;QACV,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC;YACf,IAAI,OAAO,EAAE,CAAC;gBACV,IAAI,CAAC,MAAM,GAAG,OAAO,CAAC;gBACtB,OAAO;YACX,CAAC;YACD,OAAO,GAAG,IAAA,sBAAY,EAAC;gBACnB,KAAK,EAAE,IAAI,CAAC,KAAK;gBACjB,MAAM,EAAE,gBAAM,CAAC,OAAO,CAClB,gBAAM,CAAC,SAAS,EAAE,EAClB,gBAAM,CAAC,MAAM,CAAC,CAAC,EAAE,KAAK,EAAE,OAAO,EAAE,SAAS,EAAE,EAAE,EAAE,CAAC,GAAG,SAAS,KAAK,KAAK,KAAK,OAAO,EAAE,CAAC,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L,CAAC;IAED,uEAAuE;IAC9D,SAAS,CAAC,KAAe;;QAC9B,OAAO,CAAA,MAAA,IAAI,CAAC,MAAM,0CAAE,cAAc,EAAC,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,cAAc,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;IACpG,CAAC;IAED,oDAAoD;IACjC,aAAa;QAC5B,OAAO,EAAE,CAAC;IACd,CAAC;IAEkB,GAAG,CAAC,OAAY,EAAE,OAAgB,EAAE,KAAgC,EAAE,KAAK,GAAa,MAAM;QAC7G,KAAK,CAAC,GAAG,CAAC,OAAO,EAAE,OAAO,EAAE,KAAK,aAAL,KAAK,cAAL,KAAK,GAAI,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,KAAK,CAAC,CAAC;IACpF,CAAC;CACJ,CAAA;;AArEsB;IADlB,IAAA,YAAK,EAAC,GAAG,oBAAa,gBAAgB,CAAC;;oDACS;AAI9B;IAFlB,IAAA,gBAAS,EAAC,uCAAa,CAAC;IACxB,IAAA,eAAQ,GAAE;;qDACuC;AAIxC;IAFT,IAAA,gBAAS,EAAC,0CAAgB,CAAC;IAC3B,IAAA,eAAQ,GAAE;;6CACwB;AAGzB;IADT,IAAA,oBAAa,GAAE;;;;yCAkBf;wBA/BQ,aAAa;IADzB,IAAA,gBAAS,EAAC,EAAE,EAAE,EAAE,aAAM,EAAE,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,YAAK,CAAC,SAAS,EAAE,CAAC;GACnD,aAAa,CAwEzB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"winston-logger.spec.d.ts","sourceRoot":"","sources":["../../src/node/winston-logger.spec.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const bun_test_1 = require("bun:test");
|
|
4
|
+
const chai_1 = require("chai");
|
|
5
|
+
const winston_1 = require("winston");
|
|
6
|
+
const winston_logger_1 = require("./winston-logger");
|
|
7
|
+
function logger(winstonLevel, cellLevel = 'info') {
|
|
8
|
+
const written = [];
|
|
9
|
+
const raw = (0, winston_1.createLogger)({ level: winstonLevel, transports: [new winston_1.transports.Console({ silent: true })] });
|
|
10
|
+
raw.on('data', (info) => written.push({ level: info.level, message: info.message }));
|
|
11
|
+
const instance = new winston_logger_1.WinstonLogger();
|
|
12
|
+
Object.assign(instance, { logger: raw, level: cellLevel });
|
|
13
|
+
return { instance, written };
|
|
14
|
+
}
|
|
15
|
+
(0, bun_test_1.describe)('WinstonLogger', () => {
|
|
16
|
+
(0, bun_test_1.it)('passes each message to winston at its own level, without a prefix', () => {
|
|
17
|
+
const { instance, written } = logger('debug', 'debug');
|
|
18
|
+
instance.debug('d');
|
|
19
|
+
instance.warn('w');
|
|
20
|
+
instance.error('e');
|
|
21
|
+
(0, chai_1.expect)(written).to.deep.equal([
|
|
22
|
+
{ level: 'debug', message: 'd' },
|
|
23
|
+
{ level: 'warn', message: 'w' },
|
|
24
|
+
{ level: 'error', message: 'e' },
|
|
25
|
+
]);
|
|
26
|
+
});
|
|
27
|
+
(0, bun_test_1.it)('asks winston whether a level is enabled (winstonConfig may set a level of its own)', () => {
|
|
28
|
+
const { instance } = logger('debug', 'info');
|
|
29
|
+
(0, chai_1.expect)(instance.isEnabled('debug')).to.equal(true);
|
|
30
|
+
(0, chai_1.expect)(logger('warn', 'debug').instance.isEnabled('info')).to.equal(false);
|
|
31
|
+
});
|
|
32
|
+
});
|
|
33
|
+
//# sourceMappingURL=winston-logger.spec.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"winston-logger.spec.js","sourceRoot":"","sources":["../../src/node/winston-logger.spec.ts"],"names":[],"mappings":";;AAAA,uCAAwC;AACxC,+BAA8B;AAC9B,qCAAmD;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AAE,GAAG,EAAE;YAC/B,EAAE,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,GAAG,EAAE;SACnC,CAAC,CAAC;IACP,CAAC,CAAC,CAAC;IAEH,IAAA,aAAE,EAAC,oFAAoF,EAAE,GAAG,EAAE;QAC1F,MAAM,EAAE,QAAQ,EAAE,GAAG,MAAM,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;QAC7C,IAAA,aAAM,EAAC,QAAQ,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QACnD,IAAA,aAAM,EAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,QAAQ,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;IAC/E,CAAC,CAAC,CAAC;AACP,CAAC,CAAC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@celljs/logger",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "4.1.0",
|
|
4
4
|
"description": "logger component for pino",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"cell-component"
|
|
@@ -29,8 +29,7 @@
|
|
|
29
29
|
"watch": "tsc -b -w --preserveWatchOutput"
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@celljs/core": "
|
|
33
|
-
"tslib": "^2.8.0",
|
|
32
|
+
"@celljs/core": "4.1.0",
|
|
34
33
|
"winston": "^3.10.0"
|
|
35
34
|
},
|
|
36
35
|
"publishConfig": {
|
|
@@ -38,26 +37,29 @@
|
|
|
38
37
|
},
|
|
39
38
|
"exports": {
|
|
40
39
|
".": {
|
|
41
|
-
"webpack": "./lib/node/index.js",
|
|
42
40
|
"import": "./esm/node/index.js",
|
|
43
41
|
"default": "./lib/node/index.js"
|
|
44
42
|
},
|
|
45
43
|
"./package.json": "./package.json",
|
|
46
44
|
"./lib/node": {
|
|
47
|
-
"webpack": "./lib/node/index.js",
|
|
48
45
|
"import": "./esm/node/index.js",
|
|
49
46
|
"default": "./lib/node/index.js"
|
|
50
47
|
},
|
|
51
48
|
"./lib/*.js": {
|
|
52
|
-
"webpack": "./lib/*.js",
|
|
53
49
|
"import": "./esm/*.js",
|
|
54
50
|
"default": "./lib/*.js"
|
|
55
51
|
},
|
|
56
52
|
"./lib/*": {
|
|
57
|
-
"webpack": "./lib/*.js",
|
|
58
53
|
"import": "./esm/*.js",
|
|
59
54
|
"default": "./lib/*.js"
|
|
60
55
|
},
|
|
61
56
|
"./*": "./*"
|
|
57
|
+
},
|
|
58
|
+
"cell": {
|
|
59
|
+
"modules": {
|
|
60
|
+
"backend": [
|
|
61
|
+
"lib/node/module"
|
|
62
|
+
]
|
|
63
|
+
}
|
|
62
64
|
}
|
|
63
65
|
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { describe, it } from 'bun:test';
|
|
2
|
+
import { expect } from 'chai';
|
|
3
|
+
import { createLogger, transports } from 'winston';
|
|
4
|
+
import { WinstonLogger } from './winston-logger';
|
|
5
|
+
|
|
6
|
+
function logger(winstonLevel: string, cellLevel = 'info') {
|
|
7
|
+
const written: { level: string; message: string }[] = [];
|
|
8
|
+
const raw = createLogger({ level: winstonLevel, transports: [new transports.Console({ silent: true })] });
|
|
9
|
+
raw.on('data', (info: { level: string; message: string }) => written.push({ level: info.level, message: info.message }));
|
|
10
|
+
const instance = new WinstonLogger();
|
|
11
|
+
Object.assign(instance, { logger: raw, level: cellLevel });
|
|
12
|
+
return { instance, written };
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
describe('WinstonLogger', () => {
|
|
16
|
+
it('passes each message to winston at its own level, without a prefix', () => {
|
|
17
|
+
const { instance, written } = logger('debug', 'debug');
|
|
18
|
+
instance.debug('d');
|
|
19
|
+
instance.warn('w');
|
|
20
|
+
instance.error('e');
|
|
21
|
+
expect(written).to.deep.equal([
|
|
22
|
+
{ level: 'debug', message: 'd' },
|
|
23
|
+
{ level: 'warn', message: 'w' },
|
|
24
|
+
{ level: 'error', message: 'e' },
|
|
25
|
+
]);
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
it('asks winston whether a level is enabled (winstonConfig may set a level of its own)', () => {
|
|
29
|
+
const { instance } = logger('debug', 'info');
|
|
30
|
+
expect(instance.isEnabled('debug')).to.equal(true);
|
|
31
|
+
expect(logger('warn', 'debug').instance.isEnabled('info')).to.equal(false);
|
|
32
|
+
});
|
|
33
|
+
});
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Logger, LOGGER_CONFIG, Value, Component, Autowired, Optional, AbstractLogger, PostConstruct, Scope } from '@celljs/core';
|
|
1
|
+
import { Logger, LOGGER_CONFIG, Value, Component, Autowired, Optional, AbstractLogger, PostConstruct, Scope, LogLevel } from '@celljs/core';
|
|
2
2
|
import { WinstonConfig, RawWinstonLogger } from './winston-logger-protocol';
|
|
3
3
|
import { createLogger, transports, format } from 'winston';
|
|
4
4
|
|
|
@@ -43,26 +43,38 @@ export class WinstonLogger extends AbstractLogger {
|
|
|
43
43
|
}
|
|
44
44
|
|
|
45
45
|
error(message: string, context?: string) {
|
|
46
|
-
this.log(message, context, this.logger.error.bind(this.logger));
|
|
46
|
+
this.log(message, context, this.logger.error.bind(this.logger), 'error');
|
|
47
47
|
}
|
|
48
48
|
|
|
49
49
|
warn(message: string, context?: string) {
|
|
50
|
-
this.
|
|
50
|
+
if (this.isEnabled('warn')) {
|
|
51
|
+
this.log(message, context, this.logger.warn.bind(this.logger), 'warn');
|
|
52
|
+
}
|
|
51
53
|
}
|
|
52
54
|
|
|
53
55
|
info(message: string, context?: string) {
|
|
54
|
-
this.
|
|
56
|
+
if (this.isEnabled('info')) {
|
|
57
|
+
this.log(message, context, this.logger.info.bind(this.logger), 'info');
|
|
58
|
+
}
|
|
55
59
|
}
|
|
56
60
|
|
|
57
61
|
debug(message: string, context?: string) {
|
|
58
|
-
this.
|
|
62
|
+
if (this.isEnabled('debug')) {
|
|
63
|
+
this.log(message, context, this.logger.debug.bind(this.logger), 'debug');
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/** winston decides, with its own level (winstonConfig may set one). */
|
|
68
|
+
override isEnabled(level: LogLevel): boolean {
|
|
69
|
+
return this.logger?.isLevelEnabled ? this.logger.isLevelEnabled(level) : super.isEnabled(level);
|
|
59
70
|
}
|
|
60
71
|
|
|
61
|
-
|
|
72
|
+
/** winston writes the time and the level itself. */
|
|
73
|
+
protected override resolvePrefix(): string {
|
|
62
74
|
return '';
|
|
63
75
|
}
|
|
64
76
|
|
|
65
|
-
protected override log(message: any, context?: string, logFn?: (...args: any[]) => void): void {
|
|
66
|
-
super.log(message, context, logFn ?? this.logger.info.bind(this.logger));
|
|
77
|
+
protected override log(message: any, context?: string, logFn?: (...args: any[]) => void, level: LogLevel = 'info'): void {
|
|
78
|
+
super.log(message, context, logFn ?? this.logger.info.bind(this.logger), level);
|
|
67
79
|
}
|
|
68
80
|
}
|