standard-log 9.1.0 → 9.1.3
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 +35 -5
- package/cjs/console.spec.js +1 -1
- package/cjs/console.spec.js.map +1 -1
- package/cjs/index.d.ts +2 -2
- package/cjs/index.d.ts.map +1 -1
- package/cjs/index.js +4 -4
- package/cjs/index.js.map +1 -1
- package/cjs/logger.d.ts +1 -2
- package/cjs/logger.d.ts.map +1 -1
- package/cjs/logger.js +6 -7
- package/cjs/logger.js.map +1 -1
- package/cjs/standardLog.d.ts +11 -3
- package/cjs/standardLog.d.ts.map +1 -1
- package/cjs/standardLog.js +40 -5
- package/cjs/standardLog.js.map +1 -1
- package/cjs/standardLog.spec.js +133 -85
- package/cjs/standardLog.spec.js.map +1 -1
- package/cjs/types.d.ts +2 -1
- package/cjs/types.d.ts.map +1 -1
- package/cjs/types.js.map +1 -1
- package/dist/standard-log.es5.js +50 -59
- package/dist/standard-log.es5.js.gz +0 -0
- package/dist/standard-log.es5.js.map +1 -1
- package/dist/standard-log.es5.js.map.gz +0 -0
- package/dist/standard-log.esm.js +55 -65
- package/dist/standard-log.esm.js.gz +0 -0
- package/dist/standard-log.esm.js.map +1 -1
- package/dist/standard-log.esm.js.map.gz +0 -0
- package/esm/console.spec.js +1 -1
- package/esm/console.spec.js.map +1 -1
- package/esm/index.d.ts +2 -2
- package/esm/index.d.ts.map +1 -1
- package/esm/index.js +1 -2
- package/esm/index.js.map +1 -1
- package/esm/logger.d.ts +1 -2
- package/esm/logger.d.ts.map +1 -1
- package/esm/logger.js +2 -2
- package/esm/logger.js.map +1 -1
- package/esm/standardLog.d.ts +11 -3
- package/esm/standardLog.d.ts.map +1 -1
- package/esm/standardLog.js +37 -4
- package/esm/standardLog.js.map +1 -1
- package/esm/standardLog.spec.js +93 -46
- package/esm/standardLog.spec.js.map +1 -1
- package/esm/types.d.ts +2 -1
- package/esm/types.d.ts.map +1 -1
- package/esm/types.js.map +1 -1
- package/package.json +1 -1
- package/ts/index.ts +3 -3
- package/ts/logger.ts +2 -3
- package/ts/standardLog.ts +44 -6
- package/ts/types.ts +3 -1
- package/cjs/global.d.ts +0 -13
- package/cjs/global.d.ts.map +0 -1
- package/cjs/global.js +0 -33
- package/cjs/global.js.map +0 -1
- package/cjs/global.spec.d.ts +0 -2
- package/cjs/global.spec.d.ts.map +0 -1
- package/cjs/global.spec.js +0 -32
- package/cjs/global.spec.js.map +0 -1
- package/esm/global.d.ts +0 -13
- package/esm/global.d.ts.map +0 -1
- package/esm/global.js +0 -28
- package/esm/global.js.map +0 -1
- package/esm/global.spec.d.ts +0 -2
- package/esm/global.spec.d.ts.map +0 -1
- package/esm/global.spec.js +0 -30
- package/esm/global.spec.js.map +0 -1
- package/ts/global.ts +0 -34
package/cjs/standardLog.spec.js
CHANGED
|
@@ -38,6 +38,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
38
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
39
|
var assertron_1 = require("assertron");
|
|
40
40
|
var errors_js_1 = require("./errors.js");
|
|
41
|
+
var index_js_1 = require("./index.js");
|
|
41
42
|
var logLevels_js_1 = require("./logLevels.js");
|
|
42
43
|
var memory_js_1 = require("./memory.js");
|
|
43
44
|
var standardLog_js_1 = require("./standardLog.js");
|
|
@@ -45,98 +46,109 @@ var testUtil_js_1 = require("./testUtil.js");
|
|
|
45
46
|
describe('createStandardLog()', function () {
|
|
46
47
|
describe('logLevel', function () {
|
|
47
48
|
it('is default to info', function () {
|
|
48
|
-
var actual = (0,
|
|
49
|
+
var actual = (0, index_js_1.createStandardLog)();
|
|
49
50
|
expect(actual.logLevel).toBe(logLevels_js_1.logLevels.info);
|
|
50
51
|
});
|
|
51
52
|
it('is readonly', function () {
|
|
52
|
-
var actual = (0,
|
|
53
|
+
var actual = (0, index_js_1.createStandardLog)();
|
|
53
54
|
assertron_1.assertron.throws(function () { return actual.logLevel = logLevels_js_1.logLevels.planck; }, function (err) { return /only a getter/.test(err); });
|
|
54
55
|
});
|
|
55
56
|
it('set logLevel from options', function () {
|
|
56
|
-
var actual = (0,
|
|
57
|
+
var actual = (0, index_js_1.createStandardLog)({ logLevel: logLevels_js_1.logLevels.planck });
|
|
57
58
|
expect(actual.logLevel).toBe(logLevels_js_1.logLevels.planck);
|
|
58
59
|
});
|
|
59
60
|
});
|
|
60
61
|
describe('custom levels', function () {
|
|
61
62
|
it('can define custom levels', function () {
|
|
62
|
-
var actual = (0,
|
|
63
|
+
var actual = (0, index_js_1.createStandardLog)({ customLevels: { urgent: 80 } });
|
|
63
64
|
expect(actual.toLogLevelName(80)).toBe('urgent');
|
|
64
65
|
});
|
|
65
66
|
});
|
|
66
67
|
describe('reporters', function () {
|
|
67
68
|
it('can specify reporter', function () {
|
|
68
69
|
var mem = (0, memory_js_1.createMemoryLogReporter)();
|
|
69
|
-
var sl = (0,
|
|
70
|
-
var log = sl.getLogger(
|
|
70
|
+
var sl = (0, index_js_1.createStandardLog)({ reporters: [mem] });
|
|
71
|
+
var log = sl.getLogger('x');
|
|
71
72
|
log.info('abc');
|
|
72
73
|
expect(mem.logs.length).toBe(1);
|
|
73
74
|
});
|
|
74
75
|
});
|
|
76
|
+
describe('related to global', function () {
|
|
77
|
+
beforeEach(function () {
|
|
78
|
+
standardLog_js_1.ctx.gsl = undefined;
|
|
79
|
+
standardLog_js_1.ctx.configured = false;
|
|
80
|
+
});
|
|
81
|
+
it('will affect getLogger() if configGlobal() is not called', function () {
|
|
82
|
+
var _a;
|
|
83
|
+
(0, index_js_1.createStandardLog)({ logLevel: logLevels_js_1.logLevels.planck });
|
|
84
|
+
expect((_a = standardLog_js_1.ctx.gsl) === null || _a === void 0 ? void 0 : _a.standardLog.logLevel).toBe(logLevels_js_1.logLevels.planck);
|
|
85
|
+
});
|
|
86
|
+
});
|
|
75
87
|
});
|
|
76
88
|
describe('createStandardLogForTest()', function () {
|
|
77
89
|
it('returns with memory reporter', function () {
|
|
78
|
-
var reporter = (0,
|
|
90
|
+
var reporter = (0, index_js_1.createStandardLogForTest)().reporter;
|
|
79
91
|
expect(reporter.getLogMessageWithLevel()).toBe('');
|
|
80
92
|
});
|
|
81
93
|
it('defaults to debug', function () {
|
|
82
|
-
var store = (0,
|
|
94
|
+
var store = (0, index_js_1.createStandardLogForTest)();
|
|
83
95
|
expect(store.logLevel).toBe(logLevels_js_1.logLevels.debug);
|
|
84
96
|
});
|
|
85
97
|
});
|
|
86
|
-
describe('getLogger()', function () {
|
|
98
|
+
describe('standardLog.getLogger()', function () {
|
|
87
99
|
it('supports id with alphanumeric and :_-.', function () {
|
|
88
|
-
var sl = (0,
|
|
89
|
-
sl.getLogger(
|
|
100
|
+
var sl = (0, index_js_1.createStandardLog)();
|
|
101
|
+
sl.getLogger('abcdefghijklmnopqrstuvwxyz:-_.1234567890');
|
|
90
102
|
});
|
|
91
103
|
it('supports id with unicode', function () {
|
|
92
|
-
var sl = (0,
|
|
93
|
-
sl.getLogger(
|
|
104
|
+
var sl = (0, index_js_1.createStandardLog)();
|
|
105
|
+
sl.getLogger('ミク香港');
|
|
94
106
|
});
|
|
95
107
|
it('supports id with @, \\ and /', function () {
|
|
96
|
-
var sl = (0,
|
|
97
|
-
sl.getLogger(
|
|
98
|
-
sl.getLogger(
|
|
108
|
+
var sl = (0, index_js_1.createStandardLog)();
|
|
109
|
+
sl.getLogger('@unional/fixture');
|
|
110
|
+
sl.getLogger("a\\b\\c");
|
|
99
111
|
});
|
|
100
112
|
it.each('`~!#$%^&*()=+|[]{}<>,?'.split(''))('throws if id has unsupported character %s', function (char) {
|
|
101
|
-
var sl = (0,
|
|
102
|
-
assertron_1.assertron.throws(function () { return sl.getLogger(
|
|
113
|
+
var sl = (0, index_js_1.createStandardLog)();
|
|
114
|
+
assertron_1.assertron.throws(function () { return sl.getLogger(char); }, errors_js_1.InvalidId);
|
|
103
115
|
});
|
|
104
116
|
it('throw InvalidId with ssf to the call site', function () {
|
|
105
|
-
var sl = (0,
|
|
106
|
-
var err = assertron_1.assertron.throws(function () { return sl.getLogger(
|
|
117
|
+
var sl = (0, index_js_1.createStandardLog)();
|
|
118
|
+
var err = assertron_1.assertron.throws(function () { return sl.getLogger('!'); }, errors_js_1.InvalidId);
|
|
107
119
|
(0, testUtil_js_1.assertSSF)(err, __filename);
|
|
108
120
|
});
|
|
109
121
|
test('id is readonly', function () {
|
|
110
|
-
var sl = (0,
|
|
111
|
-
var log = sl.getLogger(
|
|
122
|
+
var sl = (0, index_js_1.createStandardLog)();
|
|
123
|
+
var log = sl.getLogger('id is readonly');
|
|
112
124
|
assertron_1.assertron.throws(function () { return log.id = 'b'; });
|
|
113
125
|
});
|
|
114
126
|
test('get logger with same name gets the same instance', function () {
|
|
115
|
-
var sl = (0,
|
|
116
|
-
var expected = sl.getLogger(
|
|
117
|
-
var actual = sl.getLogger(
|
|
127
|
+
var sl = (0, index_js_1.createStandardLog)();
|
|
128
|
+
var expected = sl.getLogger('same-inst');
|
|
129
|
+
var actual = sl.getLogger('same-inst');
|
|
118
130
|
expect(actual).toBe(expected);
|
|
119
131
|
});
|
|
120
132
|
it('can specify local log level', function () {
|
|
121
|
-
var sl = (0,
|
|
122
|
-
var log = sl.getLogger(
|
|
133
|
+
var sl = (0, index_js_1.createStandardLog)();
|
|
134
|
+
var log = sl.getLogger('local', { level: logLevels_js_1.logLevels.trace });
|
|
123
135
|
expect(log.level).toBe(logLevels_js_1.logLevels.trace);
|
|
124
136
|
});
|
|
125
137
|
test('new logger will get custom level', function () {
|
|
126
|
-
var sl = (0,
|
|
127
|
-
var actual = sl.getLogger(
|
|
138
|
+
var sl = (0, index_js_1.createStandardLog)({ customLevels: { 'to_logger': 1234 } });
|
|
139
|
+
var actual = sl.getLogger('to_logger_logger');
|
|
128
140
|
expect(typeof actual.to_logger).toBe('function');
|
|
129
141
|
});
|
|
130
142
|
it('Logger have at least the default log method names', function () {
|
|
131
143
|
function wrapper(options) {
|
|
132
|
-
var sl = (0,
|
|
144
|
+
var sl = (0, index_js_1.createStandardLog)(options);
|
|
133
145
|
// since `N` is generic, just `Logger<N>` will not have the default log method names.
|
|
134
|
-
var log = sl.getLogger(
|
|
146
|
+
var log = sl.getLogger('local');
|
|
135
147
|
expect(log.info).toBeDefined();
|
|
136
148
|
return sl;
|
|
137
149
|
}
|
|
138
150
|
var sl = wrapper({ customLevels: { 'cust': 123 } });
|
|
139
|
-
var actual = sl.getLogger(
|
|
151
|
+
var actual = sl.getLogger('c');
|
|
140
152
|
expect(actual.cust).toBeDefined();
|
|
141
153
|
});
|
|
142
154
|
describe('log levels', function () {
|
|
@@ -144,7 +156,7 @@ describe('getLogger()', function () {
|
|
|
144
156
|
return __awaiter(this, void 0, void 0, function () {
|
|
145
157
|
var log, msg;
|
|
146
158
|
return __generator(this, function (_a) {
|
|
147
|
-
log = sl.getLogger(
|
|
159
|
+
log = sl.getLogger(method);
|
|
148
160
|
msg = "should log on level: ".concat(level);
|
|
149
161
|
log[method](msg);
|
|
150
162
|
assertron_1.assertron.satisfies(sl.reporter.logs, [{ id: method, level: sl.toLogLevel(method), args: [msg] }]);
|
|
@@ -156,7 +168,7 @@ describe('getLogger()', function () {
|
|
|
156
168
|
return __awaiter(this, void 0, void 0, function () {
|
|
157
169
|
var log;
|
|
158
170
|
return __generator(this, function (_a) {
|
|
159
|
-
log = sl.getLogger(
|
|
171
|
+
log = sl.getLogger(method);
|
|
160
172
|
log[method]("should not log on level: ".concat(level));
|
|
161
173
|
expect(sl.reporter.logs.length).toBe(0);
|
|
162
174
|
return [2 /*return*/];
|
|
@@ -167,7 +179,7 @@ describe('getLogger()', function () {
|
|
|
167
179
|
return __awaiter(this, void 0, void 0, function () {
|
|
168
180
|
var log, msg;
|
|
169
181
|
return __generator(this, function (_a) {
|
|
170
|
-
log = sl.getLogger(
|
|
182
|
+
log = sl.getLogger(method, { level: localLevel });
|
|
171
183
|
msg = "should log on level: ".concat(localLevel);
|
|
172
184
|
log[method](msg);
|
|
173
185
|
assertron_1.assertron.satisfies(sl.reporter.logs, [{ id: log.id, level: sl.toLogLevel(method), args: [msg] }]);
|
|
@@ -179,7 +191,7 @@ describe('getLogger()', function () {
|
|
|
179
191
|
return __awaiter(this, void 0, void 0, function () {
|
|
180
192
|
var log;
|
|
181
193
|
return __generator(this, function (_a) {
|
|
182
|
-
log = sl.getLogger(
|
|
194
|
+
log = sl.getLogger(method, { level: localLevel });
|
|
183
195
|
log[method]("should not log on level: ".concat(localLevel));
|
|
184
196
|
expect(sl.reporter.logs.length).toBe(0);
|
|
185
197
|
return [2 /*return*/];
|
|
@@ -190,7 +202,7 @@ describe('getLogger()', function () {
|
|
|
190
202
|
return __awaiter(this, void 0, void 0, function () {
|
|
191
203
|
var log, actual;
|
|
192
204
|
return __generator(this, function (_a) {
|
|
193
|
-
log = sl.getLogger(
|
|
205
|
+
log = sl.getLogger(method);
|
|
194
206
|
actual = false;
|
|
195
207
|
log.on(callLevel, function () { return actual = true; });
|
|
196
208
|
expect(actual).toBe(true);
|
|
@@ -202,7 +214,7 @@ describe('getLogger()', function () {
|
|
|
202
214
|
return __awaiter(this, void 0, void 0, function () {
|
|
203
215
|
var log;
|
|
204
216
|
return __generator(this, function (_a) {
|
|
205
|
-
log = sl.getLogger(
|
|
217
|
+
log = sl.getLogger(method);
|
|
206
218
|
log.on(callLevel, function () { throw new Error("should not log at level ".concat(actualLevel)); });
|
|
207
219
|
return [2 /*return*/];
|
|
208
220
|
});
|
|
@@ -212,7 +224,7 @@ describe('getLogger()', function () {
|
|
|
212
224
|
return __awaiter(this, void 0, void 0, function () {
|
|
213
225
|
var log, actual;
|
|
214
226
|
return __generator(this, function (_a) {
|
|
215
|
-
log = sl.getLogger(
|
|
227
|
+
log = sl.getLogger(method, { level: localLevel });
|
|
216
228
|
actual = false;
|
|
217
229
|
log.on(callLevel, function () { return actual = true; });
|
|
218
230
|
expect(actual).toBe(true);
|
|
@@ -224,21 +236,21 @@ describe('getLogger()', function () {
|
|
|
224
236
|
return __awaiter(this, void 0, void 0, function () {
|
|
225
237
|
var log;
|
|
226
238
|
return __generator(this, function (_a) {
|
|
227
|
-
log = sl.getLogger(
|
|
239
|
+
log = sl.getLogger(method, { level: localLevel });
|
|
228
240
|
log.on(callLevel, function () { throw new Error("should not log at level ".concat(localLevel)); });
|
|
229
241
|
return [2 /*return*/];
|
|
230
242
|
});
|
|
231
243
|
});
|
|
232
244
|
}
|
|
233
245
|
var shouldLog = (0, testUtil_js_1.wrapTest)(function (test) { return function (method, level) {
|
|
234
|
-
var sl = (0,
|
|
246
|
+
var sl = (0, index_js_1.createStandardLogForTest)(level);
|
|
235
247
|
var name = sl.toLogLevelName(level);
|
|
236
248
|
test("".concat(method, "() should log on level: ").concat(name, " (").concat(level, ")"), function () {
|
|
237
249
|
return assertLoggedAtLevel(sl, method, level);
|
|
238
250
|
});
|
|
239
251
|
}; });
|
|
240
252
|
var shouldNotLog = (0, testUtil_js_1.wrapTest)(function (test) { return function (method, level) {
|
|
241
|
-
var sl = (0,
|
|
253
|
+
var sl = (0, index_js_1.createStandardLogForTest)(level);
|
|
242
254
|
var name = sl.toLogLevelName(level);
|
|
243
255
|
test("".concat(method, "() should not log on level: ").concat(name, " (").concat(level, ")"), function () {
|
|
244
256
|
return assertNotLoggedAtLevel(sl, method, level);
|
|
@@ -249,7 +261,7 @@ describe('getLogger()', function () {
|
|
|
249
261
|
[logLevels_js_1.logLevels.none, logLevels_js_1.logLevels.error, logLevels_js_1.logLevels.warn, logLevels_js_1.logLevels.info, logLevels_js_1.logLevels.debug].forEach(function (globalLevel) {
|
|
250
262
|
var globalName = (0, logLevels_js_1.toLogLevelName)(globalLevel) || 'none';
|
|
251
263
|
test("".concat(method, "() should log on local level: ").concat(localName, " (").concat(localLevel, ") while global level: ").concat(globalName, " (").concat(globalLevel, ")"), function () {
|
|
252
|
-
var sl = (0,
|
|
264
|
+
var sl = (0, index_js_1.createStandardLogForTest)(globalLevel);
|
|
253
265
|
return assertLoggedAtLocalLevel(sl, method, localLevel);
|
|
254
266
|
});
|
|
255
267
|
});
|
|
@@ -259,7 +271,7 @@ describe('getLogger()', function () {
|
|
|
259
271
|
[logLevels_js_1.logLevels.none, logLevels_js_1.logLevels.error, logLevels_js_1.logLevels.warn, logLevels_js_1.logLevels.info, logLevels_js_1.logLevels.debug].forEach(function (globalLevel) {
|
|
260
272
|
var globalName = (0, logLevels_js_1.toLogLevelName)(globalLevel) || 'none';
|
|
261
273
|
test("".concat(method, "() should not log on local level: ").concat(localName, " (").concat(localLevel, ") while global level: ").concat(globalName, " (").concat(globalLevel, ")"), function () {
|
|
262
|
-
var sl = (0,
|
|
274
|
+
var sl = (0, index_js_1.createStandardLogForTest)(globalLevel);
|
|
263
275
|
return assertNotLoggedAtLocalLevel(sl, method, localLevel);
|
|
264
276
|
});
|
|
265
277
|
});
|
|
@@ -268,7 +280,7 @@ describe('getLogger()', function () {
|
|
|
268
280
|
var method = (0, logLevels_js_1.toLogLevelName)(callLevel);
|
|
269
281
|
var name = (0, logLevels_js_1.toLogLevelName)(actualLevel);
|
|
270
282
|
test("".concat(method, "() should call log function on level: ").concat(name, " (").concat(actualLevel, ")"), function () {
|
|
271
|
-
var sl = (0,
|
|
283
|
+
var sl = (0, index_js_1.createStandardLogForTest)(actualLevel);
|
|
272
284
|
return assertLoggedAtCallLevel(sl, method, callLevel);
|
|
273
285
|
});
|
|
274
286
|
}; });
|
|
@@ -276,7 +288,7 @@ describe('getLogger()', function () {
|
|
|
276
288
|
var method = (0, logLevels_js_1.toLogLevelName)(callLevel);
|
|
277
289
|
var name = (0, logLevels_js_1.toLogLevelName)(actualLevel);
|
|
278
290
|
test("".concat(method, "() should not call log function on level: ").concat(name, " (").concat(actualLevel, ")"), function () {
|
|
279
|
-
var sl = (0,
|
|
291
|
+
var sl = (0, index_js_1.createStandardLogForTest)(actualLevel);
|
|
280
292
|
return assertNotLoggedAtCallLevel(sl, method, callLevel, actualLevel);
|
|
281
293
|
});
|
|
282
294
|
}; });
|
|
@@ -286,7 +298,7 @@ describe('getLogger()', function () {
|
|
|
286
298
|
[logLevels_js_1.logLevels.none, logLevels_js_1.logLevels.error, logLevels_js_1.logLevels.warn, logLevels_js_1.logLevels.info, logLevels_js_1.logLevels.debug].forEach(function (globalLevel) {
|
|
287
299
|
var globalName = (0, logLevels_js_1.toLogLevelName)(globalLevel) || 'none';
|
|
288
300
|
test("".concat(method, "() should log on local level: ").concat(localName, " (").concat(localLevel, ") while global level: ").concat(globalName, " (").concat(globalLevel, ")"), function () {
|
|
289
|
-
var sl = (0,
|
|
301
|
+
var sl = (0, index_js_1.createStandardLogForTest)(globalLevel);
|
|
290
302
|
return assertLoggedAtCallLevelOverrideLocalLevel(sl, method, localLevel, callLevel);
|
|
291
303
|
});
|
|
292
304
|
});
|
|
@@ -297,7 +309,7 @@ describe('getLogger()', function () {
|
|
|
297
309
|
[logLevels_js_1.logLevels.none, logLevels_js_1.logLevels.error, logLevels_js_1.logLevels.warn, logLevels_js_1.logLevels.info, logLevels_js_1.logLevels.debug].forEach(function (globalLevel) {
|
|
298
310
|
var globalName = (0, logLevels_js_1.toLogLevelName)(globalLevel) || 'none';
|
|
299
311
|
test("".concat(method, "() should not log on local level: ").concat(localName, " (").concat(localLevel, ") while global level: ").concat(globalName, " (").concat(globalLevel, ")"), function () {
|
|
300
|
-
var sl = (0,
|
|
312
|
+
var sl = (0, index_js_1.createStandardLogForTest)(globalLevel);
|
|
301
313
|
return assertNotLoggedAtCallLevelOverrideLocalLevel(sl, method, localLevel, callLevel);
|
|
302
314
|
});
|
|
303
315
|
});
|
|
@@ -384,29 +396,29 @@ describe('getLogger()', function () {
|
|
|
384
396
|
shouldCallLogFunctionWithLocalLevelOverride(logLevels_js_1.logLevels.debug, logLevels_js_1.logLevels.debug);
|
|
385
397
|
});
|
|
386
398
|
it('writes entry directly', function () {
|
|
387
|
-
var sl = (0,
|
|
388
|
-
var log = sl.getLogger(
|
|
399
|
+
var sl = (0, index_js_1.createStandardLogForTest)();
|
|
400
|
+
var log = sl.getLogger('write-entry');
|
|
389
401
|
var entry = { id: 'write-entry', level: logLevels_js_1.logLevels.info, args: ['abc'], timestamp: new Date() };
|
|
390
402
|
log.write(entry);
|
|
391
403
|
assertron_1.assertron.satisfies(sl.reporter.logs, [entry]);
|
|
392
404
|
});
|
|
393
405
|
test.each(['on', 'count', 'error', 'warn', 'info', 'debug'])('method %s is readonly', function (name) {
|
|
394
|
-
var sl = (0,
|
|
395
|
-
var log = sl.getLogger(
|
|
406
|
+
var sl = (0, index_js_1.createStandardLog)();
|
|
407
|
+
var log = sl.getLogger("".concat(name, " is readonly"));
|
|
396
408
|
assertron_1.assertron.throws(function () { return log[name] = true; });
|
|
397
409
|
});
|
|
398
410
|
describe('on()', function () {
|
|
399
411
|
it('log using log argument', function () {
|
|
400
|
-
var sl = (0,
|
|
401
|
-
var logger = sl.getLogger(
|
|
412
|
+
var sl = (0, index_js_1.createStandardLogForTest)();
|
|
413
|
+
var logger = sl.getLogger('log on fn');
|
|
402
414
|
logger.on('error', function (log) { log('value'); });
|
|
403
415
|
assertron_1.assertron.satisfies(sl.reporter.logs, [
|
|
404
416
|
{ id: 'log on fn', level: logLevels_js_1.logLevels.error, args: ['value'] }
|
|
405
417
|
]);
|
|
406
418
|
});
|
|
407
419
|
it('can take log level name in first argument', function () {
|
|
408
|
-
var sl = (0,
|
|
409
|
-
var log = sl.getLogger(
|
|
420
|
+
var sl = (0, index_js_1.createStandardLogForTest)();
|
|
421
|
+
var log = sl.getLogger('string-on');
|
|
410
422
|
log.on('debug', function () { return; });
|
|
411
423
|
});
|
|
412
424
|
});
|
|
@@ -414,8 +426,8 @@ describe('getLogger()', function () {
|
|
|
414
426
|
test('will increment the counter', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
415
427
|
var sl, logger;
|
|
416
428
|
return __generator(this, function (_a) {
|
|
417
|
-
sl = (0,
|
|
418
|
-
logger = sl.getLogger(
|
|
429
|
+
sl = (0, index_js_1.createStandardLogForTest)();
|
|
430
|
+
logger = sl.getLogger('inc counter');
|
|
419
431
|
logger.count();
|
|
420
432
|
logger.count();
|
|
421
433
|
assertron_1.assertron.satisfies(sl.reporter.logs, [
|
|
@@ -428,9 +440,9 @@ describe('getLogger()', function () {
|
|
|
428
440
|
test('append args after the counter', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
429
441
|
var sl, id, logger;
|
|
430
442
|
return __generator(this, function (_a) {
|
|
431
|
-
sl = (0,
|
|
443
|
+
sl = (0, index_js_1.createStandardLogForTest)(logLevels_js_1.logLevels.debug);
|
|
432
444
|
id = 'inc with args';
|
|
433
|
-
logger = sl.getLogger(
|
|
445
|
+
logger = sl.getLogger(id);
|
|
434
446
|
logger.count('msg1', 'msg2');
|
|
435
447
|
assertron_1.assertron.satisfies(sl.reporter.logs, [
|
|
436
448
|
{ id: id, level: logLevels_js_1.logLevels.debug, args: [1, 'msg1', 'msg2'] }
|
|
@@ -441,9 +453,9 @@ describe('getLogger()', function () {
|
|
|
441
453
|
test('not log if log level is less than debug', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
442
454
|
var sl, id, logger;
|
|
443
455
|
return __generator(this, function (_a) {
|
|
444
|
-
sl = (0,
|
|
456
|
+
sl = (0, index_js_1.createStandardLogForTest)(logLevels_js_1.logLevels.debug - 1);
|
|
445
457
|
id = 'inc with args';
|
|
446
|
-
logger = sl.getLogger(
|
|
458
|
+
logger = sl.getLogger(id);
|
|
447
459
|
logger.count('msg1', 'msg2');
|
|
448
460
|
expect(sl.reporter.logs.length).toBe(0);
|
|
449
461
|
return [2 /*return*/];
|
|
@@ -454,44 +466,44 @@ describe('getLogger()', function () {
|
|
|
454
466
|
var mem, sl, logger;
|
|
455
467
|
return __generator(this, function (_a) {
|
|
456
468
|
mem = (0, memory_js_1.createMemoryLogReporter)();
|
|
457
|
-
sl = (0,
|
|
458
|
-
logger = sl.getLogger(
|
|
469
|
+
sl = (0, index_js_1.createStandardLog)({ customLevels: { 'cust_lvl': 100 }, reporters: [mem] });
|
|
470
|
+
logger = sl.getLogger('cust');
|
|
459
471
|
logger.cust_lvl('a', 'b');
|
|
460
472
|
assertron_1.assertron.satisfies(mem.logs, [{ id: 'cust', level: 100, args: ['a', 'b'] }]);
|
|
461
473
|
return [2 /*return*/];
|
|
462
474
|
});
|
|
463
475
|
}); });
|
|
464
476
|
describe('getLogger([,{ writeTo }])', function () {
|
|
465
|
-
function testWriteTo(
|
|
477
|
+
function testWriteTo(id, options, handler) {
|
|
466
478
|
var memReporter = (0, memory_js_1.createMemoryLogReporter)();
|
|
467
479
|
var specialReporter = (0, memory_js_1.createMemoryLogReporter)({ id: 'special' });
|
|
468
|
-
var sl = (0,
|
|
469
|
-
var log = sl.getLogger(
|
|
480
|
+
var sl = (0, index_js_1.createStandardLog)({ reporters: [memReporter, specialReporter] });
|
|
481
|
+
var log = sl.getLogger(id, options);
|
|
470
482
|
handler(log, memReporter.logs, specialReporter.logs, sl);
|
|
471
483
|
}
|
|
472
484
|
it('can specify which reporter to use by name', function () {
|
|
473
|
-
testWriteTo(
|
|
485
|
+
testWriteTo('writeTo-string', { writeTo: 'special' }, function (log, memLogs, specialLogs) {
|
|
474
486
|
log.error('error message');
|
|
475
487
|
expect(memLogs.length).toEqual(0);
|
|
476
488
|
expect(specialLogs.length).toEqual(1);
|
|
477
489
|
});
|
|
478
490
|
});
|
|
479
491
|
it('can specify which reporter to use by regex', function () {
|
|
480
|
-
testWriteTo(
|
|
492
|
+
testWriteTo('writeTo-regex', { writeTo: /^spec/ }, function (log, memLogs, specialLogs) {
|
|
481
493
|
log.error('error message');
|
|
482
494
|
expect(memLogs.length).toEqual(0);
|
|
483
495
|
expect(specialLogs.length).toEqual(1);
|
|
484
496
|
});
|
|
485
497
|
});
|
|
486
498
|
it('can specify which reporter to use by RegExp', function () {
|
|
487
|
-
testWriteTo(
|
|
499
|
+
testWriteTo('writeTo-RegExp', { writeTo: new RegExp('^spec') }, function (log, memLogs, specialLogs) {
|
|
488
500
|
log.error('error message');
|
|
489
501
|
expect(memLogs.length).toEqual(0);
|
|
490
502
|
expect(specialLogs.length).toEqual(1);
|
|
491
503
|
});
|
|
492
504
|
});
|
|
493
505
|
it('can specify which reporter to use by function', function () {
|
|
494
|
-
testWriteTo(
|
|
506
|
+
testWriteTo('writeTo-fn', { writeTo: function (id) { return id === 'special'; } }, function (log, memLogs, specialLogs) {
|
|
495
507
|
log.error('error message');
|
|
496
508
|
expect(memLogs.length).toEqual(0);
|
|
497
509
|
expect(specialLogs.length).toEqual(1);
|
|
@@ -499,7 +511,7 @@ describe('getLogger()', function () {
|
|
|
499
511
|
});
|
|
500
512
|
it('can specify custom reporter', function () {
|
|
501
513
|
var reporter = (0, memory_js_1.createMemoryLogReporter)({ id: 'custom mem' });
|
|
502
|
-
testWriteTo(
|
|
514
|
+
testWriteTo('writeTo-reporter', { writeTo: reporter }, function (log, memLogs, specialLogs) {
|
|
503
515
|
log.error('error message');
|
|
504
516
|
expect(memLogs.length).toEqual(0);
|
|
505
517
|
expect(specialLogs.length).toEqual(0);
|
|
@@ -510,8 +522,8 @@ describe('getLogger()', function () {
|
|
|
510
522
|
// if not, it would be a security issue as the new reporter
|
|
511
523
|
// can capture the logs from other logger and send it elsewhere
|
|
512
524
|
var reporter = (0, memory_js_1.createMemoryLogReporter)({ id: 'custom mem' });
|
|
513
|
-
testWriteTo(
|
|
514
|
-
var log = sl.getLogger(
|
|
525
|
+
testWriteTo('writeTo-reporter-no-override', { writeTo: reporter }, function (_, memLogs, specialLogs, sl) {
|
|
526
|
+
var log = sl.getLogger('writeTo-reporter-no-override-2');
|
|
515
527
|
log.error('error message');
|
|
516
528
|
expect(reporter.logs.length).toEqual(0);
|
|
517
529
|
});
|
|
@@ -520,29 +532,65 @@ describe('getLogger()', function () {
|
|
|
520
532
|
});
|
|
521
533
|
describe('suppressLogs()', function () {
|
|
522
534
|
test('suppress log', function () {
|
|
523
|
-
var sl = (0,
|
|
524
|
-
var log = sl.getLogger(
|
|
525
|
-
(0,
|
|
535
|
+
var sl = (0, index_js_1.createStandardLogForTest)();
|
|
536
|
+
var log = sl.getLogger('l');
|
|
537
|
+
(0, index_js_1.suppressLogs)(function () {
|
|
526
538
|
log.alert('should not see me');
|
|
527
539
|
}, log);
|
|
528
540
|
expect(sl.reporter.getLogMessageWithLevel()).toBe('');
|
|
529
541
|
});
|
|
530
542
|
test('suppress multiple logs', function () {
|
|
531
|
-
var sl = (0,
|
|
532
|
-
var log1 = sl.getLogger(
|
|
533
|
-
var log2 = sl.getLogger(
|
|
534
|
-
(0,
|
|
543
|
+
var sl = (0, index_js_1.createStandardLogForTest)();
|
|
544
|
+
var log1 = sl.getLogger('l1');
|
|
545
|
+
var log2 = sl.getLogger('l2');
|
|
546
|
+
(0, index_js_1.suppressLogs)(function () {
|
|
535
547
|
log1.alert('should not see me');
|
|
536
548
|
log2.alert('should not see me too');
|
|
537
549
|
}, log1, log2);
|
|
538
550
|
expect(sl.reporter.getLogMessageWithLevel()).toBe('');
|
|
539
551
|
});
|
|
540
552
|
test('return block result', function () {
|
|
541
|
-
var sl = (0,
|
|
542
|
-
var log1 = sl.getLogger(
|
|
543
|
-
var log2 = sl.getLogger(
|
|
544
|
-
var a = (0,
|
|
553
|
+
var sl = (0, index_js_1.createStandardLogForTest)();
|
|
554
|
+
var log1 = sl.getLogger('l');
|
|
555
|
+
var log2 = sl.getLogger('l2');
|
|
556
|
+
var a = (0, index_js_1.suppressLogs)(function () { return 1; }, log1, log2);
|
|
545
557
|
expect(a).toBe(1);
|
|
546
558
|
});
|
|
547
559
|
});
|
|
560
|
+
describe('getLogger()', function () {
|
|
561
|
+
it('gets a logger that logs to console by default', function () {
|
|
562
|
+
var log = (0, index_js_1.getLogger)('default');
|
|
563
|
+
log.info('from global log, expected to be printed');
|
|
564
|
+
log.debug('from global log, this should not be printed');
|
|
565
|
+
});
|
|
566
|
+
});
|
|
567
|
+
describe('configGlobal()', function () {
|
|
568
|
+
beforeEach(function () {
|
|
569
|
+
standardLog_js_1.ctx.gsl = undefined;
|
|
570
|
+
standardLog_js_1.ctx.configured = false;
|
|
571
|
+
});
|
|
572
|
+
it('configure the global instance', function () {
|
|
573
|
+
var mem = (0, memory_js_1.createMemoryLogReporter)();
|
|
574
|
+
(0, standardLog_js_1.configGlobal)({ logLevel: logLevels_js_1.logLevels.error, reporters: [mem] });
|
|
575
|
+
var log = (0, index_js_1.getLogger)('default');
|
|
576
|
+
log.error('error message');
|
|
577
|
+
log.info('info message');
|
|
578
|
+
expect(mem.logs.length).toBe(1);
|
|
579
|
+
});
|
|
580
|
+
it('can call after getLogger', function () {
|
|
581
|
+
var log = (0, index_js_1.getLogger)('default');
|
|
582
|
+
log.info('from global log, expected to be printed');
|
|
583
|
+
var mem = (0, memory_js_1.createMemoryLogReporter)();
|
|
584
|
+
(0, standardLog_js_1.configGlobal)({ logLevel: logLevels_js_1.logLevels.error, reporters: [mem] });
|
|
585
|
+
log.error('from global log, expected to be printed');
|
|
586
|
+
log.info('from global log, this should not be printed');
|
|
587
|
+
expect(mem.logs.length).toBe(1);
|
|
588
|
+
});
|
|
589
|
+
it('will emit a warning when called twice', function () {
|
|
590
|
+
var mem = (0, memory_js_1.createMemoryLogReporter)();
|
|
591
|
+
(0, standardLog_js_1.configGlobal)({ reporters: [mem] });
|
|
592
|
+
(0, standardLog_js_1.configGlobal)({ reporters: [] });
|
|
593
|
+
assertron_1.assertron.satisfies(mem.logs, [{ id: 'standard-log', level: logLevels_js_1.logLevels.warn, args: [/being called more than once/] }]);
|
|
594
|
+
});
|
|
595
|
+
});
|
|
548
596
|
//# sourceMappingURL=standardLog.spec.js.map
|