@appium/logger 1.3.0 → 1.4.1
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 +20 -0
- package/LICENSE +18 -201
- package/build/lib/log.d.ts +21 -1
- package/build/lib/log.d.ts.map +1 -1
- package/build/lib/log.js +35 -3
- package/build/lib/log.js.map +1 -1
- package/build/lib/secure-values-preprocessor.d.ts +40 -0
- package/build/lib/secure-values-preprocessor.d.ts.map +1 -0
- package/build/lib/secure-values-preprocessor.js +138 -0
- package/build/lib/secure-values-preprocessor.js.map +1 -0
- package/build/lib/types.d.ts +56 -1
- package/build/lib/types.d.ts.map +1 -1
- package/build/lib/utils.d.ts +10 -0
- package/build/lib/utils.d.ts.map +1 -0
- package/build/lib/utils.js +16 -0
- package/build/lib/utils.js.map +1 -0
- package/lib/log.ts +51 -5
- package/lib/secure-values-preprocessor.ts +149 -0
- package/lib/types.ts +63 -0
- package/lib/utils.ts +11 -0
- package/package.json +4 -3
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,26 @@
|
|
|
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
|
+
## [1.4.1](https://github.com/appium/appium/compare/@appium/logger@1.4.0...@appium/logger@1.4.1) (2024-06-11)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Bug Fixes
|
|
10
|
+
|
|
11
|
+
* **logger:** Type declaration for DEFAULT_LOG_LEVELS ([#20244](https://github.com/appium/appium/issues/20244)) ([c670010](https://github.com/appium/appium/commit/c670010ec7ea1c2730839e86b308837a83fc026e))
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
## [1.4.0](https://github.com/appium/appium/compare/@appium/logger@1.3.0...@appium/logger@1.4.0) (2024-06-10)
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
### Features
|
|
19
|
+
|
|
20
|
+
* **appium:** Add session signature to all logs ([#20202](https://github.com/appium/appium/issues/20202)) ([#20214](https://github.com/appium/appium/issues/20214)) ([0363aab](https://github.com/appium/appium/commit/0363aab8ba4fe0ec49845db2f493001aa873578b)), closes [#20222](https://github.com/appium/appium/issues/20222)
|
|
21
|
+
* **logger:** Add the debug level to the default logger ([#20219](https://github.com/appium/appium/issues/20219)) ([8ee7d07](https://github.com/appium/appium/commit/8ee7d07af4e2375d2eb7c23badaaac34685bc59c))
|
|
22
|
+
* **support:** Move SecureValuesPreprocessor to @appum/logger ([#20228](https://github.com/appium/appium/issues/20228)) ([dbc3b66](https://github.com/appium/appium/commit/dbc3b668a0a7a815d23f1cae4207d435fc09034d))
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
|
|
6
26
|
## [1.3.0](https://github.com/appium/appium/compare/@appium/logger@1.2.0...@appium/logger@1.3.0) (2024-06-06)
|
|
7
27
|
|
|
8
28
|
|
package/LICENSE
CHANGED
|
@@ -1,201 +1,18 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
direction or management of such entity, whether by contract or
|
|
20
|
-
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
-
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
-
|
|
23
|
-
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
-
exercising permissions granted by this License.
|
|
25
|
-
|
|
26
|
-
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
-
including but not limited to software source code, documentation
|
|
28
|
-
source, and configuration files.
|
|
29
|
-
|
|
30
|
-
"Object" form shall mean any form resulting from mechanical
|
|
31
|
-
transformation or translation of a Source form, including but
|
|
32
|
-
not limited to compiled object code, generated documentation,
|
|
33
|
-
and conversions to other media types.
|
|
34
|
-
|
|
35
|
-
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
-
Object form, made available under the License, as indicated by a
|
|
37
|
-
copyright notice that is included in or attached to the work
|
|
38
|
-
(an example is provided in the Appendix below).
|
|
39
|
-
|
|
40
|
-
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
-
form, that is based on (or derived from) the Work and for which the
|
|
42
|
-
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
-
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
-
of this License, Derivative Works shall not include works that remain
|
|
45
|
-
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
-
the Work and Derivative Works thereof.
|
|
47
|
-
|
|
48
|
-
"Contribution" shall mean any work of authorship, including
|
|
49
|
-
the original version of the Work and any modifications or additions
|
|
50
|
-
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
-
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
-
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
-
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
-
means any form of electronic, verbal, or written communication sent
|
|
55
|
-
to the Licensor or its representatives, including but not limited to
|
|
56
|
-
communication on electronic mailing lists, source code control systems,
|
|
57
|
-
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
-
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
-
excluding communication that is conspicuously marked or otherwise
|
|
60
|
-
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
-
|
|
62
|
-
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
-
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
-
subsequently incorporated within the Work.
|
|
65
|
-
|
|
66
|
-
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
-
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
-
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
-
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
-
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
-
Work and such Derivative Works in Source or Object form.
|
|
72
|
-
|
|
73
|
-
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
-
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
-
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
-
(except as stated in this section) patent license to make, have made,
|
|
77
|
-
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
-
where such license applies only to those patent claims licensable
|
|
79
|
-
by such Contributor that are necessarily infringed by their
|
|
80
|
-
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
-
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
-
institute patent litigation against any entity (including a
|
|
83
|
-
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
-
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
-
or contributory patent infringement, then any patent licenses
|
|
86
|
-
granted to You under this License for that Work shall terminate
|
|
87
|
-
as of the date such litigation is filed.
|
|
88
|
-
|
|
89
|
-
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
-
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
-
modifications, and in Source or Object form, provided that You
|
|
92
|
-
meet the following conditions:
|
|
93
|
-
|
|
94
|
-
(a) You must give any other recipients of the Work or
|
|
95
|
-
Derivative Works a copy of this License; and
|
|
96
|
-
|
|
97
|
-
(b) You must cause any modified files to carry prominent notices
|
|
98
|
-
stating that You changed the files; and
|
|
99
|
-
|
|
100
|
-
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
-
that You distribute, all copyright, patent, trademark, and
|
|
102
|
-
attribution notices from the Source form of the Work,
|
|
103
|
-
excluding those notices that do not pertain to any part of
|
|
104
|
-
the Derivative Works; and
|
|
105
|
-
|
|
106
|
-
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
-
distribution, then any Derivative Works that You distribute must
|
|
108
|
-
include a readable copy of the attribution notices contained
|
|
109
|
-
within such NOTICE file, excluding those notices that do not
|
|
110
|
-
pertain to any part of the Derivative Works, in at least one
|
|
111
|
-
of the following places: within a NOTICE text file distributed
|
|
112
|
-
as part of the Derivative Works; within the Source form or
|
|
113
|
-
documentation, if provided along with the Derivative Works; or,
|
|
114
|
-
within a display generated by the Derivative Works, if and
|
|
115
|
-
wherever such third-party notices normally appear. The contents
|
|
116
|
-
of the NOTICE file are for informational purposes only and
|
|
117
|
-
do not modify the License. You may add Your own attribution
|
|
118
|
-
notices within Derivative Works that You distribute, alongside
|
|
119
|
-
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
-
that such additional attribution notices cannot be construed
|
|
121
|
-
as modifying the License.
|
|
122
|
-
|
|
123
|
-
You may add Your own copyright statement to Your modifications and
|
|
124
|
-
may provide additional or different license terms and conditions
|
|
125
|
-
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
-
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
-
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
-
the conditions stated in this License.
|
|
129
|
-
|
|
130
|
-
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
-
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
-
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
-
this License, without any additional terms or conditions.
|
|
134
|
-
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
-
the terms of any separate license agreement you may have executed
|
|
136
|
-
with Licensor regarding such Contributions.
|
|
137
|
-
|
|
138
|
-
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
-
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
-
except as required for reasonable and customary use in describing the
|
|
141
|
-
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
-
|
|
143
|
-
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
-
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
-
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
-
implied, including, without limitation, any warranties or conditions
|
|
148
|
-
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
-
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
-
appropriateness of using or redistributing the Work and assume any
|
|
151
|
-
risks associated with Your exercise of permissions under this License.
|
|
152
|
-
|
|
153
|
-
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
-
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
-
unless required by applicable law (such as deliberate and grossly
|
|
156
|
-
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
-
liable to You for damages, including any direct, indirect, special,
|
|
158
|
-
incidental, or consequential damages of any character arising as a
|
|
159
|
-
result of this License or out of the use or inability to use the
|
|
160
|
-
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
-
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
-
other commercial damages or losses), even if such Contributor
|
|
163
|
-
has been advised of the possibility of such damages.
|
|
164
|
-
|
|
165
|
-
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
-
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
-
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
-
or other liability obligations and/or rights consistent with this
|
|
169
|
-
License. However, in accepting such obligations, You may act only
|
|
170
|
-
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
-
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
-
defend, and hold each Contributor harmless for any liability
|
|
173
|
-
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
-
of your accepting any such warranty or additional liability.
|
|
175
|
-
|
|
176
|
-
END OF TERMS AND CONDITIONS
|
|
177
|
-
|
|
178
|
-
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
-
|
|
180
|
-
To apply the Apache License to your work, attach the following
|
|
181
|
-
boilerplate notice, with the fields enclosed by brackets "{}"
|
|
182
|
-
replaced with your own identifying information. (Don't include
|
|
183
|
-
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
-
comment syntax for the file format. We also recommend that a
|
|
185
|
-
file or class name and description of purpose be included on the
|
|
186
|
-
same "printed page" as the copyright notice for easier
|
|
187
|
-
identification within third-party archives.
|
|
188
|
-
|
|
189
|
-
Copyright OpenJS Foundation and other contributors, https://openjsf.org/
|
|
190
|
-
|
|
191
|
-
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
-
you may not use this file except in compliance with the License.
|
|
193
|
-
You may obtain a copy of the License at
|
|
194
|
-
|
|
195
|
-
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
-
|
|
197
|
-
Unless required by applicable law or agreed to in writing, software
|
|
198
|
-
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
-
See the License for the specific language governing permissions and
|
|
201
|
-
limitations under the License.
|
|
1
|
+
ISC License
|
|
2
|
+
|
|
3
|
+
Copyright npm, Inc.
|
|
4
|
+
|
|
5
|
+
Permission to use, copy, modify, and/or distribute this
|
|
6
|
+
software for any purpose with or without fee is hereby
|
|
7
|
+
granted, provided that the above copyright notice and this
|
|
8
|
+
permission notice appear in all copies.
|
|
9
|
+
|
|
10
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND NPM DISCLAIMS ALL
|
|
11
|
+
WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL
|
|
12
|
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO
|
|
13
|
+
EVENT SHALL NPM BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
14
|
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
15
|
+
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
|
|
16
|
+
WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
|
|
17
|
+
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE
|
|
18
|
+
USE OR PERFORMANCE OF THIS SOFTWARE.
|
package/build/lib/log.d.ts
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
/// <reference types="node" />
|
|
3
|
+
/// <reference types="node" />
|
|
3
4
|
import { EventEmitter } from 'node:events';
|
|
4
|
-
import type { MessageObject, StyleObject, Logger, LogLevel } from './types';
|
|
5
|
+
import type { MessageObject, StyleObject, Logger, LogLevel, PreprocessingRulesLoadResult, LogFiltersConfig } from './types';
|
|
5
6
|
import type { Writable } from 'node:stream';
|
|
7
|
+
import { AsyncLocalStorage } from 'node:async_hooks';
|
|
8
|
+
import { SecureValuesPreprocessor } from './secure-values-preprocessor';
|
|
6
9
|
export declare class Log extends EventEmitter implements Logger {
|
|
7
10
|
level: LogLevel | string;
|
|
8
11
|
record: MessageObject[];
|
|
@@ -11,6 +14,7 @@ export declare class Log extends EventEmitter implements Logger {
|
|
|
11
14
|
headingStyle: StyleObject;
|
|
12
15
|
heading: string;
|
|
13
16
|
stream: Writable;
|
|
17
|
+
_asyncStorage: AsyncLocalStorage<Record<string, any>>;
|
|
14
18
|
_colorEnabled?: boolean;
|
|
15
19
|
_buffer: MessageObject[];
|
|
16
20
|
_style: Record<LogLevel | string, StyleObject | undefined>;
|
|
@@ -18,8 +22,10 @@ export declare class Log extends EventEmitter implements Logger {
|
|
|
18
22
|
_disp: Record<LogLevel | string, number | string>;
|
|
19
23
|
_id: number;
|
|
20
24
|
_paused: boolean;
|
|
25
|
+
_secureValuesPreprocessor: SecureValuesPreprocessor;
|
|
21
26
|
constructor();
|
|
22
27
|
private useColor;
|
|
28
|
+
get asyncStorage(): AsyncLocalStorage<Record<string, any>>;
|
|
23
29
|
enableColor(): void;
|
|
24
30
|
disableColor(): void;
|
|
25
31
|
enableUnicode(): void;
|
|
@@ -34,6 +40,7 @@ export declare class Log extends EventEmitter implements Logger {
|
|
|
34
40
|
resume(): void;
|
|
35
41
|
silly(prefix: string, message: any, ...args: any[]): void;
|
|
36
42
|
verbose(prefix: string, message: any, ...args: any[]): void;
|
|
43
|
+
debug(prefix: string, message: any, ...args: any[]): void;
|
|
37
44
|
info(prefix: string, message: any, ...args: any[]): void;
|
|
38
45
|
timing(prefix: string, message: any, ...args: any[]): void;
|
|
39
46
|
http(prefix: string, message: any, ...args: any[]): void;
|
|
@@ -50,6 +57,19 @@ export declare class Log extends EventEmitter implements Logger {
|
|
|
50
57
|
* @param args additional arguments appended to the log message also formatted using utils.format()
|
|
51
58
|
*/
|
|
52
59
|
log(level: LogLevel | string, prefix: string, message: any, ...args: any[]): void;
|
|
60
|
+
/**
|
|
61
|
+
* Loads the JSON file containing secure values replacement rules.
|
|
62
|
+
* This might be necessary to hide sensitive values that may possibly
|
|
63
|
+
* appear in Appium logs.
|
|
64
|
+
* Each call to this method replaces the previously loaded rules if any existed.
|
|
65
|
+
*
|
|
66
|
+
* @param {string|string[]|LogFiltersConfig} rulesJsonPath The full path to the JSON file containing
|
|
67
|
+
* the replacement rules. Each rule could either be a string to be replaced
|
|
68
|
+
* or an object with predefined properties.
|
|
69
|
+
* @throws {Error} If the given file cannot be loaded
|
|
70
|
+
* @returns {Promise<PreprocessingRulesLoadResult>}
|
|
71
|
+
*/
|
|
72
|
+
loadSecureValuesPreprocessingRules(rulesJsonPath: string | string[] | LogFiltersConfig): Promise<PreprocessingRulesLoadResult>;
|
|
53
73
|
private emitLog;
|
|
54
74
|
private _format;
|
|
55
75
|
private write;
|
package/build/lib/log.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"log.d.ts","sourceRoot":"","sources":["../../lib/log.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"log.d.ts","sourceRoot":"","sources":["../../lib/log.ts"],"names":[],"mappings":";;;AACA,OAAO,EAAC,YAAY,EAAC,MAAM,aAAa,CAAC;AAMzC,OAAO,KAAK,EACV,aAAa,EAC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IAI1D,QAAQ,CAAC,KAAK,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,WAAW,EAAE,IAAI,CAAC,EAAE,MAAM,GAAG,IAAI;IAY5E;;;;;;OAMG;IACH,GAAG,CAAC,KAAK,EAAE,QAAQ,GAAG,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,GAAG,EAAE,GAAG,IAAI,EAAE,GAAG,EAAE,GAAG,IAAI;IAgDjF;;;;;;;;;;;OAWG;IACG,kCAAkC,CACtC,aAAa,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,gBAAgB,GAClD,OAAO,CAAC,4BAA4B,CAAC;IAQxC,OAAO,CAAC,OAAO;IAuCf,OAAO,CAAC,OAAO;IAqCf,OAAO,CAAC,KAAK;IAWb,OAAO,CAAC,iBAAiB;IASzB,OAAO,CAAC,aAAa;IACrB,OAAO,CAAC,YAAY;CACrB;AAED,eAAO,MAAM,UAAU,KAAY,CAAC;AACpC,eAAe,UAAU,CAAC"}
|
package/build/lib/log.js
CHANGED
|
@@ -27,15 +27,20 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
27
27
|
};
|
|
28
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
29
|
exports.GLOBAL_LOG = exports.Log = void 0;
|
|
30
|
+
const lodash_1 = __importDefault(require("lodash"));
|
|
30
31
|
const node_events_1 = require("node:events");
|
|
31
32
|
// @ts-ignore This module does not provide type definitons
|
|
32
33
|
const set_blocking_1 = __importDefault(require("set-blocking"));
|
|
33
34
|
// @ts-ignore This module does not provide type definitons
|
|
34
35
|
const console_control_strings_1 = __importDefault(require("console-control-strings"));
|
|
35
36
|
const util = __importStar(require("node:util"));
|
|
37
|
+
const node_async_hooks_1 = require("node:async_hooks");
|
|
38
|
+
const utils_1 = require("./utils");
|
|
39
|
+
const secure_values_preprocessor_1 = require("./secure-values-preprocessor");
|
|
36
40
|
const DEFAULT_LOG_LEVELS = [
|
|
37
41
|
['silly', -Infinity, { inverse: true }, 'sill'],
|
|
38
42
|
['verbose', 1000, { fg: 'cyan', bg: 'black' }, 'verb'],
|
|
43
|
+
['debug', 1500, { fg: 'cyan', bg: 'black' }, 'dbug'],
|
|
39
44
|
['info', 2000, { fg: 'green' }],
|
|
40
45
|
['timing', 2500, { fg: 'green', bg: 'black' }],
|
|
41
46
|
['http', 3000, { fg: 'green', bg: 'black' }],
|
|
@@ -58,6 +63,8 @@ class Log extends node_events_1.EventEmitter {
|
|
|
58
63
|
this.headingStyle = { fg: 'white', bg: 'black' };
|
|
59
64
|
this._id = 0;
|
|
60
65
|
this._paused = false;
|
|
66
|
+
this._asyncStorage = new node_async_hooks_1.AsyncLocalStorage();
|
|
67
|
+
this._secureValuesPreprocessor = new secure_values_preprocessor_1.SecureValuesPreprocessor();
|
|
61
68
|
this._style = {};
|
|
62
69
|
this._levels = {};
|
|
63
70
|
this._disp = {};
|
|
@@ -69,6 +76,9 @@ class Log extends node_events_1.EventEmitter {
|
|
|
69
76
|
// by default, decide based on tty-ness.
|
|
70
77
|
return (this._colorEnabled ?? Boolean(this.stream && 'isTTY' in this.stream && this.stream.isTTY));
|
|
71
78
|
}
|
|
79
|
+
get asyncStorage() {
|
|
80
|
+
return this._asyncStorage;
|
|
81
|
+
}
|
|
72
82
|
enableColor() {
|
|
73
83
|
this._colorEnabled = true;
|
|
74
84
|
}
|
|
@@ -106,6 +116,9 @@ class Log extends node_events_1.EventEmitter {
|
|
|
106
116
|
verbose(prefix, message, ...args) {
|
|
107
117
|
this.log('verbose', prefix, message, ...args);
|
|
108
118
|
}
|
|
119
|
+
debug(prefix, message, ...args) {
|
|
120
|
+
this.log('debug', prefix, message, ...args);
|
|
121
|
+
}
|
|
109
122
|
info(prefix, message, ...args) {
|
|
110
123
|
this.log('info', prefix, message, ...args);
|
|
111
124
|
}
|
|
@@ -156,7 +169,7 @@ class Log extends node_events_1.EventEmitter {
|
|
|
156
169
|
for (const formatArg of [message, ...args]) {
|
|
157
170
|
messageArguments.push(formatArg);
|
|
158
171
|
// resolve stack traces to a plain string.
|
|
159
|
-
if (
|
|
172
|
+
if (lodash_1.default.isError(formatArg) && formatArg.stack) {
|
|
160
173
|
Object.defineProperty(formatArg, 'stack', {
|
|
161
174
|
value: (stack = formatArg.stack + ''),
|
|
162
175
|
enumerable: true,
|
|
@@ -172,8 +185,8 @@ class Log extends node_events_1.EventEmitter {
|
|
|
172
185
|
id: this._id++,
|
|
173
186
|
timestamp: Date.now(),
|
|
174
187
|
level,
|
|
175
|
-
prefix:
|
|
176
|
-
message: formattedMessage,
|
|
188
|
+
prefix: this._secureValuesPreprocessor.preprocess((0, utils_1.unleakString)(prefix || '')),
|
|
189
|
+
message: this._secureValuesPreprocessor.preprocess((0, utils_1.unleakString)(formattedMessage)),
|
|
177
190
|
};
|
|
178
191
|
this.emit('log', m);
|
|
179
192
|
this.emit('log.' + level, m);
|
|
@@ -187,6 +200,25 @@ class Log extends node_events_1.EventEmitter {
|
|
|
187
200
|
}
|
|
188
201
|
this.emitLog(m);
|
|
189
202
|
}
|
|
203
|
+
/**
|
|
204
|
+
* Loads the JSON file containing secure values replacement rules.
|
|
205
|
+
* This might be necessary to hide sensitive values that may possibly
|
|
206
|
+
* appear in Appium logs.
|
|
207
|
+
* Each call to this method replaces the previously loaded rules if any existed.
|
|
208
|
+
*
|
|
209
|
+
* @param {string|string[]|LogFiltersConfig} rulesJsonPath The full path to the JSON file containing
|
|
210
|
+
* the replacement rules. Each rule could either be a string to be replaced
|
|
211
|
+
* or an object with predefined properties.
|
|
212
|
+
* @throws {Error} If the given file cannot be loaded
|
|
213
|
+
* @returns {Promise<PreprocessingRulesLoadResult>}
|
|
214
|
+
*/
|
|
215
|
+
async loadSecureValuesPreprocessingRules(rulesJsonPath) {
|
|
216
|
+
const issues = await this._secureValuesPreprocessor.loadRules(rulesJsonPath);
|
|
217
|
+
return {
|
|
218
|
+
issues,
|
|
219
|
+
rules: lodash_1.default.cloneDeep(this._secureValuesPreprocessor.rules),
|
|
220
|
+
};
|
|
221
|
+
}
|
|
190
222
|
emitLog(m) {
|
|
191
223
|
if (this._paused) {
|
|
192
224
|
this._buffer.push(m);
|
package/build/lib/log.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"log.js","sourceRoot":"","sources":["../../lib/log.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,6CAAyC;AACzC,0DAA0D;AAC1D,gEAAuC;AACvC,0DAA0D;AAC1D,sFAAqD;AACrD,gDAAkC;
|
|
1
|
+
{"version":3,"file":"log.js","sourceRoot":"","sources":["../../lib/log.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,oDAAuB;AACvB,6CAAyC;AACzC,0DAA0D;AAC1D,gEAAuC;AACvC,0DAA0D;AAC1D,sFAAqD;AACrD,gDAAkC;AAUlC,uDAAmD;AACnD,mCAAuC;AACvC,6EAAwE;AAExE,MAAM,kBAAkB,GAAG;IACzB,CAAC,OAAO,EAAE,CAAC,QAAQ,EAAE,EAAC,OAAO,EAAE,IAAI,EAAC,EAAE,MAAM,CAAC;IAC7C,CAAC,SAAS,EAAE,IAAI,EAAE,EAAC,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,OAAO,EAAC,EAAE,MAAM,CAAC;IACpD,CAAC,OAAO,EAAE,IAAI,EAAE,EAAC,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,OAAO,EAAC,EAAE,MAAM,CAAC;IAClD,CAAC,MAAM,EAAE,IAAI,EAAE,EAAC,EAAE,EAAE,OAAO,EAAC,CAAC;IAC7B,CAAC,QAAQ,EAAE,IAAI,EAAE,EAAC,EAAE,EAAE,OAAO,EAAE,EAAE,EAAE,OAAO,EAAC,CAAC;IAC5C,CAAC,MAAM,EAAE,IAAI,EAAE,EAAC,EAAE,EAAE,OAAO,EAAE,EAAE,EAAE,OAAO,EAAC,CAAC;IAC1C,CAAC,QAA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C;YAC5B,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,KAAK,CAAC;YAC3B,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,GAAG,IAAI,IAAI,KAAK,CAAC;QACpC,CAAC;IACH,CAAC;IAED,oDAAoD;IAC5C,aAAa,KAAU,CAAC;IACxB,YAAY,KAAU,CAAC;CAChC;AAhUD,kBAgUC;AAEY,QAAA,UAAU,GAAG,IAAI,GAAG,EAAE,CAAC;AACpC,kBAAe,kBAAU,CAAC"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { SecureValuePreprocessingRule, LogFiltersConfig, LogFilter } from './types';
|
|
2
|
+
export declare class SecureValuesPreprocessor {
|
|
3
|
+
_rules: SecureValuePreprocessingRule[];
|
|
4
|
+
constructor();
|
|
5
|
+
/**
|
|
6
|
+
* @returns {Array<SecureValuePreprocessingRule>} The list of successfully
|
|
7
|
+
* parsed preprocessing rules
|
|
8
|
+
*/
|
|
9
|
+
get rules(): Array<SecureValuePreprocessingRule>;
|
|
10
|
+
/**
|
|
11
|
+
* Parses single rule from the given JSON file
|
|
12
|
+
*
|
|
13
|
+
* @param {string|LogFilter} rule The rule might
|
|
14
|
+
* either be represented as a single string or a configuration object
|
|
15
|
+
* @throws {Error} If there was an error while parsing the rule
|
|
16
|
+
* @returns {SecureValuePreprocessingRule} The parsed rule
|
|
17
|
+
*/
|
|
18
|
+
parseRule(rule: string | LogFilter): SecureValuePreprocessingRule;
|
|
19
|
+
/**
|
|
20
|
+
* Loads rules from the given JSON file
|
|
21
|
+
*
|
|
22
|
+
* @param {string|string[]|LogFiltersConfig} filters
|
|
23
|
+
* One or more log parsing rules
|
|
24
|
+
* @throws {Error} If the format of the source file is invalid or
|
|
25
|
+
* it does not exist
|
|
26
|
+
* @returns {Promise<string[]>} The list of issues found while parsing each rule.
|
|
27
|
+
* An empty list is returned if no rule parsing issues were found
|
|
28
|
+
*/
|
|
29
|
+
loadRules(filters: string | string[] | LogFiltersConfig): Promise<string[]>;
|
|
30
|
+
/**
|
|
31
|
+
* Performs secure values replacement inside the given string
|
|
32
|
+
* according to the previously loaded rules. No replacement is made
|
|
33
|
+
* if there are no rules or the given value is not a string
|
|
34
|
+
*
|
|
35
|
+
* @param {string} str The string to make replacements in
|
|
36
|
+
* @returns {string} The string with replacements made
|
|
37
|
+
*/
|
|
38
|
+
preprocess(str: string): string;
|
|
39
|
+
}
|
|
40
|
+
//# sourceMappingURL=secure-values-preprocessor.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"secure-values-preprocessor.d.ts","sourceRoot":"","sources":["../../lib/secure-values-preprocessor.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,4BAA4B,EAE5B,gBAAgB,EAChB,SAAS,EACV,MAAM,SAAS,CAAC;AAajB,qBAAa,wBAAwB;IACnC,MAAM,EAAE,4BAA4B,EAAE,CAAC;;IAMvC;;;OAGG;IACH,IAAI,KAAK,IAAI,KAAK,CAAC,4BAA4B,CAAC,CAE/C;IAED;;;;;;;OAOG;IACH,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS,GAAG,4BAA4B;IAsDjE;;;;;;;;;OASG;IACG,SAAS,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,gBAAgB,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;IAuBjF;;;;;;;OAOG;IACH,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM;CAWhC"}
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.SecureValuesPreprocessor = void 0;
|
|
7
|
+
const lodash_1 = __importDefault(require("lodash"));
|
|
8
|
+
const DEFAULT_REPLACER = '**SECURE**';
|
|
9
|
+
/**
|
|
10
|
+
* Type guard for log filter type
|
|
11
|
+
* @param {object} value
|
|
12
|
+
* @returns {value is LogFilterRegex}
|
|
13
|
+
*/
|
|
14
|
+
function isLogFilterRegex(value) {
|
|
15
|
+
return 'pattern' in value;
|
|
16
|
+
}
|
|
17
|
+
class SecureValuesPreprocessor {
|
|
18
|
+
constructor() {
|
|
19
|
+
this._rules = [];
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* @returns {Array<SecureValuePreprocessingRule>} The list of successfully
|
|
23
|
+
* parsed preprocessing rules
|
|
24
|
+
*/
|
|
25
|
+
get rules() {
|
|
26
|
+
return this._rules;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Parses single rule from the given JSON file
|
|
30
|
+
*
|
|
31
|
+
* @param {string|LogFilter} rule The rule might
|
|
32
|
+
* either be represented as a single string or a configuration object
|
|
33
|
+
* @throws {Error} If there was an error while parsing the rule
|
|
34
|
+
* @returns {SecureValuePreprocessingRule} The parsed rule
|
|
35
|
+
*/
|
|
36
|
+
parseRule(rule) {
|
|
37
|
+
let pattern;
|
|
38
|
+
let replacer = DEFAULT_REPLACER;
|
|
39
|
+
let flags = ['g'];
|
|
40
|
+
if (lodash_1.default.isString(rule)) {
|
|
41
|
+
if (rule.length === 0) {
|
|
42
|
+
throw new Error(`${JSON.stringify(rule)} -> The value must not be empty`);
|
|
43
|
+
}
|
|
44
|
+
pattern = `\\b${lodash_1.default.escapeRegExp(rule)}\\b`;
|
|
45
|
+
}
|
|
46
|
+
else if (lodash_1.default.isPlainObject(rule)) {
|
|
47
|
+
if (isLogFilterRegex(rule)) {
|
|
48
|
+
if (!lodash_1.default.isString(rule.pattern) || rule.pattern.length === 0) {
|
|
49
|
+
throw new Error(`${JSON.stringify(rule)} -> The value of 'pattern' must be a valid non-empty string`);
|
|
50
|
+
}
|
|
51
|
+
pattern = rule.pattern;
|
|
52
|
+
}
|
|
53
|
+
else if (lodash_1.default.has(rule, 'text')) {
|
|
54
|
+
if (!lodash_1.default.isString(rule.text) || rule.text.length === 0) {
|
|
55
|
+
throw new Error(`${JSON.stringify(rule)} -> The value of 'text' must be a valid non-empty string`);
|
|
56
|
+
}
|
|
57
|
+
pattern = `\\b${lodash_1.default.escapeRegExp(rule.text)}\\b`;
|
|
58
|
+
}
|
|
59
|
+
if (!pattern) {
|
|
60
|
+
throw new Error(`${JSON.stringify(rule)} -> Must either have a field named 'pattern' or 'text'`);
|
|
61
|
+
}
|
|
62
|
+
if (lodash_1.default.has(rule, 'flags')) {
|
|
63
|
+
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions#Advanced_searching_with_flags_2
|
|
64
|
+
for (const flag of ['i', 'g', 'm', 's', 'u', 'y']) {
|
|
65
|
+
if (lodash_1.default.includes(rule.flags, flag)) {
|
|
66
|
+
flags.push(flag);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
flags = lodash_1.default.uniq(flags);
|
|
70
|
+
}
|
|
71
|
+
if (lodash_1.default.isString(rule.replacer)) {
|
|
72
|
+
replacer = rule.replacer;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
else {
|
|
76
|
+
throw new Error(`${JSON.stringify(rule)} -> Must either be a string or an object`);
|
|
77
|
+
}
|
|
78
|
+
return {
|
|
79
|
+
pattern: new RegExp(pattern, flags.join('')),
|
|
80
|
+
replacer,
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Loads rules from the given JSON file
|
|
85
|
+
*
|
|
86
|
+
* @param {string|string[]|LogFiltersConfig} filters
|
|
87
|
+
* One or more log parsing rules
|
|
88
|
+
* @throws {Error} If the format of the source file is invalid or
|
|
89
|
+
* it does not exist
|
|
90
|
+
* @returns {Promise<string[]>} The list of issues found while parsing each rule.
|
|
91
|
+
* An empty list is returned if no rule parsing issues were found
|
|
92
|
+
*/
|
|
93
|
+
async loadRules(filters) {
|
|
94
|
+
const issues = [];
|
|
95
|
+
const rawRules = [];
|
|
96
|
+
for (const source of (lodash_1.default.isArray(filters) ? filters : [filters])) {
|
|
97
|
+
if (lodash_1.default.isPlainObject(source)) {
|
|
98
|
+
rawRules.push(source);
|
|
99
|
+
}
|
|
100
|
+
else if (lodash_1.default.isString(source)) {
|
|
101
|
+
rawRules.push(String(source));
|
|
102
|
+
}
|
|
103
|
+
else {
|
|
104
|
+
issues.push(`'${source}' must be a valid log filtering rule`);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
this._rules = [];
|
|
108
|
+
for (const rawRule of rawRules) {
|
|
109
|
+
try {
|
|
110
|
+
this._rules.push(this.parseRule(rawRule));
|
|
111
|
+
}
|
|
112
|
+
catch (e) {
|
|
113
|
+
issues.push(e.message);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
return issues;
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Performs secure values replacement inside the given string
|
|
120
|
+
* according to the previously loaded rules. No replacement is made
|
|
121
|
+
* if there are no rules or the given value is not a string
|
|
122
|
+
*
|
|
123
|
+
* @param {string} str The string to make replacements in
|
|
124
|
+
* @returns {string} The string with replacements made
|
|
125
|
+
*/
|
|
126
|
+
preprocess(str) {
|
|
127
|
+
if (this._rules.length === 0 || !str || !lodash_1.default.isString(str)) {
|
|
128
|
+
return str;
|
|
129
|
+
}
|
|
130
|
+
let result = str;
|
|
131
|
+
for (const rule of this._rules) {
|
|
132
|
+
result = result.replace(rule.pattern, rule.replacer ?? DEFAULT_REPLACER);
|
|
133
|
+
}
|
|
134
|
+
return result;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
exports.SecureValuesPreprocessor = SecureValuesPreprocessor;
|
|
138
|
+
//# sourceMappingURL=secure-values-preprocessor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"secure-values-preprocessor.js","sourceRoot":"","sources":["../../lib/secure-values-preprocessor.ts"],"names":[],"mappings":";;;;;;AAAA,oDAAuB;AAQvB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CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC;YACzD,OAAO,GAAG,CAAC;QACb,CAAC;QAED,IAAI,MAAM,GAAG,GAAG,CAAC;QACjB,KAAK,MAAM,IAAI,IAAI,IAAI,CAAC,MAAM,EAAE,CAAC;YAC/B,MAAM,GAAG,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,EAAE,IAAI,CAAC,QAAQ,IAAI,gBAAgB,CAAC,CAAC;QAC3E,CAAC;QACD,OAAO,MAAM,CAAC;IAChB,CAAC;CACF;AAjID,4DAiIC"}
|
package/build/lib/types.d.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
+
/// <reference types="node" />
|
|
2
3
|
import type { EventEmitter } from 'node:events';
|
|
4
|
+
import type { AsyncLocalStorage } from 'node:async_hooks';
|
|
3
5
|
export interface Logger extends EventEmitter {
|
|
4
6
|
level: string;
|
|
5
7
|
record: MessageObject[];
|
|
@@ -23,6 +25,7 @@ export interface Logger extends EventEmitter {
|
|
|
23
25
|
*/
|
|
24
26
|
silly(prefix: string, message: any, ...args: any[]): void;
|
|
25
27
|
verbose(prefix: string, message: any, ...args: any[]): void;
|
|
28
|
+
debug(prefix: string, message: any, ...args: any[]): void;
|
|
26
29
|
info(prefix: string, message: any, ...args: any[]): void;
|
|
27
30
|
timing(prefix: string, message: any, ...args: any[]): void;
|
|
28
31
|
http(prefix: string, message: any, ...args: any[]): void;
|
|
@@ -30,6 +33,7 @@ export interface Logger extends EventEmitter {
|
|
|
30
33
|
warn(prefix: string, message: any, ...args: any[]): void;
|
|
31
34
|
error(prefix: string, message: any, ...args: any[]): void;
|
|
32
35
|
silent(prefix: string, message: any, ...args: any[]): void;
|
|
36
|
+
loadSecureValuesPreprocessingRules(rulesJsonPath: string | string[] | LogFiltersConfig): Promise<PreprocessingRulesLoadResult>;
|
|
33
37
|
enableColor(): void;
|
|
34
38
|
disableColor(): void;
|
|
35
39
|
enableProgress(): void;
|
|
@@ -40,9 +44,10 @@ export interface Logger extends EventEmitter {
|
|
|
40
44
|
pause(): void;
|
|
41
45
|
resume(): void;
|
|
42
46
|
addLevel(level: string, n: number, style?: StyleObject, disp?: string): void;
|
|
47
|
+
get asyncStorage(): AsyncLocalStorage<Record<string, any>>;
|
|
43
48
|
[key: string]: any;
|
|
44
49
|
}
|
|
45
|
-
export type LogLevel = 'silly' | 'verbose' | 'info' | 'timing' | 'http' | 'notice' | 'warn' | 'error' | 'silent';
|
|
50
|
+
export type LogLevel = 'silly' | 'verbose' | 'debug' | 'info' | 'timing' | 'http' | 'notice' | 'warn' | 'error' | 'silent';
|
|
46
51
|
export interface StyleObject {
|
|
47
52
|
fg?: string | undefined;
|
|
48
53
|
bg?: string | undefined;
|
|
@@ -58,4 +63,54 @@ export interface MessageObject {
|
|
|
58
63
|
prefix: string;
|
|
59
64
|
message: string;
|
|
60
65
|
}
|
|
66
|
+
export interface SecureValuePreprocessingRule {
|
|
67
|
+
/** The parsed pattern which is going to be used for replacement */
|
|
68
|
+
pattern: RegExp;
|
|
69
|
+
/** The replacer value to use. By default equals to `DEFAULT_SECURE_REPLACER` */
|
|
70
|
+
replacer?: string;
|
|
71
|
+
}
|
|
72
|
+
export interface PreprocessingRulesLoadResult {
|
|
73
|
+
/**
|
|
74
|
+
* The list of rule parsing issues (one item per rule).
|
|
75
|
+
* Rules with issues are skipped. An empty list is returned if no parsing issues exist.
|
|
76
|
+
*/
|
|
77
|
+
issues: string[];
|
|
78
|
+
/**
|
|
79
|
+
* The list of successfully loaded
|
|
80
|
+
* replacement rules. The list could be empty if no rules were loaded.
|
|
81
|
+
*/
|
|
82
|
+
rules: SecureValuePreprocessingRule[];
|
|
83
|
+
}
|
|
84
|
+
export type LogFilter = {
|
|
85
|
+
/**
|
|
86
|
+
* Replacement string for matched text
|
|
87
|
+
*/
|
|
88
|
+
replacer?: string;
|
|
89
|
+
/**
|
|
90
|
+
* Matching flags; see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions#advanced_searching_with_flags
|
|
91
|
+
*/
|
|
92
|
+
flags?: string;
|
|
93
|
+
[k: string]: unknown;
|
|
94
|
+
} & (LogFilterText | LogFilterRegex);
|
|
95
|
+
/**
|
|
96
|
+
* One or more log filtering rules
|
|
97
|
+
*/
|
|
98
|
+
export type LogFiltersConfig = LogFilter[];
|
|
99
|
+
export interface LogFilterText {
|
|
100
|
+
/**
|
|
101
|
+
* Text to match
|
|
102
|
+
*/
|
|
103
|
+
text: string;
|
|
104
|
+
[k: string]: unknown;
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Log filter with regular expression
|
|
108
|
+
*/
|
|
109
|
+
export interface LogFilterRegex {
|
|
110
|
+
/**
|
|
111
|
+
* Regex pattern to match
|
|
112
|
+
*/
|
|
113
|
+
pattern: string;
|
|
114
|
+
[k: string]: unknown;
|
|
115
|
+
}
|
|
61
116
|
//# sourceMappingURL=types.d.ts.map
|
package/build/lib/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../lib/types.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../lib/types.ts"],"names":[],"mappings":";;AAAA,OAAO,KAAK,EAAC,YAAY,EAAC,MAAM,aAAa,CAAC;AAC9C,OAAO,KAAK,EAAC,iBAAiB,EAAC,MAAM,kBAAkB,CAAC;AAExD,MAAM,WAAW,MAAO,SAAQ,YAAY;IAC1C,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,aAAa,EAAE,CAAC;IACxB,aAAa,EAAE,MAAM,CAAC;IACtB,WAAW,EAAE,WAAW,CAAC;IACzB,YAAY,EAAE,WAAW,CAAC;IAC1B,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,GAAG,CAAC;IAEZ;;;;;;OAMG;IACH,GAAG,CAAC,KAAK,EAAE,QAAQ,GAAG,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,SAAS,EAAE,MAAM,CAAC;IAClB,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,4BAA4B;IAC3C,mEAAmE;IACnE,OAAO,EAAE,MAAM,CAAC;IAChB,gFAAgF;IAChF,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,4BAA4B;IAC3C;;;OAGG;IACH,MAAM,EAAE,MAAM,EAAE,CAAC;IACjB;;;OAGG;IACH,KAAK,EAAE,4BAA4B,EAAE,CAAC;CACvC;AAED,MAAM,MAAM,SAAS,GAAG;IACtB;;OAEG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB;;OAEG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,CAAC,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC;CACtB,GAAG,CAAC,aAAa,GAAG,cAAc,CAAC,CAAC;AACrC;;GAEG;AACH,MAAM,MAAM,gBAAgB,GAAG,SAAS,EAAE,CAAC;AAE3C,MAAM,WAAW,aAAa;IAC5B;;OAEG;IACH,IAAI,EAAE,MAAM,CAAC;IACb,CAAC,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC;CACtB;AACD;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B;;OAEG;IACH,OAAO,EAAE,MAAM,CAAC;IAChB,CAAC,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC;CACtB"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This function is necessary to workaround unexpected memory leaks
|
|
3
|
+
* caused by NodeJS string interning
|
|
4
|
+
* behavior described in https://bugs.chromium.org/p/v8/issues/detail?id=2869
|
|
5
|
+
*
|
|
6
|
+
* @param {any} s - The string to unleak
|
|
7
|
+
* @return {string} Either the unleaked string or the original object converted to string
|
|
8
|
+
*/
|
|
9
|
+
export declare function unleakString(s: any): string;
|
|
10
|
+
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../lib/utils.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,wBAAgB,YAAY,CAAC,CAAC,EAAE,GAAG,GAAG,MAAM,CAE3C"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.unleakString = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* This function is necessary to workaround unexpected memory leaks
|
|
6
|
+
* caused by NodeJS string interning
|
|
7
|
+
* behavior described in https://bugs.chromium.org/p/v8/issues/detail?id=2869
|
|
8
|
+
*
|
|
9
|
+
* @param {any} s - The string to unleak
|
|
10
|
+
* @return {string} Either the unleaked string or the original object converted to string
|
|
11
|
+
*/
|
|
12
|
+
function unleakString(s) {
|
|
13
|
+
return ` ${s}`.substring(1);
|
|
14
|
+
}
|
|
15
|
+
exports.unleakString = unleakString;
|
|
16
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../lib/utils.ts"],"names":[],"mappings":";;;AAAA;;;;;;;GAOG;AACH,SAAgB,YAAY,CAAC,CAAM;IACjC,OAAO,IAAI,CAAC,EAAE,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC;AAC9B,CAAC;AAFD,oCAEC"}
|
package/lib/log.ts
CHANGED
|
@@ -1,15 +1,27 @@
|
|
|
1
|
+
import _ from 'lodash';
|
|
1
2
|
import {EventEmitter} from 'node:events';
|
|
2
3
|
// @ts-ignore This module does not provide type definitons
|
|
3
4
|
import setBlocking from 'set-blocking';
|
|
4
5
|
// @ts-ignore This module does not provide type definitons
|
|
5
6
|
import consoleControl from 'console-control-strings';
|
|
6
7
|
import * as util from 'node:util';
|
|
7
|
-
import type {
|
|
8
|
+
import type {
|
|
9
|
+
MessageObject,
|
|
10
|
+
StyleObject,
|
|
11
|
+
Logger,
|
|
12
|
+
LogLevel,
|
|
13
|
+
PreprocessingRulesLoadResult,
|
|
14
|
+
LogFiltersConfig
|
|
15
|
+
} from './types';
|
|
8
16
|
import type {Writable} from 'node:stream';
|
|
17
|
+
import {AsyncLocalStorage} from 'node:async_hooks';
|
|
18
|
+
import { unleakString } from './utils';
|
|
19
|
+
import { SecureValuesPreprocessor } from './secure-values-preprocessor';
|
|
9
20
|
|
|
10
|
-
const DEFAULT_LOG_LEVELS
|
|
21
|
+
const DEFAULT_LOG_LEVELS = [
|
|
11
22
|
['silly', -Infinity, {inverse: true}, 'sill'],
|
|
12
23
|
['verbose', 1000, {fg: 'cyan', bg: 'black'}, 'verb'],
|
|
24
|
+
['debug', 1500, {fg: 'cyan', bg: 'black'}, 'dbug'],
|
|
13
25
|
['info', 2000, {fg: 'green'}],
|
|
14
26
|
['timing', 2500, {fg: 'green', bg: 'black'}],
|
|
15
27
|
['http', 3000, {fg: 'green', bg: 'black'}],
|
|
@@ -30,6 +42,7 @@ export class Log extends EventEmitter implements Logger {
|
|
|
30
42
|
heading: string;
|
|
31
43
|
stream: Writable; // Defaults to process.stderr
|
|
32
44
|
|
|
45
|
+
_asyncStorage: AsyncLocalStorage<Record<string, any>>;
|
|
33
46
|
_colorEnabled?: boolean;
|
|
34
47
|
_buffer: MessageObject[];
|
|
35
48
|
_style: Record<LogLevel | string, StyleObject | undefined>;
|
|
@@ -37,6 +50,7 @@ export class Log extends EventEmitter implements Logger {
|
|
|
37
50
|
_disp: Record<LogLevel | string, number | string>;
|
|
38
51
|
_id: number;
|
|
39
52
|
_paused: boolean;
|
|
53
|
+
_secureValuesPreprocessor: SecureValuesPreprocessor;
|
|
40
54
|
|
|
41
55
|
constructor() {
|
|
42
56
|
super();
|
|
@@ -51,6 +65,8 @@ export class Log extends EventEmitter implements Logger {
|
|
|
51
65
|
this.headingStyle = {fg: 'white', bg: 'black'};
|
|
52
66
|
this._id = 0;
|
|
53
67
|
this._paused = false;
|
|
68
|
+
this._asyncStorage = new AsyncLocalStorage();
|
|
69
|
+
this._secureValuesPreprocessor = new SecureValuesPreprocessor();
|
|
54
70
|
|
|
55
71
|
this._style = {};
|
|
56
72
|
this._levels = {};
|
|
@@ -68,6 +84,10 @@ export class Log extends EventEmitter implements Logger {
|
|
|
68
84
|
);
|
|
69
85
|
}
|
|
70
86
|
|
|
87
|
+
get asyncStorage(): AsyncLocalStorage<Record<string, any>> {
|
|
88
|
+
return this._asyncStorage;
|
|
89
|
+
}
|
|
90
|
+
|
|
71
91
|
enableColor(): void {
|
|
72
92
|
this._colorEnabled = true;
|
|
73
93
|
}
|
|
@@ -114,6 +134,10 @@ export class Log extends EventEmitter implements Logger {
|
|
|
114
134
|
this.log('verbose', prefix, message, ...args);
|
|
115
135
|
}
|
|
116
136
|
|
|
137
|
+
debug(prefix: string, message: any, ...args: any[]): void {
|
|
138
|
+
this.log('debug', prefix, message, ...args);
|
|
139
|
+
}
|
|
140
|
+
|
|
117
141
|
info(prefix: string, message: any, ...args: any[]): void {
|
|
118
142
|
this.log('info', prefix, message, ...args);
|
|
119
143
|
}
|
|
@@ -173,7 +197,7 @@ export class Log extends EventEmitter implements Logger {
|
|
|
173
197
|
for (const formatArg of [message, ...args]) {
|
|
174
198
|
messageArguments.push(formatArg);
|
|
175
199
|
// resolve stack traces to a plain string.
|
|
176
|
-
if (
|
|
200
|
+
if (_.isError(formatArg) && formatArg.stack) {
|
|
177
201
|
Object.defineProperty(formatArg, 'stack', {
|
|
178
202
|
value: (stack = formatArg.stack + ''),
|
|
179
203
|
enumerable: true,
|
|
@@ -190,8 +214,8 @@ export class Log extends EventEmitter implements Logger {
|
|
|
190
214
|
id: this._id++,
|
|
191
215
|
timestamp: Date.now(),
|
|
192
216
|
level,
|
|
193
|
-
prefix:
|
|
194
|
-
message: formattedMessage,
|
|
217
|
+
prefix: this._secureValuesPreprocessor.preprocess(unleakString(prefix || '')),
|
|
218
|
+
message: this._secureValuesPreprocessor.preprocess(unleakString(formattedMessage)),
|
|
195
219
|
};
|
|
196
220
|
|
|
197
221
|
this.emit('log', m);
|
|
@@ -209,6 +233,28 @@ export class Log extends EventEmitter implements Logger {
|
|
|
209
233
|
this.emitLog(m);
|
|
210
234
|
}
|
|
211
235
|
|
|
236
|
+
/**
|
|
237
|
+
* Loads the JSON file containing secure values replacement rules.
|
|
238
|
+
* This might be necessary to hide sensitive values that may possibly
|
|
239
|
+
* appear in Appium logs.
|
|
240
|
+
* Each call to this method replaces the previously loaded rules if any existed.
|
|
241
|
+
*
|
|
242
|
+
* @param {string|string[]|LogFiltersConfig} rulesJsonPath The full path to the JSON file containing
|
|
243
|
+
* the replacement rules. Each rule could either be a string to be replaced
|
|
244
|
+
* or an object with predefined properties.
|
|
245
|
+
* @throws {Error} If the given file cannot be loaded
|
|
246
|
+
* @returns {Promise<PreprocessingRulesLoadResult>}
|
|
247
|
+
*/
|
|
248
|
+
async loadSecureValuesPreprocessingRules(
|
|
249
|
+
rulesJsonPath: string | string[] | LogFiltersConfig
|
|
250
|
+
): Promise<PreprocessingRulesLoadResult> {
|
|
251
|
+
const issues = await this._secureValuesPreprocessor.loadRules(rulesJsonPath);
|
|
252
|
+
return {
|
|
253
|
+
issues,
|
|
254
|
+
rules: _.cloneDeep(this._secureValuesPreprocessor.rules),
|
|
255
|
+
};
|
|
256
|
+
}
|
|
257
|
+
|
|
212
258
|
private emitLog(m: MessageObject): void {
|
|
213
259
|
if (this._paused) {
|
|
214
260
|
this._buffer.push(m);
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
import _ from 'lodash';
|
|
2
|
+
import type {
|
|
3
|
+
SecureValuePreprocessingRule,
|
|
4
|
+
LogFilterRegex,
|
|
5
|
+
LogFiltersConfig,
|
|
6
|
+
LogFilter,
|
|
7
|
+
} from './types';
|
|
8
|
+
|
|
9
|
+
const DEFAULT_REPLACER = '**SECURE**';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Type guard for log filter type
|
|
13
|
+
* @param {object} value
|
|
14
|
+
* @returns {value is LogFilterRegex}
|
|
15
|
+
*/
|
|
16
|
+
function isLogFilterRegex(value: object): value is LogFilterRegex {
|
|
17
|
+
return 'pattern' in value;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export class SecureValuesPreprocessor {
|
|
21
|
+
_rules: SecureValuePreprocessingRule[];
|
|
22
|
+
|
|
23
|
+
constructor() {
|
|
24
|
+
this._rules = [];
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* @returns {Array<SecureValuePreprocessingRule>} The list of successfully
|
|
29
|
+
* parsed preprocessing rules
|
|
30
|
+
*/
|
|
31
|
+
get rules(): Array<SecureValuePreprocessingRule> {
|
|
32
|
+
return this._rules;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Parses single rule from the given JSON file
|
|
37
|
+
*
|
|
38
|
+
* @param {string|LogFilter} rule The rule might
|
|
39
|
+
* either be represented as a single string or a configuration object
|
|
40
|
+
* @throws {Error} If there was an error while parsing the rule
|
|
41
|
+
* @returns {SecureValuePreprocessingRule} The parsed rule
|
|
42
|
+
*/
|
|
43
|
+
parseRule(rule: string | LogFilter): SecureValuePreprocessingRule {
|
|
44
|
+
let pattern: string | undefined;
|
|
45
|
+
let replacer = DEFAULT_REPLACER;
|
|
46
|
+
let flags = ['g'];
|
|
47
|
+
if (_.isString(rule)) {
|
|
48
|
+
if (rule.length === 0) {
|
|
49
|
+
throw new Error(`${JSON.stringify(rule)} -> The value must not be empty`);
|
|
50
|
+
}
|
|
51
|
+
pattern = `\\b${_.escapeRegExp(rule)}\\b`;
|
|
52
|
+
} else if (_.isPlainObject(rule)) {
|
|
53
|
+
if (isLogFilterRegex(rule)) {
|
|
54
|
+
if (!_.isString(rule.pattern) || rule.pattern.length === 0) {
|
|
55
|
+
throw new Error(
|
|
56
|
+
`${JSON.stringify(rule)} -> The value of 'pattern' must be a valid non-empty string`
|
|
57
|
+
);
|
|
58
|
+
}
|
|
59
|
+
pattern = rule.pattern;
|
|
60
|
+
} else if (_.has(rule, 'text')) {
|
|
61
|
+
if (!_.isString(rule.text) || rule.text.length === 0) {
|
|
62
|
+
throw new Error(
|
|
63
|
+
`${JSON.stringify(rule)} -> The value of 'text' must be a valid non-empty string`
|
|
64
|
+
);
|
|
65
|
+
}
|
|
66
|
+
pattern = `\\b${_.escapeRegExp(rule.text)}\\b`;
|
|
67
|
+
}
|
|
68
|
+
if (!pattern) {
|
|
69
|
+
throw new Error(
|
|
70
|
+
`${JSON.stringify(rule)} -> Must either have a field named 'pattern' or 'text'`
|
|
71
|
+
);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
if (_.has(rule, 'flags')) {
|
|
75
|
+
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions#Advanced_searching_with_flags_2
|
|
76
|
+
for (const flag of ['i', 'g', 'm', 's', 'u', 'y']) {
|
|
77
|
+
if (_.includes(rule.flags, flag)) {
|
|
78
|
+
flags.push(flag);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
flags = _.uniq(flags);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
if (_.isString(rule.replacer)) {
|
|
85
|
+
replacer = rule.replacer;
|
|
86
|
+
}
|
|
87
|
+
} else {
|
|
88
|
+
throw new Error(`${JSON.stringify(rule)} -> Must either be a string or an object`);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
return {
|
|
92
|
+
pattern: new RegExp(pattern, flags.join('')),
|
|
93
|
+
replacer,
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Loads rules from the given JSON file
|
|
99
|
+
*
|
|
100
|
+
* @param {string|string[]|LogFiltersConfig} filters
|
|
101
|
+
* One or more log parsing rules
|
|
102
|
+
* @throws {Error} If the format of the source file is invalid or
|
|
103
|
+
* it does not exist
|
|
104
|
+
* @returns {Promise<string[]>} The list of issues found while parsing each rule.
|
|
105
|
+
* An empty list is returned if no rule parsing issues were found
|
|
106
|
+
*/
|
|
107
|
+
async loadRules(filters: string | string[] | LogFiltersConfig): Promise<string[]> {
|
|
108
|
+
const issues: string[] = [];
|
|
109
|
+
const rawRules: (LogFilter | string)[] = [];
|
|
110
|
+
for (const source of (_.isArray(filters) ? filters : [filters])) {
|
|
111
|
+
if (_.isPlainObject(source)) {
|
|
112
|
+
rawRules.push(source as LogFilter);
|
|
113
|
+
} else if (_.isString(source)) {
|
|
114
|
+
rawRules.push(String(source));
|
|
115
|
+
} else {
|
|
116
|
+
issues.push(`'${source}' must be a valid log filtering rule`);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
this._rules = [];
|
|
120
|
+
for (const rawRule of rawRules) {
|
|
121
|
+
try {
|
|
122
|
+
this._rules.push(this.parseRule(rawRule));
|
|
123
|
+
} catch (e) {
|
|
124
|
+
issues.push((e as Error).message);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
return issues;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* Performs secure values replacement inside the given string
|
|
132
|
+
* according to the previously loaded rules. No replacement is made
|
|
133
|
+
* if there are no rules or the given value is not a string
|
|
134
|
+
*
|
|
135
|
+
* @param {string} str The string to make replacements in
|
|
136
|
+
* @returns {string} The string with replacements made
|
|
137
|
+
*/
|
|
138
|
+
preprocess(str: string): string {
|
|
139
|
+
if (this._rules.length === 0 || !str || !_.isString(str)) {
|
|
140
|
+
return str;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
let result = str;
|
|
144
|
+
for (const rule of this._rules) {
|
|
145
|
+
result = result.replace(rule.pattern, rule.replacer ?? DEFAULT_REPLACER);
|
|
146
|
+
}
|
|
147
|
+
return result;
|
|
148
|
+
}
|
|
149
|
+
}
|
package/lib/types.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type {EventEmitter} from 'node:events';
|
|
2
|
+
import type {AsyncLocalStorage} from 'node:async_hooks';
|
|
2
3
|
|
|
3
4
|
export interface Logger extends EventEmitter {
|
|
4
5
|
level: string;
|
|
@@ -25,6 +26,7 @@ export interface Logger extends EventEmitter {
|
|
|
25
26
|
*/
|
|
26
27
|
silly(prefix: string, message: any, ...args: any[]): void;
|
|
27
28
|
verbose(prefix: string, message: any, ...args: any[]): void;
|
|
29
|
+
debug(prefix: string, message: any, ...args: any[]): void;
|
|
28
30
|
info(prefix: string, message: any, ...args: any[]): void;
|
|
29
31
|
timing(prefix: string, message: any, ...args: any[]): void;
|
|
30
32
|
http(prefix: string, message: any, ...args: any[]): void;
|
|
@@ -33,6 +35,10 @@ export interface Logger extends EventEmitter {
|
|
|
33
35
|
error(prefix: string, message: any, ...args: any[]): void;
|
|
34
36
|
silent(prefix: string, message: any, ...args: any[]): void;
|
|
35
37
|
|
|
38
|
+
loadSecureValuesPreprocessingRules(
|
|
39
|
+
rulesJsonPath: string | string[] | LogFiltersConfig
|
|
40
|
+
): Promise<PreprocessingRulesLoadResult>;
|
|
41
|
+
|
|
36
42
|
enableColor(): void;
|
|
37
43
|
disableColor(): void;
|
|
38
44
|
|
|
@@ -48,6 +54,8 @@ export interface Logger extends EventEmitter {
|
|
|
48
54
|
|
|
49
55
|
addLevel(level: string, n: number, style?: StyleObject, disp?: string): void;
|
|
50
56
|
|
|
57
|
+
get asyncStorage(): AsyncLocalStorage<Record<string, any>>;
|
|
58
|
+
|
|
51
59
|
// Allows for custom log levels
|
|
52
60
|
// log.addLevel("custom", level)
|
|
53
61
|
// log.custom(prefix, message)
|
|
@@ -57,6 +65,7 @@ export interface Logger extends EventEmitter {
|
|
|
57
65
|
export type LogLevel =
|
|
58
66
|
| 'silly'
|
|
59
67
|
| 'verbose'
|
|
68
|
+
| 'debug'
|
|
60
69
|
| 'info'
|
|
61
70
|
| 'timing'
|
|
62
71
|
| 'http'
|
|
@@ -81,3 +90,57 @@ export interface MessageObject {
|
|
|
81
90
|
prefix: string;
|
|
82
91
|
message: string;
|
|
83
92
|
}
|
|
93
|
+
|
|
94
|
+
export interface SecureValuePreprocessingRule {
|
|
95
|
+
/** The parsed pattern which is going to be used for replacement */
|
|
96
|
+
pattern: RegExp;
|
|
97
|
+
/** The replacer value to use. By default equals to `DEFAULT_SECURE_REPLACER` */
|
|
98
|
+
replacer?: string;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
export interface PreprocessingRulesLoadResult {
|
|
102
|
+
/**
|
|
103
|
+
* The list of rule parsing issues (one item per rule).
|
|
104
|
+
* Rules with issues are skipped. An empty list is returned if no parsing issues exist.
|
|
105
|
+
*/
|
|
106
|
+
issues: string[];
|
|
107
|
+
/**
|
|
108
|
+
* The list of successfully loaded
|
|
109
|
+
* replacement rules. The list could be empty if no rules were loaded.
|
|
110
|
+
*/
|
|
111
|
+
rules: SecureValuePreprocessingRule[];
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
export type LogFilter = {
|
|
115
|
+
/**
|
|
116
|
+
* Replacement string for matched text
|
|
117
|
+
*/
|
|
118
|
+
replacer?: string;
|
|
119
|
+
/**
|
|
120
|
+
* Matching flags; see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions#advanced_searching_with_flags
|
|
121
|
+
*/
|
|
122
|
+
flags?: string;
|
|
123
|
+
[k: string]: unknown;
|
|
124
|
+
} & (LogFilterText | LogFilterRegex);
|
|
125
|
+
/**
|
|
126
|
+
* One or more log filtering rules
|
|
127
|
+
*/
|
|
128
|
+
export type LogFiltersConfig = LogFilter[];
|
|
129
|
+
|
|
130
|
+
export interface LogFilterText {
|
|
131
|
+
/**
|
|
132
|
+
* Text to match
|
|
133
|
+
*/
|
|
134
|
+
text: string;
|
|
135
|
+
[k: string]: unknown;
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Log filter with regular expression
|
|
139
|
+
*/
|
|
140
|
+
export interface LogFilterRegex {
|
|
141
|
+
/**
|
|
142
|
+
* Regex pattern to match
|
|
143
|
+
*/
|
|
144
|
+
pattern: string;
|
|
145
|
+
[k: string]: unknown;
|
|
146
|
+
}
|
package/lib/utils.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This function is necessary to workaround unexpected memory leaks
|
|
3
|
+
* caused by NodeJS string interning
|
|
4
|
+
* behavior described in https://bugs.chromium.org/p/v8/issues/detail?id=2869
|
|
5
|
+
*
|
|
6
|
+
* @param {any} s - The string to unleak
|
|
7
|
+
* @return {string} Either the unleaked string or the original object converted to string
|
|
8
|
+
*/
|
|
9
|
+
export function unleakString(s: any): string {
|
|
10
|
+
return ` ${s}`.substring(1);
|
|
11
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@appium/logger",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.4.1",
|
|
4
4
|
"author": "https://github.com/appium",
|
|
5
5
|
"description": "A Universal Logger For The Appium Ecosystem",
|
|
6
6
|
"repository": {
|
|
@@ -28,9 +28,10 @@
|
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
30
30
|
"console-control-strings": "1.1.0",
|
|
31
|
+
"lodash": "4.17.21",
|
|
31
32
|
"set-blocking": "2.0.0"
|
|
32
33
|
},
|
|
33
|
-
"license": "
|
|
34
|
+
"license": "ISC",
|
|
34
35
|
"engines": {
|
|
35
36
|
"node": "^14.17.0 || ^16.13.0 || >=18.0.0",
|
|
36
37
|
"npm": ">=8"
|
|
@@ -42,7 +43,7 @@
|
|
|
42
43
|
"publishConfig": {
|
|
43
44
|
"access": "public"
|
|
44
45
|
},
|
|
45
|
-
"gitHead": "
|
|
46
|
+
"gitHead": "192f1f379301539540aa7882f4b667a802cbc4a8",
|
|
46
47
|
"keywords": [
|
|
47
48
|
"automation",
|
|
48
49
|
"javascript",
|