@atlaspack/logger 2.14.50 → 2.14.52

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
@@ -1,5 +1,21 @@
1
1
  # @atlaspack/logger
2
2
 
3
+ ## 2.14.52
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies [[`7d1839c`](https://github.com/atlassian-labs/atlaspack/commit/7d1839cc7cf0225dd35afecb68109a11fd931f2b)]:
8
+ - @atlaspack/rust@3.28.0
9
+ - @atlaspack/types-internal@2.25.2
10
+
11
+ ## 2.14.51
12
+
13
+ ### Patch Changes
14
+
15
+ - Updated dependencies [[`a958853`](https://github.com/atlassian-labs/atlaspack/commit/a958853ae3de2812bfd032357e9fa7cab6a1ddb6), [`0f5c1ef`](https://github.com/atlassian-labs/atlaspack/commit/0f5c1eff9138728168231efa66202a8d844c33ef)]:
16
+ - @atlaspack/rust@3.27.0
17
+ - @atlaspack/types-internal@2.25.1
18
+
3
19
  ## 2.14.50
4
20
 
5
21
  ### Patch Changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaspack/logger",
3
- "version": "2.14.50",
3
+ "version": "2.14.52",
4
4
  "description": "Blazing fast, zero configuration web application bundler",
5
5
  "license": "(MIT OR Apache-2.0)",
6
6
  "publishConfig": {
@@ -18,9 +18,9 @@
18
18
  },
19
19
  "dependencies": {
20
20
  "@atlaspack/diagnostic": "2.14.4",
21
- "@atlaspack/types-internal": "2.25.0",
21
+ "@atlaspack/types-internal": "2.25.2",
22
22
  "@atlaspack/events": "2.14.4",
23
- "@atlaspack/rust": "3.26.0"
23
+ "@atlaspack/rust": "3.28.0"
24
24
  },
25
25
  "type": "commonjs",
26
26
  "scripts": {
@@ -1,10 +1,14 @@
1
1
  import assert from 'assert';
2
2
  import sinon from 'sinon';
3
- import Logger from '../src/Logger';
3
+ import Logger, {PluginLogger} from '../src/Logger';
4
+ import type {LogEvent} from '@atlaspack/types-internal';
5
+
6
+ const ORIGIN = 'test-plugin';
4
7
 
5
8
  describe('Logger', () => {
6
- let onLog: any;
7
- let logDisposable: any;
9
+ let onLog: sinon.SinonSpy<[LogEvent]>;
10
+ let logDisposable: {dispose(): void};
11
+
8
12
  beforeEach(() => {
9
13
  onLog = sinon.spy();
10
14
  logDisposable = Logger.onLog(onLog);
@@ -14,49 +18,58 @@ describe('Logger', () => {
14
18
  logDisposable.dispose();
15
19
  });
16
20
 
17
- it('emits log diagnostics with info level', () => {
18
- let diagnostic = {
19
- message: 'hello',
20
- origin: 'logger',
21
- };
21
+ const diagnostic = {message: 'hello', origin: ORIGIN};
22
22
 
23
+ it('emits log diagnostics with info level', () => {
23
24
  Logger.log(diagnostic);
25
+ assert(
26
+ onLog.calledWith({type: 'log', level: 'info', diagnostics: [diagnostic]}),
27
+ );
28
+ });
24
29
 
30
+ it('emits info() diagnostics with info level', () => {
31
+ Logger.info(diagnostic);
32
+ assert(
33
+ onLog.calledWith({type: 'log', level: 'info', diagnostics: [diagnostic]}),
34
+ );
35
+ });
36
+
37
+ it('emits verbose() diagnostics with verbose level', () => {
38
+ Logger.verbose(diagnostic);
25
39
  assert(
26
40
  onLog.calledWith({
27
- level: 'info',
28
- diagnostics: [diagnostic],
29
41
  type: 'log',
42
+ level: 'verbose',
43
+ diagnostics: [diagnostic],
30
44
  }),
31
45
  );
32
46
  });
33
47
 
34
48
  it('emits warn diagnostic with warn level', () => {
35
- let diagnostic = {
36
- message: 'zomg',
37
- origin: 'logger',
38
- };
39
-
40
49
  Logger.warn(diagnostic);
41
-
42
50
  assert(
43
- onLog.calledWith({level: 'warn', diagnostics: [diagnostic], type: 'log'}),
51
+ onLog.calledWith({type: 'log', level: 'warn', diagnostics: [diagnostic]}),
44
52
  );
45
53
  });
46
54
 
47
55
  it('emits error messages with error level', () => {
48
- let diagnostic = {
49
- message: 'oh noes',
50
- origin: 'logger',
51
- };
52
-
53
56
  Logger.error(diagnostic);
54
-
55
57
  assert(
56
58
  onLog.calledWith({
59
+ type: 'log',
57
60
  level: 'error',
58
61
  diagnostics: [diagnostic],
62
+ }),
63
+ );
64
+ });
65
+
66
+ it('stamps origin on error() when realOrigin is provided', () => {
67
+ Logger.error({message: 'oops'}, ORIGIN);
68
+ assert(
69
+ onLog.calledWith({
59
70
  type: 'log',
71
+ level: 'error',
72
+ diagnostics: [{message: 'oops', origin: ORIGIN}],
60
73
  }),
61
74
  );
62
75
  });
@@ -64,7 +77,173 @@ describe('Logger', () => {
64
77
  it('emits progress messages with progress level', () => {
65
78
  Logger.progress('update');
66
79
  assert(
67
- onLog.calledWith({level: 'progress', message: 'update', type: 'log'}),
80
+ onLog.calledWith({type: 'log', level: 'progress', message: 'update'}),
68
81
  );
69
82
  });
70
83
  });
84
+
85
+ describe('PluginLogger', () => {
86
+ let onLog: sinon.SinonSpy<[LogEvent]>;
87
+ let logDisposable: {dispose(): void};
88
+
89
+ beforeEach(() => {
90
+ onLog = sinon.spy();
91
+ logDisposable = Logger.onLog(onLog);
92
+ });
93
+
94
+ afterEach(() => {
95
+ logDisposable.dispose();
96
+ });
97
+
98
+ const diagnostic = {message: 'test message'};
99
+ const diagnosticArray = [{message: 'first'}, {message: 'second'}];
100
+
101
+ describe('verbose()', () => {
102
+ it('forwards a single diagnostic at verbose level with origin', () => {
103
+ new PluginLogger({origin: ORIGIN}).verbose(diagnostic);
104
+ assert(
105
+ onLog.calledWith({
106
+ type: 'log',
107
+ level: 'verbose',
108
+ diagnostics: [{...diagnostic, origin: ORIGIN}],
109
+ }),
110
+ );
111
+ });
112
+
113
+ it('stamps origin on every diagnostic in an array', () => {
114
+ new PluginLogger({origin: ORIGIN}).verbose(diagnosticArray);
115
+ assert(
116
+ onLog.calledWith({
117
+ type: 'log',
118
+ level: 'verbose',
119
+ diagnostics: diagnosticArray.map((d) => ({...d, origin: ORIGIN})),
120
+ }),
121
+ );
122
+ });
123
+ });
124
+
125
+ describe('info()', () => {
126
+ it('forwards a single diagnostic at info level with origin', () => {
127
+ new PluginLogger({origin: ORIGIN}).info(diagnostic);
128
+ assert(
129
+ onLog.calledWith({
130
+ type: 'log',
131
+ level: 'info',
132
+ diagnostics: [{...diagnostic, origin: ORIGIN}],
133
+ }),
134
+ );
135
+ });
136
+
137
+ it('stamps origin on every diagnostic in an array', () => {
138
+ new PluginLogger({origin: ORIGIN}).info(diagnosticArray);
139
+ assert(
140
+ onLog.calledWith({
141
+ type: 'log',
142
+ level: 'info',
143
+ diagnostics: diagnosticArray.map((d) => ({...d, origin: ORIGIN})),
144
+ }),
145
+ );
146
+ });
147
+ });
148
+
149
+ describe('log()', () => {
150
+ it('forwards a single diagnostic at info level with origin', () => {
151
+ new PluginLogger({origin: ORIGIN}).log(diagnostic);
152
+ assert(
153
+ onLog.calledWith({
154
+ type: 'log',
155
+ level: 'info',
156
+ diagnostics: [{...diagnostic, origin: ORIGIN}],
157
+ }),
158
+ );
159
+ });
160
+
161
+ it('stamps origin on every diagnostic in an array', () => {
162
+ new PluginLogger({origin: ORIGIN}).log(diagnosticArray);
163
+ assert(
164
+ onLog.calledWith({
165
+ type: 'log',
166
+ level: 'info',
167
+ diagnostics: diagnosticArray.map((d) => ({...d, origin: ORIGIN})),
168
+ }),
169
+ );
170
+ });
171
+ });
172
+
173
+ describe('warn()', () => {
174
+ it('forwards a single diagnostic at warn level with origin', () => {
175
+ new PluginLogger({origin: ORIGIN}).warn(diagnostic);
176
+ assert(
177
+ onLog.calledWith({
178
+ type: 'log',
179
+ level: 'warn',
180
+ diagnostics: [{...diagnostic, origin: ORIGIN}],
181
+ }),
182
+ );
183
+ });
184
+
185
+ it('stamps origin on every diagnostic in an array', () => {
186
+ new PluginLogger({origin: ORIGIN}).warn(diagnosticArray);
187
+ assert(
188
+ onLog.calledWith({
189
+ type: 'log',
190
+ level: 'warn',
191
+ diagnostics: diagnosticArray.map((d) => ({...d, origin: ORIGIN})),
192
+ }),
193
+ );
194
+ });
195
+ });
196
+
197
+ describe('error()', () => {
198
+ it('forwards a diagnostic at error level with origin', () => {
199
+ new PluginLogger({origin: ORIGIN}).error(diagnostic);
200
+ assert(
201
+ onLog.calledWith({
202
+ type: 'log',
203
+ level: 'error',
204
+ diagnostics: [{...diagnostic, origin: ORIGIN}],
205
+ }),
206
+ );
207
+ });
208
+
209
+ it('stamps origin on every diagnostic in an array', () => {
210
+ new PluginLogger({origin: ORIGIN}).error(diagnosticArray);
211
+ assert(
212
+ onLog.calledWith({
213
+ type: 'log',
214
+ level: 'error',
215
+ diagnostics: diagnosticArray.map((d) => ({...d, origin: ORIGIN})),
216
+ }),
217
+ );
218
+ });
219
+
220
+ it('accepts a plain Error object and stamps origin', () => {
221
+ const err = new Error('something went wrong');
222
+ new PluginLogger({origin: ORIGIN}).error(err);
223
+ assert(onLog.calledOnce);
224
+ const event = onLog.firstCall.args[0];
225
+ assert.equal(event.type, 'log');
226
+ assert.equal(event.level, 'error');
227
+ assert.ok(Array.isArray(event.diagnostics));
228
+ assert.equal(event.diagnostics[0].message, 'something went wrong');
229
+ assert.equal(event.diagnostics[0].origin, ORIGIN);
230
+ });
231
+ });
232
+
233
+ it('does not bleed origin between instances', () => {
234
+ new PluginLogger({origin: 'plugin-a'}).info({message: 'from a'});
235
+ new PluginLogger({origin: 'plugin-b'}).info({message: 'from b'});
236
+
237
+ assert.equal(onLog.callCount, 2);
238
+ assert.equal(onLog.firstCall.args[0].diagnostics[0].origin, 'plugin-a');
239
+ assert.equal(onLog.secondCall.args[0].diagnostics[0].origin, 'plugin-b');
240
+ });
241
+
242
+ it('each method emits exactly once', () => {
243
+ for (const method of ['verbose', 'info', 'log', 'warn', 'error'] as const) {
244
+ onLog.resetHistory();
245
+ new PluginLogger({origin: ORIGIN})[method](diagnostic);
246
+ assert.equal(onLog.callCount, 1, `${method}() should emit exactly once`);
247
+ }
248
+ });
249
+ });