@atlaspack/logger 2.14.5-canary.38 → 2.14.5-canary.380
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 +270 -0
- package/dist/Logger.js +179 -0
- package/dist/tracer.js +28 -0
- package/lib/Logger.js +7 -23
- package/lib/types/Logger.d.ts +129 -0
- package/lib/types/tracer.d.ts +4 -0
- package/package.json +13 -14
- package/src/{Logger.js → Logger.ts} +22 -33
- package/src/{tracer.js → tracer.ts} +0 -2
- package/test/{Logger.test.js → Logger.test.ts} +2 -4
- package/tsconfig.json +21 -0
- package/tsconfig.tsbuildinfo +1 -0
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import type { IDisposable, LogEvent, PluginLogger as IPluginLogger } from '@atlaspack/types-internal';
|
|
2
|
+
import type { Diagnostic, Diagnostifiable, DiagnosticWithoutOrigin } from '@atlaspack/diagnostic';
|
|
3
|
+
import { ValueEmitter } from '@atlaspack/events';
|
|
4
|
+
export { instrument, instrumentAsync } from './tracer';
|
|
5
|
+
declare class Logger {
|
|
6
|
+
logEmitter: ValueEmitter<LogEvent>;
|
|
7
|
+
onLog(cb: (event: LogEvent) => unknown): IDisposable;
|
|
8
|
+
verbose(diagnostic: Diagnostic | Array<Diagnostic>): void;
|
|
9
|
+
info(diagnostic: Diagnostic | Array<Diagnostic>): void;
|
|
10
|
+
log(diagnostic: Diagnostic | Array<Diagnostic>): void;
|
|
11
|
+
warn(diagnostic: Diagnostic | Array<Diagnostic>): void;
|
|
12
|
+
error(input: Diagnostifiable, realOrigin?: string): void;
|
|
13
|
+
progress(message: string): void;
|
|
14
|
+
}
|
|
15
|
+
declare const logger: Logger;
|
|
16
|
+
export default logger;
|
|
17
|
+
/** @private */
|
|
18
|
+
export type PluginLoggerOpts = {
|
|
19
|
+
origin: string;
|
|
20
|
+
};
|
|
21
|
+
export declare class PluginLogger implements IPluginLogger {
|
|
22
|
+
/** @private */
|
|
23
|
+
origin: string;
|
|
24
|
+
/** @private */
|
|
25
|
+
constructor(opts: PluginLoggerOpts);
|
|
26
|
+
/** @private */
|
|
27
|
+
updateOrigin(diagnostic: DiagnosticWithoutOrigin | Array<DiagnosticWithoutOrigin>): Diagnostic | Array<Diagnostic>;
|
|
28
|
+
verbose(diagnostic: DiagnosticWithoutOrigin | Array<DiagnosticWithoutOrigin>): void;
|
|
29
|
+
info(diagnostic: DiagnosticWithoutOrigin | Array<DiagnosticWithoutOrigin>): void;
|
|
30
|
+
log(diagnostic: DiagnosticWithoutOrigin | Array<DiagnosticWithoutOrigin>): void;
|
|
31
|
+
warn(diagnostic: DiagnosticWithoutOrigin | Array<DiagnosticWithoutOrigin>): void;
|
|
32
|
+
error(input: Diagnostifiable | DiagnosticWithoutOrigin | Array<DiagnosticWithoutOrigin>): void;
|
|
33
|
+
/** @private */
|
|
34
|
+
progress(message: string): void;
|
|
35
|
+
}
|
|
36
|
+
/** @private */
|
|
37
|
+
export declare const INTERNAL_ORIGINAL_CONSOLE: {
|
|
38
|
+
readonly assert: {
|
|
39
|
+
(condition?: boolean, ...data: any[]): void;
|
|
40
|
+
(value: any, message?: string, ...optionalParams: any[]): void;
|
|
41
|
+
};
|
|
42
|
+
readonly clear: {
|
|
43
|
+
(): void;
|
|
44
|
+
(): void;
|
|
45
|
+
};
|
|
46
|
+
readonly count: {
|
|
47
|
+
(label?: string): void;
|
|
48
|
+
(label?: string): void;
|
|
49
|
+
};
|
|
50
|
+
readonly countReset: {
|
|
51
|
+
(label?: string): void;
|
|
52
|
+
(label?: string): void;
|
|
53
|
+
};
|
|
54
|
+
readonly debug: {
|
|
55
|
+
(...data: any[]): void;
|
|
56
|
+
(message?: any, ...optionalParams: any[]): void;
|
|
57
|
+
};
|
|
58
|
+
readonly dir: {
|
|
59
|
+
(item?: any, options?: any): void;
|
|
60
|
+
(obj: any, options?: import("util").InspectOptions): void;
|
|
61
|
+
};
|
|
62
|
+
readonly dirxml: {
|
|
63
|
+
(...data: any[]): void;
|
|
64
|
+
(...data: any[]): void;
|
|
65
|
+
};
|
|
66
|
+
readonly error: {
|
|
67
|
+
(...data: any[]): void;
|
|
68
|
+
(message?: any, ...optionalParams: any[]): void;
|
|
69
|
+
};
|
|
70
|
+
readonly group: {
|
|
71
|
+
(...data: any[]): void;
|
|
72
|
+
(...label: any[]): void;
|
|
73
|
+
};
|
|
74
|
+
readonly groupCollapsed: {
|
|
75
|
+
(...data: any[]): void;
|
|
76
|
+
(...label: any[]): void;
|
|
77
|
+
};
|
|
78
|
+
readonly groupEnd: {
|
|
79
|
+
(): void;
|
|
80
|
+
(): void;
|
|
81
|
+
};
|
|
82
|
+
readonly info: {
|
|
83
|
+
(...data: any[]): void;
|
|
84
|
+
(message?: any, ...optionalParams: any[]): void;
|
|
85
|
+
};
|
|
86
|
+
readonly log: {
|
|
87
|
+
(...data: any[]): void;
|
|
88
|
+
(message?: any, ...optionalParams: any[]): void;
|
|
89
|
+
};
|
|
90
|
+
readonly table: {
|
|
91
|
+
(tabularData?: any, properties?: string[]): void;
|
|
92
|
+
(tabularData: any, properties?: readonly string[]): void;
|
|
93
|
+
};
|
|
94
|
+
readonly time: {
|
|
95
|
+
(label?: string): void;
|
|
96
|
+
(label?: string): void;
|
|
97
|
+
};
|
|
98
|
+
readonly timeEnd: {
|
|
99
|
+
(label?: string): void;
|
|
100
|
+
(label?: string): void;
|
|
101
|
+
};
|
|
102
|
+
readonly timeLog: {
|
|
103
|
+
(label?: string, ...data: any[]): void;
|
|
104
|
+
(label?: string, ...data: any[]): void;
|
|
105
|
+
};
|
|
106
|
+
readonly timeStamp: {
|
|
107
|
+
(label?: string): void;
|
|
108
|
+
(label?: string): void;
|
|
109
|
+
};
|
|
110
|
+
readonly trace: {
|
|
111
|
+
(...data: any[]): void;
|
|
112
|
+
(message?: any, ...optionalParams: any[]): void;
|
|
113
|
+
};
|
|
114
|
+
readonly warn: {
|
|
115
|
+
(...data: any[]): void;
|
|
116
|
+
(message?: any, ...optionalParams: any[]): void;
|
|
117
|
+
};
|
|
118
|
+
readonly Console: console.ConsoleConstructor;
|
|
119
|
+
readonly profile: (label?: string) => void;
|
|
120
|
+
readonly profileEnd: (label?: string) => void;
|
|
121
|
+
};
|
|
122
|
+
/**
|
|
123
|
+
* Patch `console` APIs within workers to forward their messages to the Logger
|
|
124
|
+
* at the appropriate levels.
|
|
125
|
+
* @private
|
|
126
|
+
*/
|
|
127
|
+
export declare function patchConsole(): void;
|
|
128
|
+
/** @private */
|
|
129
|
+
export declare function unpatchConsole(): void;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaspack/logger",
|
|
3
|
-
"version": "2.14.5-canary.
|
|
3
|
+
"version": "2.14.5-canary.380+5755a1149",
|
|
4
4
|
"description": "Blazing fast, zero configuration web application bundler",
|
|
5
5
|
"license": "(MIT OR Apache-2.0)",
|
|
6
6
|
"publishConfig": {
|
|
@@ -10,22 +10,21 @@
|
|
|
10
10
|
"type": "git",
|
|
11
11
|
"url": "https://github.com/atlassian-labs/atlaspack.git"
|
|
12
12
|
},
|
|
13
|
-
"main": "lib/Logger.js",
|
|
14
|
-
"source": "src/Logger.
|
|
15
|
-
"
|
|
16
|
-
".": {
|
|
17
|
-
"@atlaspack::sources": "./src/Logger.js",
|
|
18
|
-
"default": "./lib/Logger.js"
|
|
19
|
-
}
|
|
20
|
-
},
|
|
13
|
+
"main": "./lib/Logger.js",
|
|
14
|
+
"source": "./src/Logger.ts",
|
|
15
|
+
"types": "./lib/types/Logger.d.ts",
|
|
21
16
|
"engines": {
|
|
22
17
|
"node": ">= 16.0.0"
|
|
23
18
|
},
|
|
24
19
|
"dependencies": {
|
|
25
|
-
"@atlaspack/diagnostic": "2.14.1-canary.
|
|
26
|
-
"@atlaspack/events": "2.14.1-canary.
|
|
27
|
-
"@atlaspack/rust": "3.2.1-canary.
|
|
20
|
+
"@atlaspack/diagnostic": "2.14.1-canary.448+5755a1149",
|
|
21
|
+
"@atlaspack/events": "2.14.1-canary.448+5755a1149",
|
|
22
|
+
"@atlaspack/rust": "3.2.1-canary.380+5755a1149",
|
|
23
|
+
"@atlaspack/types-internal": "2.14.1-canary.448+5755a1149"
|
|
28
24
|
},
|
|
29
25
|
"type": "commonjs",
|
|
30
|
-
"
|
|
31
|
-
|
|
26
|
+
"scripts": {
|
|
27
|
+
"build:lib": "gulp build --gulpfile ../../../gulpfile.js --cwd ."
|
|
28
|
+
},
|
|
29
|
+
"gitHead": "5755a114903bbf660e2ada3ae2e7ff6ceac7565b"
|
|
30
|
+
}
|
|
@@ -1,10 +1,8 @@
|
|
|
1
|
-
// @flow strict-local
|
|
2
|
-
|
|
3
1
|
import type {
|
|
4
2
|
IDisposable,
|
|
5
3
|
LogEvent,
|
|
6
4
|
PluginLogger as IPluginLogger,
|
|
7
|
-
} from '@atlaspack/types';
|
|
5
|
+
} from '@atlaspack/types-internal';
|
|
8
6
|
import type {
|
|
9
7
|
Diagnostic,
|
|
10
8
|
Diagnostifiable,
|
|
@@ -18,14 +16,14 @@ import {errorToDiagnostic, anyToDiagnostic} from '@atlaspack/diagnostic';
|
|
|
18
16
|
export {instrument, instrumentAsync} from './tracer';
|
|
19
17
|
|
|
20
18
|
class Logger {
|
|
21
|
-
|
|
19
|
+
logEmitter: ValueEmitter<LogEvent> = new ValueEmitter();
|
|
22
20
|
|
|
23
|
-
onLog(cb: (event: LogEvent) =>
|
|
24
|
-
return this
|
|
21
|
+
onLog(cb: (event: LogEvent) => unknown): IDisposable {
|
|
22
|
+
return this.logEmitter.addListener(cb);
|
|
25
23
|
}
|
|
26
24
|
|
|
27
25
|
verbose(diagnostic: Diagnostic | Array<Diagnostic>): void {
|
|
28
|
-
this
|
|
26
|
+
this.logEmitter.emit({
|
|
29
27
|
type: 'log',
|
|
30
28
|
level: 'verbose',
|
|
31
29
|
diagnostics: Array.isArray(diagnostic) ? diagnostic : [diagnostic],
|
|
@@ -37,7 +35,7 @@ class Logger {
|
|
|
37
35
|
}
|
|
38
36
|
|
|
39
37
|
log(diagnostic: Diagnostic | Array<Diagnostic>): void {
|
|
40
|
-
this
|
|
38
|
+
this.logEmitter.emit({
|
|
41
39
|
type: 'log',
|
|
42
40
|
level: 'info',
|
|
43
41
|
diagnostics: Array.isArray(diagnostic) ? diagnostic : [diagnostic],
|
|
@@ -45,7 +43,7 @@ class Logger {
|
|
|
45
43
|
}
|
|
46
44
|
|
|
47
45
|
warn(diagnostic: Diagnostic | Array<Diagnostic>): void {
|
|
48
|
-
this
|
|
46
|
+
this.logEmitter.emit({
|
|
49
47
|
type: 'log',
|
|
50
48
|
level: 'warn',
|
|
51
49
|
diagnostics: Array.isArray(diagnostic) ? diagnostic : [diagnostic],
|
|
@@ -53,7 +51,7 @@ class Logger {
|
|
|
53
51
|
}
|
|
54
52
|
|
|
55
53
|
error(input: Diagnostifiable, realOrigin?: string): void {
|
|
56
|
-
let diagnostic = anyToDiagnostic(input)
|
|
54
|
+
let diagnostic = anyToDiagnostic(input) as Diagnostic | Array<Diagnostic>;
|
|
57
55
|
if (typeof realOrigin === 'string') {
|
|
58
56
|
diagnostic = Array.isArray(diagnostic)
|
|
59
57
|
? diagnostic.map((d) => {
|
|
@@ -65,7 +63,7 @@ class Logger {
|
|
|
65
63
|
};
|
|
66
64
|
}
|
|
67
65
|
|
|
68
|
-
this
|
|
66
|
+
this.logEmitter.emit({
|
|
69
67
|
type: 'log',
|
|
70
68
|
level: 'error',
|
|
71
69
|
diagnostics: Array.isArray(diagnostic) ? diagnostic : [diagnostic],
|
|
@@ -73,7 +71,7 @@ class Logger {
|
|
|
73
71
|
}
|
|
74
72
|
|
|
75
73
|
progress(message: string): void {
|
|
76
|
-
this
|
|
74
|
+
this.logEmitter.emit({
|
|
77
75
|
type: 'log',
|
|
78
76
|
level: 'progress',
|
|
79
77
|
message,
|
|
@@ -85,9 +83,9 @@ const logger: Logger = new Logger();
|
|
|
85
83
|
export default logger;
|
|
86
84
|
|
|
87
85
|
/** @private */
|
|
88
|
-
export type PluginLoggerOpts = {
|
|
89
|
-
origin: string
|
|
90
|
-
|
|
86
|
+
export type PluginLoggerOpts = {
|
|
87
|
+
origin: string;
|
|
88
|
+
};
|
|
91
89
|
|
|
92
90
|
export class PluginLogger implements IPluginLogger {
|
|
93
91
|
/** @private */
|
|
@@ -106,7 +104,7 @@ export class PluginLogger implements IPluginLogger {
|
|
|
106
104
|
? diagnostic.map((d) => {
|
|
107
105
|
return {...d, origin: this.origin};
|
|
108
106
|
})
|
|
109
|
-
: {...diagnostic, origin: this.origin};
|
|
107
|
+
: ({...diagnostic, origin: this.origin} as Diagnostic);
|
|
110
108
|
}
|
|
111
109
|
|
|
112
110
|
verbose(
|
|
@@ -149,7 +147,7 @@ export class PluginLogger implements IPluginLogger {
|
|
|
149
147
|
}
|
|
150
148
|
|
|
151
149
|
/** @private */
|
|
152
|
-
export const INTERNAL_ORIGINAL_CONSOLE = {...console};
|
|
150
|
+
export const INTERNAL_ORIGINAL_CONSOLE = {...console} as const;
|
|
153
151
|
let consolePatched = false;
|
|
154
152
|
|
|
155
153
|
/**
|
|
@@ -162,24 +160,20 @@ export function patchConsole() {
|
|
|
162
160
|
if (consolePatched) return;
|
|
163
161
|
|
|
164
162
|
/* eslint-disable no-console */
|
|
165
|
-
|
|
166
|
-
console.log = console.info = (...messages: Array<mixed>) => {
|
|
163
|
+
console.log = console.info = (...messages: Array<unknown>) => {
|
|
167
164
|
logger.info(messagesToDiagnostic(messages));
|
|
168
165
|
};
|
|
169
166
|
|
|
170
|
-
|
|
171
|
-
console.debug = (...messages: Array<mixed>) => {
|
|
167
|
+
console.debug = (...messages: Array<unknown>) => {
|
|
172
168
|
// TODO: dedicated debug level?
|
|
173
169
|
logger.verbose(messagesToDiagnostic(messages));
|
|
174
170
|
};
|
|
175
171
|
|
|
176
|
-
|
|
177
|
-
console.warn = (...messages: Array<mixed>) => {
|
|
172
|
+
console.warn = (...messages: Array<unknown>) => {
|
|
178
173
|
logger.warn(messagesToDiagnostic(messages));
|
|
179
174
|
};
|
|
180
175
|
|
|
181
|
-
|
|
182
|
-
console.error = (...messages: Array<mixed>) => {
|
|
176
|
+
console.error = (...messages: Array<unknown>) => {
|
|
183
177
|
logger.error(messagesToDiagnostic(messages));
|
|
184
178
|
};
|
|
185
179
|
|
|
@@ -193,19 +187,14 @@ export function unpatchConsole() {
|
|
|
193
187
|
if (!consolePatched) return;
|
|
194
188
|
|
|
195
189
|
/* eslint-disable no-console */
|
|
196
|
-
// $FlowFixMe
|
|
197
190
|
console.log = INTERNAL_ORIGINAL_CONSOLE.log;
|
|
198
191
|
|
|
199
|
-
// $FlowFixMe
|
|
200
192
|
console.info = INTERNAL_ORIGINAL_CONSOLE.info;
|
|
201
193
|
|
|
202
|
-
// $FlowFixMe
|
|
203
194
|
console.debug = INTERNAL_ORIGINAL_CONSOLE.debug;
|
|
204
195
|
|
|
205
|
-
// $FlowFixMe
|
|
206
196
|
console.warn = INTERNAL_ORIGINAL_CONSOLE.warn;
|
|
207
197
|
|
|
208
|
-
// $FlowFixMe
|
|
209
198
|
console.error = INTERNAL_ORIGINAL_CONSOLE.error;
|
|
210
199
|
|
|
211
200
|
/* eslint-enable no-console */
|
|
@@ -213,11 +202,11 @@ export function unpatchConsole() {
|
|
|
213
202
|
}
|
|
214
203
|
|
|
215
204
|
function messagesToDiagnostic(
|
|
216
|
-
messages: Array<
|
|
205
|
+
messages: Array<unknown>,
|
|
217
206
|
): Diagnostic | Array<Diagnostic> {
|
|
218
207
|
if (messages.length === 1 && messages[0] instanceof Error) {
|
|
219
208
|
let error: Error = messages[0];
|
|
220
|
-
let diagnostic = errorToDiagnostic(error)
|
|
209
|
+
let diagnostic = errorToDiagnostic(error) as Diagnostic | Array<Diagnostic>;
|
|
221
210
|
|
|
222
211
|
if (Array.isArray(diagnostic)) {
|
|
223
212
|
return diagnostic.map((d) => {
|
|
@@ -241,7 +230,7 @@ function messagesToDiagnostic(
|
|
|
241
230
|
}
|
|
242
231
|
}
|
|
243
232
|
|
|
244
|
-
function joinLogMessages(messages: Array<
|
|
233
|
+
function joinLogMessages(messages: Array<unknown>): string {
|
|
245
234
|
return messages
|
|
246
235
|
.map((m) => (typeof m === 'string' ? m : inspect(m)))
|
|
247
236
|
.join(' ');
|
|
@@ -1,12 +1,10 @@
|
|
|
1
|
-
// @flow strict-local
|
|
2
|
-
|
|
3
1
|
import assert from 'assert';
|
|
4
2
|
import sinon from 'sinon';
|
|
5
3
|
import Logger from '../src/Logger';
|
|
6
4
|
|
|
7
5
|
describe('Logger', () => {
|
|
8
|
-
let onLog;
|
|
9
|
-
let logDisposable;
|
|
6
|
+
let onLog: any;
|
|
7
|
+
let logDisposable: any;
|
|
10
8
|
beforeEach(() => {
|
|
11
9
|
onLog = sinon.spy();
|
|
12
10
|
logDisposable = Logger.onLog(onLog);
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
{
|
|
2
|
+
"extends": "../../../tsconfig.base.json",
|
|
3
|
+
"include": ["src"],
|
|
4
|
+
"compilerOptions": {
|
|
5
|
+
"composite": true
|
|
6
|
+
},
|
|
7
|
+
"references": [
|
|
8
|
+
{
|
|
9
|
+
"path": "../../utils/events/tsconfig.json"
|
|
10
|
+
},
|
|
11
|
+
{
|
|
12
|
+
"path": "../diagnostic/tsconfig.json"
|
|
13
|
+
},
|
|
14
|
+
{
|
|
15
|
+
"path": "../rust/tsconfig.json"
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
"path": "../types-internal/tsconfig.json"
|
|
19
|
+
}
|
|
20
|
+
]
|
|
21
|
+
}
|