1 | "use strict";
|
---|
2 | /**
|
---|
3 | * @license
|
---|
4 | * Copyright Google LLC All Rights Reserved.
|
---|
5 | *
|
---|
6 | * Use of this source code is governed by an MIT-style license that can be
|
---|
7 | * found in the LICENSE file at https://angular.io/license
|
---|
8 | */
|
---|
9 | Object.defineProperty(exports, "__esModule", { value: true });
|
---|
10 | exports.IndentLogger = void 0;
|
---|
11 | const operators_1 = require("rxjs/operators");
|
---|
12 | const logger_1 = require("./logger");
|
---|
13 | /**
|
---|
14 | * Keep an map of indentation => array of indentations based on the level.
|
---|
15 | * This is to optimize calculating the prefix based on the indentation itself. Since most logs
|
---|
16 | * come from similar levels, and with similar indentation strings, this will be shared by all
|
---|
17 | * loggers. Also, string concatenation is expensive so performing concats for every log entries
|
---|
18 | * is expensive; this alleviates it.
|
---|
19 | */
|
---|
20 | const indentationMap = {};
|
---|
21 | class IndentLogger extends logger_1.Logger {
|
---|
22 | constructor(name, parent = null, indentation = ' ') {
|
---|
23 | super(name, parent);
|
---|
24 | indentationMap[indentation] = indentationMap[indentation] || [''];
|
---|
25 | const indentMap = indentationMap[indentation];
|
---|
26 | this._observable = this._observable.pipe(operators_1.map((entry) => {
|
---|
27 | const l = entry.path.filter((x) => !!x).length;
|
---|
28 | if (l >= indentMap.length) {
|
---|
29 | let current = indentMap[indentMap.length - 1];
|
---|
30 | while (l >= indentMap.length) {
|
---|
31 | current += indentation;
|
---|
32 | indentMap.push(current);
|
---|
33 | }
|
---|
34 | }
|
---|
35 | entry.message = indentMap[l] + entry.message.split(/\n/).join('\n' + indentMap[l]);
|
---|
36 | return entry;
|
---|
37 | }));
|
---|
38 | }
|
---|
39 | }
|
---|
40 | exports.IndentLogger = IndentLogger;
|
---|