nightingale-logger 12.1.4 → 13.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -3,6 +3,36 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ # [13.0.0](https://github.com/christophehurpeau/nightingale/compare/v12.1.4...v13.0.0) (2022-11-19)
7
+
8
+
9
+ ### Bug Fixes
10
+
11
+ * fix node global declaration ([ab5100b](https://github.com/christophehurpeau/nightingale/commit/ab5100b9d63718b18c4f97c9a8d73907be325fe8))
12
+ * **nightingale-logger:** add explicit error message when trying to extends undefined context ([1346bd5](https://github.com/christophehurpeau/nightingale/commit/1346bd5a70ca3df9e87c5a84154bd4b6d58217b4))
13
+
14
+
15
+ ### Code Refactoring
16
+
17
+ * drop node 14 and cjs ([9a8ca06](https://github.com/christophehurpeau/nightingale/commit/9a8ca064449ddc0d69e26543e21c2d522536c50a))
18
+
19
+
20
+ ### Features
21
+
22
+ * build for node 16 ([30ae3e9](https://github.com/christophehurpeau/nightingale/commit/30ae3e9c455dbad793c2f704b9d860069dc80c32))
23
+ * **nightingale-sentry:** update to v7 ([0188b65](https://github.com/christophehurpeau/nightingale/commit/0188b65014dcc4a492d9b868e86fb08ee0954b87))
24
+
25
+
26
+ ### BREAKING CHANGES
27
+
28
+ * dropped node 14 and cjs
29
+ * **nightingale-sentry:** remove deprecated token passed in constructor. Use Sentry object instead and init in the app.
30
+ * drop node 14
31
+
32
+
33
+
34
+
35
+
6
36
  ## [12.1.4](https://github.com/christophehurpeau/nightingale/compare/v12.1.3...v12.1.4) (2022-02-05)
7
37
 
8
38
 
package/README.md CHANGED
@@ -8,6 +8,10 @@
8
8
 
9
9
  <p align="center">
10
10
  <a href="https://npmjs.org/package/nightingale-logger"><img src="https://img.shields.io/npm/v/nightingale-logger.svg?style=flat-square"></a>
11
+ <a href="https://npmjs.org/package/nightingale-logger"><img src="https://img.shields.io/npm/dw/nightingale-logger.svg?style=flat-square"></a>
12
+ <a href="https://npmjs.org/package/nightingale-logger"><img src="https://img.shields.io/node/v/nightingale-logger.svg?style=flat-square"></a>
13
+ <a href="https://npmjs.org/package/nightingale-logger"><img src="https://img.shields.io/npm/types/nightingale-logger.svg?style=flat-square"></a>
14
+ <a href="https://codecov.io/gh/christophehurpeau/nightingale"><img src="https://img.shields.io/codecov/c/github/christophehurpeau/nightingale/master.svg?style=flat-square"></a>
11
15
  </p>
12
16
 
13
17
  ## nightingale
@@ -1,6 +1,5 @@
1
1
  import { Level } from 'nightingale-levels';
2
2
  import type { Metadata, MetadataStyles, Styles, Handler, Processor, LogRecord } from 'nightingale-types';
3
- import 'pob-babel';
4
3
  export { Level } from 'nightingale-levels';
5
4
  export interface Options<T extends Metadata> {
6
5
  symbol?: string;
@@ -11,7 +10,7 @@ export interface ComputedConfigForKey {
11
10
  handlers: Handler[];
12
11
  processors: Processor[];
13
12
  }
14
- interface ExtendedFunctionNameMetadata {
13
+ export interface ExtendedFunctionNameMetadata {
15
14
  functionName: string;
16
15
  }
17
16
  export interface Config {
@@ -25,16 +24,12 @@ export interface Config {
25
24
  stop?: boolean;
26
25
  }
27
26
  declare global {
28
- namespace NodeJS {
29
- interface Global {
30
- __NIGHTINGALE_CONFIG: Config[];
31
- __NIGHTINGALE_LOGGER_MAP_CACHE: Map<string, ComputedConfigForKey>;
32
- __NIGHTINGALE_CONFIG_DEFAULT: ComputedConfigForKey;
33
- __NIGHTINGALE_GLOBAL_HANDLERS: unknown;
34
- __NIGHTINGALE_GET_CONFIG_FOR_LOGGER: (key: string) => ComputedConfigForKey;
35
- __NIGHTINGALE_GET_CONFIG_FOR_LOGGER_RECORD: (key: string, level: number) => ComputedConfigForKey;
36
- }
37
- }
27
+ var __NIGHTINGALE_CONFIG: Config[];
28
+ var __NIGHTINGALE_LOGGER_MAP_CACHE: Map<string, ComputedConfigForKey>;
29
+ var __NIGHTINGALE_CONFIG_DEFAULT: ComputedConfigForKey;
30
+ var __NIGHTINGALE_GLOBAL_HANDLERS: unknown;
31
+ var __NIGHTINGALE_GET_CONFIG_FOR_LOGGER: (key: string) => ComputedConfigForKey;
32
+ var __NIGHTINGALE_GET_CONFIG_FOR_LOGGER_RECORD: (key: string, level: number) => ComputedConfigForKey;
38
33
  }
39
34
  /**
40
35
  * Interface that allows you to log records.
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAC3C,OAAO,KAAK,EACV,QAAQ,EACR,cAAc,EACd,MAAM,EACN,OAAO,EACP,SAAS,EACT,SAAS,EACV,MAAM,mBAAmB,CAAC;AAE3B,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAE3C,MAAM,WAAW,OAAO,CAAC,CAAC,SAAS,QAAQ;IACzC,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,cAAc,CAAC,EAAE,cAAc,CAAC,CAAC,CAAC,CAAC;IACnC,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,oBAAoB;IACnC,QAAQ,EAAE,OAAO,EAAE,CAAC;IACpB,UAAU,EAAE,SAAS,EAAE,CAAC;CACzB;AAED,MAAM,WAAW,4BAA4B;IAC3C,YAAY,EAAE,MAAM,CAAC;CACtB;AAED,MAAM,WAAW,MAAM;IACrB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,QAAQ,CAAC,EAAE,OAAO,EAAE,CAAC;IACrB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,IAAI,CAAC,EAAE,MAAM,EAAE,CAAC;IAChB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,SAAS,CAAC,EAAE,SAAS,CAAC;IACtB,UAAU,CAAC,EAAE,SAAS,EAAE,CAAC;IACzB,IAAI,CAAC,EAAE,OAAO,CAAC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;IACH,IAAI,CAAC,EAAE,SAAS,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,OAAO,EAC7C,EAAE,EAAE,EAAE,EACN,QAAQ,EAAE,MAAM,IAAI,GACnB,IAAI;IAEP,IAAI,CAAC,CAAC,SAAS,QAAQ,EAAE,EAAE,SAAS,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,OAAO,EACjE,EAAE,EAAE,EAAE,EACN,QAAQ,EAAE,CAAC,EACX,QAAQ,EAAE,MAAM,IAAI,GACnB,IAAI;IAEP,IAAI,CAAC,CAAC,SAAS,QAAQ,EAAE,EAAE,SAAS,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,OAAO,EACjE,EAAE,EAAE,EAAE,EACN,QAAQ,EAAE,CAAC,EACX,cAAc,EAAE,cAAc,CAAC,CAAC,CAAC,EACjC,QAAQ,EAAE,MAAM,IAAI,GACnB,IAAI;CA2BR"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=index.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.test.d.ts","sourceRoot":"","sources":["../../src/index.test.ts"],"names":[],"mappings":""}
@@ -3,7 +3,6 @@ import { Level } from 'nightingale-levels';
3
3
  export { Level } from 'nightingale-levels';
4
4
 
5
5
  var globalOrWindow = typeof global !== 'undefined' ? global : window;
6
-
7
6
  if (!globalOrWindow.__NIGHTINGALE_GET_CONFIG_FOR_LOGGER) {
8
7
  globalOrWindow.__NIGHTINGALE_GET_CONFIG_FOR_LOGGER = function () {
9
8
  return {
@@ -12,13 +11,11 @@ if (!globalOrWindow.__NIGHTINGALE_GET_CONFIG_FOR_LOGGER) {
12
11
  };
13
12
  };
14
13
  }
15
-
16
14
  if (!globalOrWindow.__NIGHTINGALE_GET_CONFIG_FOR_LOGGER_RECORD) {
17
15
  globalOrWindow.__NIGHTINGALE_GET_CONFIG_FOR_LOGGER_RECORD = function (key, level) {
18
16
  var _globalOrWindow$__NIG = globalOrWindow.__NIGHTINGALE_GET_CONFIG_FOR_LOGGER(key),
19
- handlers = _globalOrWindow$__NIG.handlers,
20
- processors = _globalOrWindow$__NIG.processors;
21
-
17
+ handlers = _globalOrWindow$__NIG.handlers,
18
+ processors = _globalOrWindow$__NIG.processors;
22
19
  return {
23
20
  handlers: handlers.filter(function (handler) {
24
21
  return level >= handler.minLevel && (!handler.isHandling || handler.isHandling(level, key));
@@ -27,22 +24,17 @@ if (!globalOrWindow.__NIGHTINGALE_GET_CONFIG_FOR_LOGGER_RECORD) {
27
24
  };
28
25
  };
29
26
  }
30
- /** @private */
31
-
32
-
33
27
  function getConfigForLoggerRecord(key, recordLevel) {
34
28
  return globalOrWindow.__NIGHTINGALE_GET_CONFIG_FOR_LOGGER_RECORD(key, recordLevel);
35
29
  }
36
-
37
30
  function isError(messageOrError) {
38
31
  return messageOrError instanceof Error;
39
32
  }
33
+
40
34
  /**
41
35
  * Interface that allows you to log records.
42
36
  * This records are treated by handlers
43
37
  */
44
-
45
-
46
38
  var Logger = /*#__PURE__*/function () {
47
39
  /**
48
40
  * Create a new Logger
@@ -53,33 +45,29 @@ var Logger = /*#__PURE__*/function () {
53
45
  function Logger(key, displayName) {
54
46
  this.key = key;
55
47
  this.displayName = displayName;
56
-
57
- if ((process.env.NODE_ENV !== "production") && key.includes('.')) {
48
+ if (process.env.NODE_ENV !== "production" && key.includes('.')) {
58
49
  throw new Error("nightingale: `.` in key is no longer supported, use `:` instead (key: " + key + ")");
59
50
  }
60
51
  }
61
- /** @private */
62
-
63
52
 
53
+ /** @private */
64
54
  var _proto = Logger.prototype;
65
-
66
55
  _proto.getHandlersAndProcessors = function getHandlersAndProcessors(recordLevel) {
67
56
  return getConfigForLoggerRecord(this.key, recordLevel);
68
57
  }
69
- /** @private */
70
- ;
71
58
 
59
+ /** @private */;
72
60
  _proto.getConfig = function getConfig() {
73
61
  return globalOrWindow.__NIGHTINGALE_GET_CONFIG_FOR_LOGGER(this.key);
74
62
  }
63
+
75
64
  /**
76
65
  * Create a child logger
77
- */
78
- ;
79
-
66
+ */;
80
67
  _proto.child = function child(childSuffixKey, childDisplayName) {
81
68
  return new Logger(this.key + ":" + childSuffixKey, childDisplayName);
82
69
  }
70
+
83
71
  /**
84
72
  * Create a new Logger with the same key a this attached context
85
73
  *
@@ -96,52 +84,48 @@ var Logger = /*#__PURE__*/function () {
96
84
  * }
97
85
  * ```
98
86
  *
99
- */
100
- ;
101
-
87
+ */;
102
88
  _proto.context = function context(_context) {
103
89
  var logger = new Logger(this.key);
104
90
  logger.setContext(_context);
105
91
  return logger;
106
92
  }
93
+
107
94
  /**
108
95
  * Get the context of this logger
109
- */
110
- ;
111
-
96
+ */;
112
97
  _proto.getContextObject = function getContextObject() {
113
98
  return this.contextObject;
114
99
  }
100
+
115
101
  /**
116
102
  * Set the context of this logger
117
103
  *
118
104
  * @param {Object} context
119
- */
120
- ;
121
-
105
+ */;
122
106
  _proto.setContext = function setContext(context) {
123
107
  this.contextObject = context;
124
108
  }
109
+
125
110
  /**
126
111
  * Extends existing context of this logger
127
- */
128
- ;
129
-
112
+ */;
130
113
  _proto.extendsContext = function extendsContext(extendedContext) {
114
+ if (this.contextObject === undefined) {
115
+ throw new Error('Cannot extends context that does not exists. Use setContext(context) first.');
116
+ }
131
117
  Object.assign(this.contextObject, extendedContext);
132
118
  }
119
+
133
120
  /**
134
121
  * Handle a record
135
122
  *
136
123
  * Use this only if you know what you are doing.
137
- */
138
- ;
139
-
124
+ */;
140
125
  _proto.addRecord = function addRecord(record) {
141
126
  var _this$getHandlersAndP = this.getHandlersAndProcessors(record.level),
142
- handlers = _this$getHandlersAndP.handlers,
143
- processors = _this$getHandlersAndP.processors;
144
-
127
+ handlers = _this$getHandlersAndP.handlers,
128
+ processors = _this$getHandlersAndP.processors;
145
129
  if (handlers.length === 0) {
146
130
  if (record.level > Level.ERROR) {
147
131
  // eslint-disable-next-line no-console
@@ -150,41 +134,34 @@ var Logger = /*#__PURE__*/function () {
150
134
  message: record.message
151
135
  });
152
136
  }
153
-
154
137
  return;
155
138
  }
156
-
157
139
  if (processors) {
158
140
  processors.forEach(function (process) {
159
141
  process(record, record.context);
160
142
  });
161
143
  }
162
-
163
144
  handlers.some(function (handler) {
164
145
  return handler.handle(record) === false;
165
146
  });
166
147
  }
148
+
167
149
  /**
168
150
  * Log a message
169
- */
170
- ;
171
-
151
+ */;
172
152
  _proto.log = function log(messageOrError, metadata, level, options) {
173
153
  if (level === void 0) {
174
154
  level = Level.INFO;
175
155
  }
176
-
177
156
  var isMessageError = isError(messageOrError);
178
157
  var message = isMessageError ? messageOrError.name + ": " + messageOrError.message : messageOrError;
179
158
  var extendedMetadata = isMessageError && !(metadata && Object.prototype.hasOwnProperty.call(metadata, 'error')) ? _extends({}, metadata, {
180
159
  error: messageOrError
181
160
  }) : metadata;
182
161
  var context = extendedMetadata == null ? void 0 : extendedMetadata.context;
183
-
184
162
  if (extendedMetadata) {
185
163
  delete extendedMetadata.context;
186
164
  }
187
-
188
165
  var record = _extends({
189
166
  level: level,
190
167
  key: this.key,
@@ -195,59 +172,54 @@ var Logger = /*#__PURE__*/function () {
195
172
  metadata: extendedMetadata,
196
173
  extra: {}
197
174
  }, options);
198
-
199
175
  this.addRecord(record);
200
176
  }
177
+
201
178
  /**
202
179
  * Log a trace message
203
- */
204
- ;
205
-
180
+ */;
206
181
  _proto.trace = function trace(messageOrError, metadata, metadataStyles) {
207
182
  this.log(messageOrError, metadata, Level.TRACE, {
208
183
  metadataStyles: metadataStyles
209
184
  });
210
185
  }
186
+
211
187
  /**
212
188
  * Log a debug message
213
- */
214
- ;
215
-
189
+ */;
216
190
  _proto.debug = function debug(messageOrError, metadata, metadataStyles) {
217
191
  this.log(messageOrError, metadata, Level.DEBUG, {
218
192
  metadataStyles: metadataStyles
219
193
  });
220
194
  }
195
+
221
196
  /**
222
197
  * Notice an info message
223
- */
224
- ;
225
-
198
+ */;
226
199
  _proto.notice = function notice(messageOrError, metadata, metadataStyles) {
227
200
  this.log(messageOrError, metadata, Level.NOTICE, {
228
201
  metadataStyles: metadataStyles
229
202
  });
230
203
  }
204
+
231
205
  /**
232
206
  * Log an info message
233
- */
234
- ;
235
-
207
+ */;
236
208
  _proto.info = function info(messageOrError, metadata, metadataStyles) {
237
209
  this.log(messageOrError, metadata, Level.INFO, {
238
210
  metadataStyles: metadataStyles
239
211
  });
240
212
  }
213
+
241
214
  /**
242
215
  * Log a warn message
243
- */
244
- ;
245
-
216
+ */;
246
217
  _proto.warn = function warn(messageOrError, metadata, metadataStyles) {
247
218
  this.log(messageOrError, metadata, Level.WARN, {
248
219
  metadataStyles: metadataStyles
249
220
  });
250
221
  }
222
+
251
223
  /**
252
224
  * Log an error message
253
225
  *
@@ -260,24 +232,22 @@ var Logger = /*#__PURE__*/function () {
260
232
  * logger.error('caught error', { error });
261
233
  * }
262
234
  * ```
263
- */
264
- ;
265
-
235
+ */;
266
236
  _proto.error = function error(messageOrError, metadata, metadataStyles) {
267
237
  this.log(messageOrError, metadata, Level.ERROR, {
268
238
  metadataStyles: metadataStyles
269
239
  });
270
240
  }
241
+
271
242
  /**
272
243
  * Log an critical message
273
- */
274
- ;
275
-
244
+ */;
276
245
  _proto.critical = function critical(messageOrError, metadata, metadataStyles) {
277
246
  this.log(messageOrError, metadata, Level.CRITICAL, {
278
247
  metadataStyles: metadataStyles
279
248
  });
280
249
  }
250
+
281
251
  /**
282
252
  * Log a fatal message
283
253
  *
@@ -290,53 +260,46 @@ var Logger = /*#__PURE__*/function () {
290
260
  * logger.error('caught error', { error });
291
261
  * process.exit(1);
292
262
  * }
293
- */
294
- ;
295
-
263
+ */;
296
264
  _proto.fatal = function fatal(messageOrError, metadata, metadataStyles) {
297
265
  this.log(messageOrError, metadata, Level.FATAL, {
298
266
  metadataStyles: metadataStyles
299
267
  });
300
268
  }
269
+
301
270
  /**
302
271
  * Log an alert message
303
- */
304
- ;
305
-
272
+ */;
306
273
  _proto.alert = function alert(messageOrError, metadata, metadataStyles) {
307
274
  this.log(messageOrError, metadata, Level.ALERT, {
308
275
  metadataStyles: metadataStyles
309
276
  });
310
277
  }
278
+
311
279
  /**
312
280
  * Log an inspected value
313
- */
314
- ;
315
-
281
+ */;
316
282
  _proto.inspectValue = function inspectValue() {
317
283
  throw new Error('Not supported for the browser. Prefer `debugger;`');
318
284
  }
285
+
319
286
  /**
320
287
  * Log a debugged var
321
- */
322
- ;
323
-
288
+ */;
324
289
  _proto.inspectVar = function inspectVar() {
325
290
  throw new Error('Not supported for the browser. Prefer `debugger;`');
326
291
  }
292
+
327
293
  /**
328
294
  * Alias for infoSuccess
329
- */
330
- ;
331
-
295
+ */;
332
296
  _proto.success = function success(message, metadata, metadataStyles) {
333
297
  this.infoSuccess(message, metadata, metadataStyles);
334
298
  }
299
+
335
300
  /**
336
301
  * Log an info success message
337
- */
338
- ;
339
-
302
+ */;
340
303
  _proto.infoSuccess = function infoSuccess(message, metadata, metadataStyles) {
341
304
  this.log(message, metadata, Level.INFO, {
342
305
  metadataStyles: metadataStyles,
@@ -344,11 +307,10 @@ var Logger = /*#__PURE__*/function () {
344
307
  styles: ['green', 'bold']
345
308
  });
346
309
  }
310
+
347
311
  /**
348
312
  * Log an debug success message
349
- */
350
- ;
351
-
313
+ */;
352
314
  _proto.debugSuccess = function debugSuccess(message, metadata, metadataStyles) {
353
315
  this.log(message, metadata, Level.DEBUG, {
354
316
  metadataStyles: metadataStyles,
@@ -356,19 +318,17 @@ var Logger = /*#__PURE__*/function () {
356
318
  styles: ['green']
357
319
  });
358
320
  }
321
+
359
322
  /**
360
323
  * Alias for infoFail
361
- */
362
- ;
363
-
324
+ */;
364
325
  _proto.fail = function fail(messageOrError, metadata, metadataStyles) {
365
326
  this.infoFail(messageOrError, metadata, metadataStyles);
366
327
  }
328
+
367
329
  /**
368
330
  * Log an info fail message
369
- */
370
- ;
371
-
331
+ */;
372
332
  _proto.infoFail = function infoFail(messageOrError, metadata, metadataStyles) {
373
333
  this.log(messageOrError, metadata, Level.INFO, {
374
334
  metadataStyles: metadataStyles,
@@ -376,11 +336,10 @@ var Logger = /*#__PURE__*/function () {
376
336
  styles: ['red', 'bold']
377
337
  });
378
338
  }
339
+
379
340
  /**
380
341
  * Log an debug fail message
381
- */
382
- ;
383
-
342
+ */;
384
343
  _proto.debugFail = function debugFail(messageOrError, metadata, metadataStyles) {
385
344
  this.log(messageOrError, metadata, Level.DEBUG, {
386
345
  metadataStyles: metadataStyles,
@@ -388,80 +347,70 @@ var Logger = /*#__PURE__*/function () {
388
347
  styles: ['red']
389
348
  });
390
349
  }
350
+
391
351
  /**
392
352
  * @returns {number} time to pass to timeEnd
393
- */
394
- ;
395
-
353
+ */;
396
354
  _proto.time = function time(message, metadata, metadataStyles, level) {
397
355
  if (level === void 0) {
398
356
  level = Level.DEBUG;
399
357
  }
400
-
401
358
  if (message) {
402
359
  this.log(message, metadata, level, {
403
360
  metadataStyles: metadataStyles
404
361
  });
405
362
  }
406
-
407
363
  return Date.now();
408
364
  };
409
-
410
365
  _proto.infoTime = function infoTime(message, metadata, metadataStyles) {
411
366
  return this.time(message, metadata, metadataStyles, Level.INFO);
412
367
  }
368
+
413
369
  /**
414
370
  * Finds difference between when this method
415
371
  * was called and when the respective time method
416
372
  * was called, then logs out the difference
417
373
  * and deletes the original record
418
- */
419
- ;
420
-
374
+ */;
421
375
  _proto.timeEnd = function timeEnd(startTime, message, metadata, metadataStyles, level, options) {
422
376
  if (level === void 0) {
423
377
  level = Level.DEBUG;
424
378
  }
425
-
426
379
  var now = Date.now();
427
380
  var diffTime = now - startTime;
428
381
  var readableTime;
429
-
430
382
  if (diffTime < 1000) {
431
383
  readableTime = diffTime + "ms";
432
384
  } else {
433
385
  var seconds = diffTime > 1000 ? Math.floor(diffTime / 1000) : 0;
434
386
  readableTime = "" + (seconds ? seconds + "s and " : '') + (diffTime - seconds * 1000) + "ms";
435
387
  }
436
-
437
388
  var extendedMetadata = _extends({}, metadata, {
438
389
  readableTime: readableTime,
439
390
  timeMs: diffTime
440
391
  });
441
-
442
392
  this.log(message, extendedMetadata, level, _extends({}, options, {
443
393
  metadataStyles: metadataStyles
444
394
  }));
445
395
  }
396
+
446
397
  /**
447
398
  * Like timeEnd, but with INFO level
448
- */
449
- ;
450
-
399
+ */;
451
400
  _proto.infoTimeEnd = function infoTimeEnd(time, message, metadata, metadataStyles) {
452
401
  this.timeEnd(time, message, metadata, metadataStyles, Level.INFO);
453
402
  }
403
+
454
404
  /**
455
405
  * Like timeEnd, but with INFO level
456
- */
457
- ;
458
-
406
+ */;
459
407
  _proto.infoSuccessTimeEnd = function infoSuccessTimeEnd(time, message, metadata, metadataStyles) {
460
408
  this.timeEnd(time, message, metadata, metadataStyles, Level.INFO, {
461
409
  symbol: '✔',
462
410
  styles: ['green', 'bold']
463
411
  });
464
412
  }
413
+
465
414
  /**
466
415
  * Log an enter in a function
467
416
  *
@@ -475,18 +424,16 @@ var Logger = /*#__PURE__*/function () {
475
424
  * }
476
425
  * ```
477
426
  *
478
- */
479
- ;
480
-
427
+ */;
481
428
  _proto.enter = function enter(fn, metadata, metadataStyles) {
482
429
  var extendedMetadata = _extends({}, metadata, {
483
430
  functionName: fn.name
484
431
  });
485
-
486
432
  this.log('enter', extendedMetadata, Level.TRACE, {
487
433
  metadataStyles: metadataStyles
488
434
  });
489
435
  }
436
+
490
437
  /**
491
438
  * Log an exit in a function
492
439
  *
@@ -500,18 +447,16 @@ var Logger = /*#__PURE__*/function () {
500
447
  * }
501
448
  * }
502
449
  * ```
503
- */
504
- ;
505
-
450
+ */;
506
451
  _proto.exit = function exit(fn, metadata, metadataStyles) {
507
452
  var extendedMetadata = _extends({}, metadata, {
508
453
  functionName: fn.name
509
454
  });
510
-
511
455
  this.log('exit', extendedMetadata, Level.TRACE, {
512
456
  metadataStyles: metadataStyles
513
457
  });
514
458
  }
459
+
515
460
  /**
516
461
  * Wrap around a function to log enter and exit of a function
517
462
  *
@@ -526,30 +471,24 @@ var Logger = /*#__PURE__*/function () {
526
471
  * }
527
472
  * }
528
473
  * ```
529
- */
530
- ;
531
-
474
+ */;
532
475
  _proto.wrap = function wrap(fn, option1, option2, callback) {
533
476
  var metadata;
534
477
  var metadataStyles;
535
-
536
478
  if (typeof option1 === 'function') {
537
479
  callback = option1;
538
480
  } else {
539
481
  metadata = option1;
540
-
541
482
  if (typeof option2 === 'function') {
542
483
  callback = option2;
543
484
  } else {
544
485
  metadataStyles = option2;
545
486
  }
546
487
  }
547
-
548
488
  this.enter(fn, metadata, metadataStyles);
549
489
  callback();
550
490
  this.exit(fn);
551
491
  };
552
-
553
492
  return Logger;
554
493
  }();
555
494