@x-oasis/log 0.1.1 → 0.1.3
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/README.md +4 -0
- package/package.json +15 -1
- package/.turbo/turbo-build.log +0 -26
- package/CHANGELOG.md +0 -17
- package/test/test.spec.ts +0 -333
- package/tsconfig.build.json +0 -11
- package/tsconfig.json +0 -7
- package/vitest.config.ts +0 -21
package/README.md
CHANGED
|
@@ -335,6 +335,10 @@ This library is designed to work in all modern browsers. It uses standard browse
|
|
|
335
335
|
|
|
336
336
|
Full TypeScript support with comprehensive type definitions included.
|
|
337
337
|
|
|
338
|
+
## Reading More
|
|
339
|
+
- [loglayer](https://github.com/loglayer/loglayer)
|
|
340
|
+
- [loglevel](https://github.com/pimterry/loglevel)
|
|
341
|
+
|
|
338
342
|
## License
|
|
339
343
|
|
|
340
344
|
ISC
|
package/package.json
CHANGED
|
@@ -1,10 +1,24 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@x-oasis/log",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.3",
|
|
4
4
|
"description": "A friendly logging library for browser environments",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"typings": "dist/index.d.ts",
|
|
7
7
|
"module": "dist/log.esm.js",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"import": "./dist/log.esm.js",
|
|
12
|
+
"require": "./dist/index.js",
|
|
13
|
+
"default": "./dist/index.js"
|
|
14
|
+
},
|
|
15
|
+
"./package.json": "./package.json"
|
|
16
|
+
},
|
|
17
|
+
"files": [
|
|
18
|
+
"dist",
|
|
19
|
+
"index.ts",
|
|
20
|
+
"src"
|
|
21
|
+
],
|
|
8
22
|
"publishConfig": {
|
|
9
23
|
"access": "public"
|
|
10
24
|
},
|
package/.turbo/turbo-build.log
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
> @x-oasis/log@0.1.1 build /home/runner/work/x-oasis/x-oasis/packages/error/log
|
|
3
|
-
> tsdx build --tsconfig tsconfig.build.json
|
|
4
|
-
|
|
5
|
-
@rollup/plugin-replace: 'preventAssignment' currently defaults to false. It is recommended to set this option to `true`, as the next major version will default this option to `true`.
|
|
6
|
-
@rollup/plugin-replace: 'preventAssignment' currently defaults to false. It is recommended to set this option to `true`, as the next major version will default this option to `true`.
|
|
7
|
-
⠙ Creating entry file
|
|
8
|
-
[2K[1A[2K[G⠙ Building modules
|
|
9
|
-
[2K[1A[2K[G✓ Creating entry file 4.5 secs
|
|
10
|
-
⠹ Building modules
|
|
11
|
-
[2K[1A[2K[G⠸ Building modules
|
|
12
|
-
[2K[1A[2K[G⠼ Building modules
|
|
13
|
-
[2K[1A[2K[G⠴ Building modules
|
|
14
|
-
[2K[1A[2K[G⠦ Building modules
|
|
15
|
-
[2K[1A[2K[G⠧ Building modules
|
|
16
|
-
[2K[1A[2K[G⠇ Building modules
|
|
17
|
-
[2K[1A[2K[G⠏ Building modules
|
|
18
|
-
[2K[1A[2K[G⠋ Building modules
|
|
19
|
-
[2K[1A[2K[G⠙ Building modules
|
|
20
|
-
[2K[1A[2K[G⠹ Building modules
|
|
21
|
-
[2K[1A[2K[G⠸ Building modules
|
|
22
|
-
[2K[1A[2K[G⠼ Building modules
|
|
23
|
-
[tsdx]: Your rootDir is currently set to "./". Please change your rootDir to "./src".
|
|
24
|
-
TSDX has deprecated setting tsconfig.compilerOptions.rootDir to "./" as it caused buggy output for declarationMaps and more.
|
|
25
|
-
You may also need to change your include to remove "test", which also caused declarations to be unnecessarily created for test files.
|
|
26
|
-
[2K[1A[2K[G✓ Building modules 14.7 secs
|
package/CHANGELOG.md
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
# @x-oasis/log
|
|
2
|
-
|
|
3
|
-
## 0.1.1
|
|
4
|
-
|
|
5
|
-
### Patch Changes
|
|
6
|
-
|
|
7
|
-
- f1aae14: bump version
|
|
8
|
-
|
|
9
|
-
## 0.1.0
|
|
10
|
-
|
|
11
|
-
### Initial Release
|
|
12
|
-
|
|
13
|
-
- Initial release of the log library
|
|
14
|
-
- Support for multiple log levels (trace, debug, info, warn, error)
|
|
15
|
-
- Browser-friendly API with chainable methods
|
|
16
|
-
- Context and metadata support
|
|
17
|
-
- Configurable log levels and output handlers
|
package/test/test.spec.ts
DELETED
|
@@ -1,333 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
|
2
|
-
import { Logger, LogLevel } from '../src';
|
|
3
|
-
// import { log } from '../src';
|
|
4
|
-
|
|
5
|
-
describe('Logger', () => {
|
|
6
|
-
let mockHandler: ReturnType<typeof vi.fn>;
|
|
7
|
-
let logger: Logger;
|
|
8
|
-
|
|
9
|
-
beforeEach(() => {
|
|
10
|
-
mockHandler = vi.fn();
|
|
11
|
-
logger = new Logger({
|
|
12
|
-
handler: mockHandler,
|
|
13
|
-
enableTimestamp: false,
|
|
14
|
-
});
|
|
15
|
-
});
|
|
16
|
-
|
|
17
|
-
describe('Basic logging', () => {
|
|
18
|
-
it('should log at trace level', () => {
|
|
19
|
-
logger.setLevel(LogLevel.TRACE);
|
|
20
|
-
logger.trace('test message');
|
|
21
|
-
|
|
22
|
-
expect(mockHandler).toHaveBeenCalledTimes(1);
|
|
23
|
-
expect(mockHandler).toHaveBeenCalledWith(
|
|
24
|
-
expect.objectContaining({
|
|
25
|
-
level: LogLevel.TRACE,
|
|
26
|
-
message: 'test message',
|
|
27
|
-
})
|
|
28
|
-
);
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
it('should log at debug level', () => {
|
|
32
|
-
logger.setLevel(LogLevel.DEBUG);
|
|
33
|
-
logger.debug('test message');
|
|
34
|
-
|
|
35
|
-
expect(mockHandler).toHaveBeenCalledTimes(1);
|
|
36
|
-
expect(mockHandler).toHaveBeenCalledWith(
|
|
37
|
-
expect.objectContaining({
|
|
38
|
-
level: LogLevel.DEBUG,
|
|
39
|
-
message: 'test message',
|
|
40
|
-
})
|
|
41
|
-
);
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
it('should log at info level', () => {
|
|
45
|
-
logger.info('test message');
|
|
46
|
-
|
|
47
|
-
expect(mockHandler).toHaveBeenCalledTimes(1);
|
|
48
|
-
expect(mockHandler).toHaveBeenCalledWith(
|
|
49
|
-
expect.objectContaining({
|
|
50
|
-
level: LogLevel.INFO,
|
|
51
|
-
message: 'test message',
|
|
52
|
-
})
|
|
53
|
-
);
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
it('should log at warn level', () => {
|
|
57
|
-
logger.warn('test message');
|
|
58
|
-
|
|
59
|
-
expect(mockHandler).toHaveBeenCalledTimes(1);
|
|
60
|
-
expect(mockHandler).toHaveBeenCalledWith(
|
|
61
|
-
expect.objectContaining({
|
|
62
|
-
level: LogLevel.WARN,
|
|
63
|
-
message: 'test message',
|
|
64
|
-
})
|
|
65
|
-
);
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
it('should log at error level', () => {
|
|
69
|
-
logger.error('test message');
|
|
70
|
-
|
|
71
|
-
expect(mockHandler).toHaveBeenCalledTimes(1);
|
|
72
|
-
expect(mockHandler).toHaveBeenCalledWith(
|
|
73
|
-
expect.objectContaining({
|
|
74
|
-
level: LogLevel.ERROR,
|
|
75
|
-
message: 'test message',
|
|
76
|
-
})
|
|
77
|
-
);
|
|
78
|
-
});
|
|
79
|
-
});
|
|
80
|
-
|
|
81
|
-
describe('Log level filtering', () => {
|
|
82
|
-
it('should not log messages below the set level', () => {
|
|
83
|
-
logger.setLevel(LogLevel.WARN);
|
|
84
|
-
logger.trace('trace message');
|
|
85
|
-
logger.debug('debug message');
|
|
86
|
-
logger.info('info message');
|
|
87
|
-
|
|
88
|
-
expect(mockHandler).not.toHaveBeenCalled();
|
|
89
|
-
|
|
90
|
-
logger.warn('warn message');
|
|
91
|
-
logger.error('error message');
|
|
92
|
-
|
|
93
|
-
expect(mockHandler).toHaveBeenCalledTimes(2);
|
|
94
|
-
});
|
|
95
|
-
|
|
96
|
-
it('should log all messages when level is TRACE', () => {
|
|
97
|
-
logger.setLevel(LogLevel.TRACE);
|
|
98
|
-
logger.trace('trace');
|
|
99
|
-
logger.debug('debug');
|
|
100
|
-
logger.info('info');
|
|
101
|
-
logger.warn('warn');
|
|
102
|
-
logger.error('error');
|
|
103
|
-
|
|
104
|
-
expect(mockHandler).toHaveBeenCalledTimes(5);
|
|
105
|
-
});
|
|
106
|
-
});
|
|
107
|
-
|
|
108
|
-
describe('Context support', () => {
|
|
109
|
-
it('should include context in log entries', () => {
|
|
110
|
-
logger.info('test message', { userId: '123', action: 'login' });
|
|
111
|
-
|
|
112
|
-
expect(mockHandler).toHaveBeenCalledWith(
|
|
113
|
-
expect.objectContaining({
|
|
114
|
-
context: {
|
|
115
|
-
userId: '123',
|
|
116
|
-
action: 'login',
|
|
117
|
-
},
|
|
118
|
-
})
|
|
119
|
-
);
|
|
120
|
-
});
|
|
121
|
-
|
|
122
|
-
it('should merge default context with provided context', () => {
|
|
123
|
-
logger.setDefaultContext({ app: 'my-app', version: '1.0.0' });
|
|
124
|
-
logger.info('test message', { userId: '123' });
|
|
125
|
-
|
|
126
|
-
expect(mockHandler).toHaveBeenCalledWith(
|
|
127
|
-
expect.objectContaining({
|
|
128
|
-
context: {
|
|
129
|
-
app: 'my-app',
|
|
130
|
-
version: '1.0.0',
|
|
131
|
-
userId: '123',
|
|
132
|
-
},
|
|
133
|
-
})
|
|
134
|
-
);
|
|
135
|
-
});
|
|
136
|
-
});
|
|
137
|
-
|
|
138
|
-
describe('Chainable API', () => {
|
|
139
|
-
it('should support chaining with context', () => {
|
|
140
|
-
logger
|
|
141
|
-
.chain()
|
|
142
|
-
.withContext({ userId: '123' })
|
|
143
|
-
.withContext({ action: 'login' })
|
|
144
|
-
.info('User logged in');
|
|
145
|
-
|
|
146
|
-
expect(mockHandler).toHaveBeenCalledWith(
|
|
147
|
-
expect.objectContaining({
|
|
148
|
-
context: {
|
|
149
|
-
userId: '123',
|
|
150
|
-
action: 'login',
|
|
151
|
-
},
|
|
152
|
-
message: 'User logged in',
|
|
153
|
-
})
|
|
154
|
-
);
|
|
155
|
-
});
|
|
156
|
-
|
|
157
|
-
it('should support chaining with metadata', () => {
|
|
158
|
-
logger
|
|
159
|
-
.chain()
|
|
160
|
-
.withMetadata({ duration: 150, status: 'success' })
|
|
161
|
-
.info('Request completed');
|
|
162
|
-
|
|
163
|
-
expect(mockHandler).toHaveBeenCalledWith(
|
|
164
|
-
expect.objectContaining({
|
|
165
|
-
metadata: {
|
|
166
|
-
duration: 150,
|
|
167
|
-
status: 'success',
|
|
168
|
-
},
|
|
169
|
-
message: 'Request completed',
|
|
170
|
-
})
|
|
171
|
-
);
|
|
172
|
-
});
|
|
173
|
-
|
|
174
|
-
it('should support chaining with error', () => {
|
|
175
|
-
const error = new Error('Something went wrong');
|
|
176
|
-
logger.chain().withError(error).error('Operation failed');
|
|
177
|
-
|
|
178
|
-
expect(mockHandler).toHaveBeenCalledWith(
|
|
179
|
-
expect.objectContaining({
|
|
180
|
-
error,
|
|
181
|
-
message: 'Operation failed',
|
|
182
|
-
})
|
|
183
|
-
);
|
|
184
|
-
});
|
|
185
|
-
|
|
186
|
-
it('should support chaining with prefix', () => {
|
|
187
|
-
logger.chain().withPrefix('[API]').info('Request received');
|
|
188
|
-
|
|
189
|
-
expect(mockHandler).toHaveBeenCalledWith(
|
|
190
|
-
expect.objectContaining({
|
|
191
|
-
prefix: '[API]',
|
|
192
|
-
message: 'Request received',
|
|
193
|
-
})
|
|
194
|
-
);
|
|
195
|
-
});
|
|
196
|
-
|
|
197
|
-
it('should support complex chaining', () => {
|
|
198
|
-
const error = new Error('Validation failed');
|
|
199
|
-
logger
|
|
200
|
-
.chain()
|
|
201
|
-
.withContext({ userId: '123' })
|
|
202
|
-
.withMetadata({ field: 'email', value: 'invalid' })
|
|
203
|
-
.withError(error)
|
|
204
|
-
.withPrefix('[VALIDATION]')
|
|
205
|
-
.warn('Validation error');
|
|
206
|
-
|
|
207
|
-
expect(mockHandler).toHaveBeenCalledWith(
|
|
208
|
-
expect.objectContaining({
|
|
209
|
-
context: { userId: '123' },
|
|
210
|
-
metadata: { field: 'email', value: 'invalid' },
|
|
211
|
-
error,
|
|
212
|
-
prefix: '[VALIDATION]',
|
|
213
|
-
message: 'Validation error',
|
|
214
|
-
})
|
|
215
|
-
);
|
|
216
|
-
});
|
|
217
|
-
});
|
|
218
|
-
|
|
219
|
-
describe('withContext and withPrefix methods', () => {
|
|
220
|
-
it('should create chainable logger with context', () => {
|
|
221
|
-
logger.withContext({ userId: '123' }).info('User action');
|
|
222
|
-
|
|
223
|
-
expect(mockHandler).toHaveBeenCalledWith(
|
|
224
|
-
expect.objectContaining({
|
|
225
|
-
context: { userId: '123' },
|
|
226
|
-
})
|
|
227
|
-
);
|
|
228
|
-
});
|
|
229
|
-
|
|
230
|
-
it('should create chainable logger with prefix', () => {
|
|
231
|
-
logger.withPrefix('[APP]').info('Application started');
|
|
232
|
-
|
|
233
|
-
expect(mockHandler).toHaveBeenCalledWith(
|
|
234
|
-
expect.objectContaining({
|
|
235
|
-
prefix: '[APP]',
|
|
236
|
-
})
|
|
237
|
-
);
|
|
238
|
-
});
|
|
239
|
-
});
|
|
240
|
-
|
|
241
|
-
describe('Default prefix', () => {
|
|
242
|
-
it('should include default prefix in all logs', () => {
|
|
243
|
-
logger.setDefaultPrefix('[MY-APP]');
|
|
244
|
-
logger.info('Test message');
|
|
245
|
-
|
|
246
|
-
expect(mockHandler).toHaveBeenCalledWith(
|
|
247
|
-
expect.objectContaining({
|
|
248
|
-
prefix: '[MY-APP]',
|
|
249
|
-
})
|
|
250
|
-
);
|
|
251
|
-
});
|
|
252
|
-
|
|
253
|
-
it('should allow overriding default prefix with chain prefix', () => {
|
|
254
|
-
logger.setDefaultPrefix('[DEFAULT]');
|
|
255
|
-
logger.chain().withPrefix('[OVERRIDE]').info('Test message');
|
|
256
|
-
|
|
257
|
-
expect(mockHandler).toHaveBeenCalledWith(
|
|
258
|
-
expect.objectContaining({
|
|
259
|
-
prefix: '[OVERRIDE]',
|
|
260
|
-
})
|
|
261
|
-
);
|
|
262
|
-
});
|
|
263
|
-
});
|
|
264
|
-
|
|
265
|
-
describe('Timestamp', () => {
|
|
266
|
-
it('should include timestamp when enabled', () => {
|
|
267
|
-
const loggerWithTimestamp = new Logger({
|
|
268
|
-
handler: mockHandler,
|
|
269
|
-
enableTimestamp: true,
|
|
270
|
-
});
|
|
271
|
-
loggerWithTimestamp.info('test');
|
|
272
|
-
|
|
273
|
-
const call = mockHandler.mock.calls[0][0];
|
|
274
|
-
expect(call.timestamp).toBeGreaterThan(0);
|
|
275
|
-
});
|
|
276
|
-
|
|
277
|
-
it('should not include timestamp when disabled', () => {
|
|
278
|
-
logger.info('test');
|
|
279
|
-
|
|
280
|
-
const call = mockHandler.mock.calls[0][0];
|
|
281
|
-
expect(call.timestamp).toBe(0);
|
|
282
|
-
});
|
|
283
|
-
});
|
|
284
|
-
|
|
285
|
-
describe('Log level string parsing', () => {
|
|
286
|
-
it('should accept log level as string', () => {
|
|
287
|
-
logger.setLevel('DEBUG');
|
|
288
|
-
logger.setLevel('WARN');
|
|
289
|
-
logger.setLevel('ERROR');
|
|
290
|
-
|
|
291
|
-
expect(logger.getLevel()).toBe(LogLevel.ERROR);
|
|
292
|
-
});
|
|
293
|
-
|
|
294
|
-
it('should default to INFO for invalid string', () => {
|
|
295
|
-
logger.setLevel('INVALID' as any);
|
|
296
|
-
expect(logger.getLevel()).toBe(LogLevel.INFO);
|
|
297
|
-
});
|
|
298
|
-
});
|
|
299
|
-
});
|
|
300
|
-
|
|
301
|
-
// describe('Default logger (log)', () => {
|
|
302
|
-
// it('should provide convenience methods', () => {
|
|
303
|
-
// const originalConsole = console.info;
|
|
304
|
-
// const mockConsole = vi.fn();
|
|
305
|
-
// console.info = mockConsole;
|
|
306
|
-
|
|
307
|
-
// try {
|
|
308
|
-
// log.info('test message');
|
|
309
|
-
// expect(mockConsole).toHaveBeenCalled();
|
|
310
|
-
// } finally {
|
|
311
|
-
// console.info = originalConsole;
|
|
312
|
-
// }
|
|
313
|
-
// });
|
|
314
|
-
|
|
315
|
-
// it('should support setLevel', () => {
|
|
316
|
-
// expect(() => log.setLevel(LogLevel.DEBUG)).not.toThrow();
|
|
317
|
-
// });
|
|
318
|
-
|
|
319
|
-
// it('should support withContext', () => {
|
|
320
|
-
// const chain = log.withContext({ test: 'value' });
|
|
321
|
-
// expect(chain).toBeDefined();
|
|
322
|
-
// });
|
|
323
|
-
|
|
324
|
-
// it('should support withPrefix', () => {
|
|
325
|
-
// const chain = log.withPrefix('[TEST]');
|
|
326
|
-
// expect(chain).toBeDefined();
|
|
327
|
-
// });
|
|
328
|
-
|
|
329
|
-
// it('should support chain', () => {
|
|
330
|
-
// const chain = log.chain();
|
|
331
|
-
// expect(chain).toBeDefined();
|
|
332
|
-
// });
|
|
333
|
-
// });
|
package/tsconfig.build.json
DELETED
package/tsconfig.json
DELETED
package/vitest.config.ts
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { defineConfig } from 'vitest/config';
|
|
2
|
-
|
|
3
|
-
export default defineConfig({
|
|
4
|
-
test: {
|
|
5
|
-
globals: true,
|
|
6
|
-
include: ['test/**/*.(spec|test).ts'],
|
|
7
|
-
exclude: ['node_modules/**'],
|
|
8
|
-
threads: false,
|
|
9
|
-
|
|
10
|
-
coverage: {
|
|
11
|
-
provider: 'istanbul',
|
|
12
|
-
},
|
|
13
|
-
},
|
|
14
|
-
|
|
15
|
-
resolve: {
|
|
16
|
-
alias: {},
|
|
17
|
-
},
|
|
18
|
-
define: {
|
|
19
|
-
__DEV__: false,
|
|
20
|
-
},
|
|
21
|
-
});
|