@x-oasis/log 0.1.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/.turbo/turbo-build.log +26 -0
- package/CHANGELOG.md +17 -0
- package/README.md +340 -0
- package/dist/index.d.ts +17 -0
- package/dist/index.js +8 -0
- package/dist/log.cjs.development.js +227 -0
- package/dist/log.cjs.development.js.map +1 -0
- package/dist/log.cjs.production.min.js +2 -0
- package/dist/log.cjs.production.min.js.map +1 -0
- package/dist/log.esm.js +222 -0
- package/dist/log.esm.js.map +1 -0
- package/dist/logger.d.ts +23 -0
- package/dist/types.d.ts +36 -0
- package/dist/utils.d.ts +4 -0
- package/package.json +22 -0
- package/src/index.ts +39 -0
- package/src/logger.ts +247 -0
- package/src/types.ts +109 -0
- package/src/utils.ts +63 -0
- package/test/test.spec.ts +333 -0
- package/tsconfig.build.json +11 -0
- package/tsconfig.json +7 -0
- package/vitest.config.ts +21 -0
|
@@ -0,0 +1,26 @@
|
|
|
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
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
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/README.md
ADDED
|
@@ -0,0 +1,340 @@
|
|
|
1
|
+
# @x-oasis/log
|
|
2
|
+
|
|
3
|
+
A friendly, browser-compatible logging library with a fluent API for specifying log messages, metadata, context, and errors.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- 🎯 **Simple API** - Easy to use with a clean, chainable interface
|
|
8
|
+
- 🌐 **Browser Compatible** - Works seamlessly in browser environments
|
|
9
|
+
- 📊 **Multiple Log Levels** - Support for trace, debug, info, warn, and error levels
|
|
10
|
+
- 🔗 **Chainable API** - Fluent interface for building log entries
|
|
11
|
+
- 📝 **Context & Metadata** - Attach contextual data and metadata to logs
|
|
12
|
+
- 🎨 **Customizable** - Configurable log levels and custom output handlers
|
|
13
|
+
- ⚡ **Lightweight** - Small bundle size with zero dependencies
|
|
14
|
+
|
|
15
|
+
## Installation
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
npm install @x-oasis/log
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## Quick Start
|
|
22
|
+
|
|
23
|
+
### Basic Usage
|
|
24
|
+
|
|
25
|
+
```typescript
|
|
26
|
+
import { Logger, LogLevel } from '@x-oasis/log';
|
|
27
|
+
|
|
28
|
+
// Create a logger instance
|
|
29
|
+
const logger = new Logger({
|
|
30
|
+
level: LogLevel.INFO, // Only log info, warn, and error
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
// Simple logging
|
|
34
|
+
logger.info('User logged in');
|
|
35
|
+
logger.warn('Deprecated API used');
|
|
36
|
+
logger.error('Failed to process request');
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
### Using the Default Logger
|
|
40
|
+
|
|
41
|
+
```typescript
|
|
42
|
+
import { log } from '@x-oasis/log';
|
|
43
|
+
|
|
44
|
+
// Use the default logger instance
|
|
45
|
+
log.info('Application started');
|
|
46
|
+
log.debug('Debug information');
|
|
47
|
+
log.error('An error occurred');
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
### Chainable API
|
|
51
|
+
|
|
52
|
+
The chainable API allows you to build log entries with context, metadata, errors, and prefixes:
|
|
53
|
+
|
|
54
|
+
```typescript
|
|
55
|
+
import { Logger } from '@x-oasis/log';
|
|
56
|
+
|
|
57
|
+
const logger = new Logger();
|
|
58
|
+
|
|
59
|
+
// Chain multiple operations
|
|
60
|
+
logger
|
|
61
|
+
.chain()
|
|
62
|
+
.withContext({ userId: '123', sessionId: 'abc' })
|
|
63
|
+
.withMetadata({ duration: 150, status: 'success' })
|
|
64
|
+
.withPrefix('[API]')
|
|
65
|
+
.info('Request completed');
|
|
66
|
+
|
|
67
|
+
// With error
|
|
68
|
+
const error = new Error('Validation failed');
|
|
69
|
+
logger
|
|
70
|
+
.chain()
|
|
71
|
+
.withError(error)
|
|
72
|
+
.withContext({ field: 'email' })
|
|
73
|
+
.error('Validation error');
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
### Context and Metadata
|
|
77
|
+
|
|
78
|
+
Context and metadata help you attach additional information to your logs:
|
|
79
|
+
|
|
80
|
+
```typescript
|
|
81
|
+
const logger = new Logger();
|
|
82
|
+
|
|
83
|
+
// Context: persistent data that describes the environment
|
|
84
|
+
logger.setDefaultContext({
|
|
85
|
+
app: 'my-app',
|
|
86
|
+
version: '1.0.0',
|
|
87
|
+
environment: 'production',
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
// Metadata: specific data for individual log entries
|
|
91
|
+
logger
|
|
92
|
+
.chain()
|
|
93
|
+
.withContext({ requestId: 'req-123' })
|
|
94
|
+
.withMetadata({ responseTime: 45, statusCode: 200 })
|
|
95
|
+
.info('HTTP request completed');
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
### Setting Log Levels
|
|
99
|
+
|
|
100
|
+
Control which logs are output based on severity:
|
|
101
|
+
|
|
102
|
+
```typescript
|
|
103
|
+
import { Logger, LogLevel } from '@x-oasis/log';
|
|
104
|
+
|
|
105
|
+
const logger = new Logger();
|
|
106
|
+
|
|
107
|
+
// Set minimum log level (only warn and error will be logged)
|
|
108
|
+
logger.setLevel(LogLevel.WARN);
|
|
109
|
+
|
|
110
|
+
// Or use string
|
|
111
|
+
logger.setLevel('DEBUG');
|
|
112
|
+
|
|
113
|
+
// Available levels (from most to least verbose):
|
|
114
|
+
// LogLevel.TRACE (0)
|
|
115
|
+
// LogLevel.DEBUG (1)
|
|
116
|
+
// LogLevel.INFO (2)
|
|
117
|
+
// LogLevel.WARN (3)
|
|
118
|
+
// LogLevel.ERROR (4)
|
|
119
|
+
// LogLevel.SILENT (5)
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
### Custom Output Handler
|
|
123
|
+
|
|
124
|
+
Replace the default console output with your own handler:
|
|
125
|
+
|
|
126
|
+
```typescript
|
|
127
|
+
import { Logger, LogLevel, LogEntry } from '@x-oasis/log';
|
|
128
|
+
|
|
129
|
+
const logger = new Logger({
|
|
130
|
+
handler: (entry: LogEntry) => {
|
|
131
|
+
// Send to your logging service
|
|
132
|
+
fetch('/api/logs', {
|
|
133
|
+
method: 'POST',
|
|
134
|
+
body: JSON.stringify({
|
|
135
|
+
level: entry.level,
|
|
136
|
+
message: entry.message,
|
|
137
|
+
timestamp: entry.timestamp,
|
|
138
|
+
context: entry.context,
|
|
139
|
+
metadata: entry.metadata,
|
|
140
|
+
error: entry.error ? {
|
|
141
|
+
name: entry.error.name,
|
|
142
|
+
message: entry.error.message,
|
|
143
|
+
stack: entry.error.stack,
|
|
144
|
+
} : undefined,
|
|
145
|
+
}),
|
|
146
|
+
});
|
|
147
|
+
},
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
logger.info('This will be sent to your API');
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
### Default Prefix
|
|
154
|
+
|
|
155
|
+
Add a prefix to all log messages:
|
|
156
|
+
|
|
157
|
+
```typescript
|
|
158
|
+
const logger = new Logger({
|
|
159
|
+
defaultPrefix: '[MY-APP]',
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
logger.info('Application started');
|
|
163
|
+
// Output: [MY-APP] Application started
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
### Convenience Methods
|
|
167
|
+
|
|
168
|
+
Use the `withContext` and `withPrefix` methods for quick setup:
|
|
169
|
+
|
|
170
|
+
```typescript
|
|
171
|
+
const logger = new Logger();
|
|
172
|
+
|
|
173
|
+
// Create a logger with context
|
|
174
|
+
logger
|
|
175
|
+
.withContext({ userId: '123' })
|
|
176
|
+
.info('User action');
|
|
177
|
+
|
|
178
|
+
// Create a logger with prefix
|
|
179
|
+
logger
|
|
180
|
+
.withPrefix('[MODULE]')
|
|
181
|
+
.warn('Warning message');
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
## API Reference
|
|
185
|
+
|
|
186
|
+
### Logger
|
|
187
|
+
|
|
188
|
+
#### Constructor Options
|
|
189
|
+
|
|
190
|
+
```typescript
|
|
191
|
+
interface LoggerOptions {
|
|
192
|
+
level?: LogLevel | keyof typeof LogLevel; // Default: LogLevel.INFO
|
|
193
|
+
handler?: OutputHandler; // Default: console handler
|
|
194
|
+
enableTimestamp?: boolean; // Default: true
|
|
195
|
+
defaultContext?: Record<string, unknown>; // Default: undefined
|
|
196
|
+
defaultPrefix?: string; // Default: undefined
|
|
197
|
+
}
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
#### Methods
|
|
201
|
+
|
|
202
|
+
- `setLevel(level: LogLevel | keyof typeof LogLevel): void` - Set minimum log level
|
|
203
|
+
- `getLevel(): LogLevel` - Get current log level
|
|
204
|
+
- `setHandler(handler: OutputHandler): void` - Set custom output handler
|
|
205
|
+
- `setDefaultContext(context: Record<string, unknown>): void` - Set default context
|
|
206
|
+
- `setDefaultPrefix(prefix: string): void` - Set default prefix
|
|
207
|
+
- `chain(): LoggerChain` - Create a chainable logger instance
|
|
208
|
+
- `withContext(context: Record<string, unknown>): LoggerChain` - Create chainable logger with context
|
|
209
|
+
- `withPrefix(prefix: string): LoggerChain` - Create chainable logger with prefix
|
|
210
|
+
- `trace(message: string, context?: Record<string, unknown>): void`
|
|
211
|
+
- `debug(message: string, context?: Record<string, unknown>): void`
|
|
212
|
+
- `info(message: string, context?: Record<string, unknown>): void`
|
|
213
|
+
- `warn(message: string, context?: Record<string, unknown>): void`
|
|
214
|
+
- `error(message: string, context?: Record<string, unknown>): void`
|
|
215
|
+
|
|
216
|
+
### LoggerChain
|
|
217
|
+
|
|
218
|
+
Chainable interface for building log entries:
|
|
219
|
+
|
|
220
|
+
- `withContext(context: Record<string, unknown>): LoggerChain`
|
|
221
|
+
- `withMetadata(metadata: Record<string, unknown>): LoggerChain`
|
|
222
|
+
- `withError(error: Error): LoggerChain`
|
|
223
|
+
- `withPrefix(prefix: string): LoggerChain`
|
|
224
|
+
- `trace(message: string): void`
|
|
225
|
+
- `debug(message: string): void`
|
|
226
|
+
- `info(message: string): void`
|
|
227
|
+
- `warn(message: string): void`
|
|
228
|
+
- `error(message: string): void`
|
|
229
|
+
|
|
230
|
+
## Examples
|
|
231
|
+
|
|
232
|
+
### Example 1: API Request Logging
|
|
233
|
+
|
|
234
|
+
```typescript
|
|
235
|
+
import { Logger } from '@x-oasis/log';
|
|
236
|
+
|
|
237
|
+
const logger = new Logger({
|
|
238
|
+
defaultContext: {
|
|
239
|
+
service: 'api',
|
|
240
|
+
version: '1.0.0',
|
|
241
|
+
},
|
|
242
|
+
});
|
|
243
|
+
|
|
244
|
+
function handleRequest(req: Request) {
|
|
245
|
+
const requestId = generateRequestId();
|
|
246
|
+
|
|
247
|
+
logger
|
|
248
|
+
.chain()
|
|
249
|
+
.withContext({ requestId, method: req.method, path: req.path })
|
|
250
|
+
.withMetadata({ timestamp: Date.now() })
|
|
251
|
+
.info('Request received');
|
|
252
|
+
|
|
253
|
+
try {
|
|
254
|
+
const result = await processRequest(req);
|
|
255
|
+
|
|
256
|
+
logger
|
|
257
|
+
.chain()
|
|
258
|
+
.withContext({ requestId })
|
|
259
|
+
.withMetadata({ duration: result.duration, statusCode: 200 })
|
|
260
|
+
.info('Request completed');
|
|
261
|
+
|
|
262
|
+
return result;
|
|
263
|
+
} catch (error) {
|
|
264
|
+
logger
|
|
265
|
+
.chain()
|
|
266
|
+
.withContext({ requestId })
|
|
267
|
+
.withError(error as Error)
|
|
268
|
+
.error('Request failed');
|
|
269
|
+
|
|
270
|
+
throw error;
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
```
|
|
274
|
+
|
|
275
|
+
### Example 2: Form Validation
|
|
276
|
+
|
|
277
|
+
```typescript
|
|
278
|
+
import { Logger } from '@x-oasis/log';
|
|
279
|
+
|
|
280
|
+
const logger = new Logger({
|
|
281
|
+
level: 'WARN', // Only log warnings and errors
|
|
282
|
+
});
|
|
283
|
+
|
|
284
|
+
function validateEmail(email: string) {
|
|
285
|
+
if (!email.includes('@')) {
|
|
286
|
+
logger
|
|
287
|
+
.chain()
|
|
288
|
+
.withContext({ field: 'email', value: email })
|
|
289
|
+
.withMetadata({ validation: 'format' })
|
|
290
|
+
.warn('Invalid email format');
|
|
291
|
+
|
|
292
|
+
return false;
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
return true;
|
|
296
|
+
}
|
|
297
|
+
```
|
|
298
|
+
|
|
299
|
+
### Example 3: Error Tracking
|
|
300
|
+
|
|
301
|
+
```typescript
|
|
302
|
+
import { Logger, LogLevel } from '@x-oasis/log';
|
|
303
|
+
|
|
304
|
+
const logger = new Logger({
|
|
305
|
+
handler: (entry) => {
|
|
306
|
+
// Send errors to error tracking service
|
|
307
|
+
if (entry.level >= LogLevel.ERROR && entry.error) {
|
|
308
|
+
errorTrackingService.captureException(entry.error, {
|
|
309
|
+
context: entry.context,
|
|
310
|
+
metadata: entry.metadata,
|
|
311
|
+
});
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
// Also log to console
|
|
315
|
+
console.error(entry);
|
|
316
|
+
},
|
|
317
|
+
});
|
|
318
|
+
|
|
319
|
+
try {
|
|
320
|
+
riskyOperation();
|
|
321
|
+
} catch (error) {
|
|
322
|
+
logger
|
|
323
|
+
.chain()
|
|
324
|
+
.withError(error as Error)
|
|
325
|
+
.withContext({ operation: 'riskyOperation' })
|
|
326
|
+
.error('Operation failed');
|
|
327
|
+
}
|
|
328
|
+
```
|
|
329
|
+
|
|
330
|
+
## Browser Compatibility
|
|
331
|
+
|
|
332
|
+
This library is designed to work in all modern browsers. It uses standard browser APIs and has no dependencies.
|
|
333
|
+
|
|
334
|
+
## TypeScript Support
|
|
335
|
+
|
|
336
|
+
Full TypeScript support with comprehensive type definitions included.
|
|
337
|
+
|
|
338
|
+
## License
|
|
339
|
+
|
|
340
|
+
ISC
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Logger } from './logger';
|
|
2
|
+
import { LogLevel } from './types';
|
|
3
|
+
export { Logger, LogLevel };
|
|
4
|
+
export type { LogEntry, LoggerOptions, LoggerChain, OutputHandler, } from './types';
|
|
5
|
+
export declare const defaultLogger: Logger;
|
|
6
|
+
export declare const log: {
|
|
7
|
+
trace: (message: string, context?: Record<string, unknown>) => void;
|
|
8
|
+
debug: (message: string, context?: Record<string, unknown>) => void;
|
|
9
|
+
info: (message: string, context?: Record<string, unknown>) => void;
|
|
10
|
+
warn: (message: string, context?: Record<string, unknown>) => void;
|
|
11
|
+
error: (message: string, context?: Record<string, unknown>) => void;
|
|
12
|
+
setLevel: (level: LogLevel | keyof typeof LogLevel) => void;
|
|
13
|
+
withContext: (context: Record<string, unknown>) => import("./types").LoggerChain;
|
|
14
|
+
withPrefix: (prefix: string) => import("./types").LoggerChain;
|
|
15
|
+
chain: () => import("./types").LoggerChain;
|
|
16
|
+
};
|
|
17
|
+
export default Logger;
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
function _extends() {
|
|
6
|
+
_extends = Object.assign ? Object.assign.bind() : function (target) {
|
|
7
|
+
for (var i = 1; i < arguments.length; i++) {
|
|
8
|
+
var source = arguments[i];
|
|
9
|
+
for (var key in source) {
|
|
10
|
+
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
|
11
|
+
target[key] = source[key];
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
return target;
|
|
16
|
+
};
|
|
17
|
+
return _extends.apply(this, arguments);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
(function (LogLevel) {
|
|
21
|
+
LogLevel[LogLevel["TRACE"] = 0] = "TRACE";
|
|
22
|
+
LogLevel[LogLevel["DEBUG"] = 1] = "DEBUG";
|
|
23
|
+
LogLevel[LogLevel["INFO"] = 2] = "INFO";
|
|
24
|
+
LogLevel[LogLevel["WARN"] = 3] = "WARN";
|
|
25
|
+
LogLevel[LogLevel["ERROR"] = 4] = "ERROR";
|
|
26
|
+
LogLevel[LogLevel["SILENT"] = 5] = "SILENT";
|
|
27
|
+
})(exports.LogLevel || (exports.LogLevel = {}));
|
|
28
|
+
|
|
29
|
+
function parseLogLevel(level) {
|
|
30
|
+
var _LogLevel$level;
|
|
31
|
+
if (typeof level === 'number') {
|
|
32
|
+
return level;
|
|
33
|
+
}
|
|
34
|
+
return (_LogLevel$level = exports.LogLevel[level]) != null ? _LogLevel$level : exports.LogLevel.INFO;
|
|
35
|
+
}
|
|
36
|
+
function createConsoleHandler() {
|
|
37
|
+
var _consoleMethods;
|
|
38
|
+
var consoleMethods = (_consoleMethods = {}, _consoleMethods[exports.LogLevel.TRACE] = console.trace || console.debug, _consoleMethods[exports.LogLevel.DEBUG] = console.debug, _consoleMethods[exports.LogLevel.INFO] = console.info, _consoleMethods[exports.LogLevel.WARN] = console.warn, _consoleMethods[exports.LogLevel.ERROR] = console.error, _consoleMethods);
|
|
39
|
+
return function (entry) {
|
|
40
|
+
var method = consoleMethods[entry.level] || console.log;
|
|
41
|
+
var parts = [];
|
|
42
|
+
if (entry.prefix) {
|
|
43
|
+
parts.push(entry.prefix);
|
|
44
|
+
}
|
|
45
|
+
parts.push(entry.message);
|
|
46
|
+
if (entry.context && Object.keys(entry.context).length > 0) {
|
|
47
|
+
parts.push('\nContext:', entry.context);
|
|
48
|
+
}
|
|
49
|
+
if (entry.metadata && Object.keys(entry.metadata).length > 0) {
|
|
50
|
+
parts.push('\nMetadata:', entry.metadata);
|
|
51
|
+
}
|
|
52
|
+
if (entry.error) {
|
|
53
|
+
parts.push('\nError:', entry.error);
|
|
54
|
+
}
|
|
55
|
+
method.apply(void 0, parts);
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
var Logger = /*#__PURE__*/function () {
|
|
60
|
+
function Logger(options) {
|
|
61
|
+
if (options === void 0) {
|
|
62
|
+
options = {};
|
|
63
|
+
}
|
|
64
|
+
this.level = options.level ? parseLogLevel(options.level) : exports.LogLevel.INFO;
|
|
65
|
+
this.handler = options.handler || createConsoleHandler();
|
|
66
|
+
this.enableTimestamp = options.enableTimestamp !== undefined ? options.enableTimestamp : true;
|
|
67
|
+
this.defaultContext = options.defaultContext;
|
|
68
|
+
this.defaultPrefix = options.defaultPrefix;
|
|
69
|
+
}
|
|
70
|
+
var _proto = Logger.prototype;
|
|
71
|
+
_proto.setLevel = function setLevel(level) {
|
|
72
|
+
this.level = parseLogLevel(level);
|
|
73
|
+
};
|
|
74
|
+
_proto.getLevel = function getLevel() {
|
|
75
|
+
return this.level;
|
|
76
|
+
};
|
|
77
|
+
_proto.setHandler = function setHandler(handler) {
|
|
78
|
+
this.handler = handler;
|
|
79
|
+
};
|
|
80
|
+
_proto.setDefaultContext = function setDefaultContext(context) {
|
|
81
|
+
this.defaultContext = context;
|
|
82
|
+
};
|
|
83
|
+
_proto.setDefaultPrefix = function setDefaultPrefix(prefix) {
|
|
84
|
+
this.defaultPrefix = prefix;
|
|
85
|
+
};
|
|
86
|
+
_proto.chain = function chain() {
|
|
87
|
+
return new LoggerChainBuilder(this);
|
|
88
|
+
};
|
|
89
|
+
_proto.trace = function trace(message, context) {
|
|
90
|
+
this.log(exports.LogLevel.TRACE, message, context);
|
|
91
|
+
};
|
|
92
|
+
_proto.debug = function debug(message, context) {
|
|
93
|
+
this.log(exports.LogLevel.DEBUG, message, context);
|
|
94
|
+
};
|
|
95
|
+
_proto.info = function info(message, context) {
|
|
96
|
+
this.log(exports.LogLevel.INFO, message, context);
|
|
97
|
+
};
|
|
98
|
+
_proto.warn = function warn(message, context) {
|
|
99
|
+
this.log(exports.LogLevel.WARN, message, context);
|
|
100
|
+
};
|
|
101
|
+
_proto.error = function error(message, context) {
|
|
102
|
+
this.log(exports.LogLevel.ERROR, message, context);
|
|
103
|
+
};
|
|
104
|
+
_proto.log = function log(level, message, context) {
|
|
105
|
+
if (level < this.level) {
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
var entry = {
|
|
109
|
+
level: level,
|
|
110
|
+
message: message,
|
|
111
|
+
timestamp: this.enableTimestamp ? Date.now() : 0,
|
|
112
|
+
prefix: this.defaultPrefix
|
|
113
|
+
};
|
|
114
|
+
if (this.defaultContext || context) {
|
|
115
|
+
entry.context = _extends({}, this.defaultContext, context);
|
|
116
|
+
}
|
|
117
|
+
this.handler(entry);
|
|
118
|
+
};
|
|
119
|
+
_proto.withContext = function withContext(context) {
|
|
120
|
+
return new LoggerChainBuilder(this).withContext(context);
|
|
121
|
+
};
|
|
122
|
+
_proto.withPrefix = function withPrefix(prefix) {
|
|
123
|
+
return new LoggerChainBuilder(this).withPrefix(prefix);
|
|
124
|
+
};
|
|
125
|
+
return Logger;
|
|
126
|
+
}();
|
|
127
|
+
var LoggerChainBuilder = /*#__PURE__*/function () {
|
|
128
|
+
function LoggerChainBuilder(logger) {
|
|
129
|
+
this.logger = logger;
|
|
130
|
+
}
|
|
131
|
+
var _proto2 = LoggerChainBuilder.prototype;
|
|
132
|
+
_proto2.withContext = function withContext(context) {
|
|
133
|
+
this.context = _extends({}, this.context, context);
|
|
134
|
+
return this;
|
|
135
|
+
};
|
|
136
|
+
_proto2.withMetadata = function withMetadata(metadata) {
|
|
137
|
+
this.metadata = _extends({}, this.metadata, metadata);
|
|
138
|
+
return this;
|
|
139
|
+
};
|
|
140
|
+
_proto2.withError = function withError(error) {
|
|
141
|
+
this.errorObj = error;
|
|
142
|
+
return this;
|
|
143
|
+
};
|
|
144
|
+
_proto2.withPrefix = function withPrefix(prefix) {
|
|
145
|
+
this.prefix = prefix;
|
|
146
|
+
return this;
|
|
147
|
+
};
|
|
148
|
+
_proto2.createEntry = function createEntry(level, message) {
|
|
149
|
+
var entry = {
|
|
150
|
+
level: level,
|
|
151
|
+
message: message,
|
|
152
|
+
timestamp: this.logger['enableTimestamp'] ? Date.now() : 0,
|
|
153
|
+
prefix: this.prefix || this.logger['defaultPrefix']
|
|
154
|
+
};
|
|
155
|
+
var defaultContext = this.logger['defaultContext'];
|
|
156
|
+
if (defaultContext || this.context) {
|
|
157
|
+
entry.context = _extends({}, defaultContext, this.context);
|
|
158
|
+
}
|
|
159
|
+
if (this.metadata) {
|
|
160
|
+
entry.metadata = this.metadata;
|
|
161
|
+
}
|
|
162
|
+
if (this.errorObj) {
|
|
163
|
+
entry.error = this.errorObj;
|
|
164
|
+
}
|
|
165
|
+
return entry;
|
|
166
|
+
};
|
|
167
|
+
_proto2.log = function log(level, message) {
|
|
168
|
+
if (level < this.logger.getLevel()) {
|
|
169
|
+
return;
|
|
170
|
+
}
|
|
171
|
+
var entry = this.createEntry(level, message);
|
|
172
|
+
this.logger['handler'](entry);
|
|
173
|
+
};
|
|
174
|
+
_proto2.trace = function trace(message) {
|
|
175
|
+
this.log(exports.LogLevel.TRACE, message);
|
|
176
|
+
};
|
|
177
|
+
_proto2.debug = function debug(message) {
|
|
178
|
+
this.log(exports.LogLevel.DEBUG, message);
|
|
179
|
+
};
|
|
180
|
+
_proto2.info = function info(message) {
|
|
181
|
+
this.log(exports.LogLevel.INFO, message);
|
|
182
|
+
};
|
|
183
|
+
_proto2.warn = function warn(message) {
|
|
184
|
+
this.log(exports.LogLevel.WARN, message);
|
|
185
|
+
};
|
|
186
|
+
_proto2.error = function error(message) {
|
|
187
|
+
this.log(exports.LogLevel.ERROR, message);
|
|
188
|
+
};
|
|
189
|
+
return LoggerChainBuilder;
|
|
190
|
+
}();
|
|
191
|
+
|
|
192
|
+
var defaultLogger = /*#__PURE__*/new Logger();
|
|
193
|
+
var log = {
|
|
194
|
+
trace: function trace(message, context) {
|
|
195
|
+
return defaultLogger.trace(message, context);
|
|
196
|
+
},
|
|
197
|
+
debug: function debug(message, context) {
|
|
198
|
+
return defaultLogger.debug(message, context);
|
|
199
|
+
},
|
|
200
|
+
info: function info(message, context) {
|
|
201
|
+
return defaultLogger.info(message, context);
|
|
202
|
+
},
|
|
203
|
+
warn: function warn(message, context) {
|
|
204
|
+
return defaultLogger.warn(message, context);
|
|
205
|
+
},
|
|
206
|
+
error: function error(message, context) {
|
|
207
|
+
return defaultLogger.error(message, context);
|
|
208
|
+
},
|
|
209
|
+
setLevel: function setLevel(level) {
|
|
210
|
+
return defaultLogger.setLevel(level);
|
|
211
|
+
},
|
|
212
|
+
withContext: function withContext(context) {
|
|
213
|
+
return defaultLogger.withContext(context);
|
|
214
|
+
},
|
|
215
|
+
withPrefix: function withPrefix(prefix) {
|
|
216
|
+
return defaultLogger.withPrefix(prefix);
|
|
217
|
+
},
|
|
218
|
+
chain: function chain() {
|
|
219
|
+
return defaultLogger.chain();
|
|
220
|
+
}
|
|
221
|
+
};
|
|
222
|
+
|
|
223
|
+
exports.Logger = Logger;
|
|
224
|
+
exports.default = Logger;
|
|
225
|
+
exports.defaultLogger = defaultLogger;
|
|
226
|
+
exports.log = log;
|
|
227
|
+
//# sourceMappingURL=log.cjs.development.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"log.cjs.development.js","sources":["../src/types.ts","../src/utils.ts","../src/logger.ts","../src/index.ts"],"sourcesContent":["/**\n * Log levels in order of severity\n */\nexport enum LogLevel {\n TRACE = 0,\n DEBUG = 1,\n INFO = 2,\n WARN = 3,\n ERROR = 4,\n SILENT = 5,\n}\n\n/**\n * Log entry data structure\n */\nexport interface LogEntry {\n level: LogLevel;\n message: string;\n timestamp: number;\n context?: Record<string, unknown>;\n metadata?: Record<string, unknown>;\n error?: Error;\n prefix?: string;\n}\n\n/**\n * Output handler function type\n */\nexport type OutputHandler = (entry: LogEntry) => void;\n\n/**\n * Logger configuration options\n */\nexport interface LoggerOptions {\n /**\n * Minimum log level to output (default: LogLevel.INFO)\n */\n level?: LogLevel | keyof typeof LogLevel;\n\n /**\n * Custom output handler (default: console)\n */\n handler?: OutputHandler;\n\n /**\n * Enable timestamps in log entries (default: true)\n */\n enableTimestamp?: boolean;\n\n /**\n * Default context that will be included in all logs\n */\n defaultContext?: Record<string, unknown>;\n\n /**\n * Default prefix for all log messages\n */\n defaultPrefix?: string;\n}\n\n/**\n * Chainable logger interface\n */\nexport interface LoggerChain {\n /**\n * Add context data that will be included in this log entry\n */\n withContext(context: Record<string, unknown>): LoggerChain;\n\n /**\n * Add metadata that will be included in this log entry\n */\n withMetadata(metadata: Record<string, unknown>): LoggerChain;\n\n /**\n * Add an error object to this log entry\n */\n withError(error: Error): LoggerChain;\n\n /**\n * Add a prefix to this log message\n */\n withPrefix(prefix: string): LoggerChain;\n\n /**\n * Log at trace level\n */\n trace(message: string): void;\n\n /**\n * Log at debug level\n */\n debug(message: string): void;\n\n /**\n * Log at info level\n */\n info(message: string): void;\n\n /**\n * Log at warn level\n */\n warn(message: string): void;\n\n /**\n * Log at error level\n */\n error(message: string): void;\n}\n","import { LogLevel, LogEntry } from './types';\n\n/**\n * Convert log level string to LogLevel enum\n */\nexport function parseLogLevel(\n level: LogLevel | keyof typeof LogLevel\n): LogLevel {\n if (typeof level === 'number') {\n return level;\n }\n return LogLevel[level] ?? LogLevel.INFO;\n}\n\n/**\n * Get log level name\n */\nexport function getLogLevelName(level: LogLevel): string {\n return LogLevel[level] ?? 'UNKNOWN';\n}\n\n/**\n * Default console output handler\n */\nexport function createConsoleHandler(): (entry: LogEntry) => void {\n const consoleMethods: Record<number, typeof console.log> = {\n [LogLevel.TRACE]: console.trace || console.debug,\n [LogLevel.DEBUG]: console.debug,\n [LogLevel.INFO]: console.info,\n [LogLevel.WARN]: console.warn,\n [LogLevel.ERROR]: console.error,\n };\n\n return (entry) => {\n const method = consoleMethods[entry.level] || console.log;\n const parts: unknown[] = [];\n\n // Add prefix if present\n if (entry.prefix) {\n parts.push(entry.prefix);\n }\n\n // Add message\n parts.push(entry.message);\n\n // Add context if present\n if (entry.context && Object.keys(entry.context).length > 0) {\n parts.push('\\nContext:', entry.context);\n }\n\n // Add metadata if present\n if (entry.metadata && Object.keys(entry.metadata).length > 0) {\n parts.push('\\nMetadata:', entry.metadata);\n }\n\n // Add error if present\n if (entry.error) {\n parts.push('\\nError:', entry.error);\n }\n\n method(...parts);\n };\n}\n","import {\n LogLevel,\n LogEntry,\n LoggerOptions,\n LoggerChain,\n OutputHandler,\n} from './types';\nimport { parseLogLevel, createConsoleHandler } from './utils';\n\n/**\n * Main Logger class\n */\nexport class Logger {\n private level: LogLevel;\n private handler: OutputHandler;\n private enableTimestamp: boolean;\n private defaultContext?: Record<string, unknown>;\n private defaultPrefix?: string;\n\n constructor(options: LoggerOptions = {}) {\n this.level = options.level ? parseLogLevel(options.level) : LogLevel.INFO;\n this.handler = options.handler || createConsoleHandler();\n this.enableTimestamp =\n options.enableTimestamp !== undefined ? options.enableTimestamp : true;\n this.defaultContext = options.defaultContext;\n this.defaultPrefix = options.defaultPrefix;\n }\n\n /**\n * Set the minimum log level\n */\n setLevel(level: LogLevel | keyof typeof LogLevel): void {\n this.level = parseLogLevel(level);\n }\n\n /**\n * Get the current log level\n */\n getLevel(): LogLevel {\n return this.level;\n }\n\n /**\n * Set a custom output handler\n */\n setHandler(handler: OutputHandler): void {\n this.handler = handler;\n }\n\n /**\n * Set default context that will be included in all logs\n */\n setDefaultContext(context: Record<string, unknown>): void {\n this.defaultContext = context;\n }\n\n /**\n * Set default prefix for all log messages\n */\n setDefaultPrefix(prefix: string): void {\n this.defaultPrefix = prefix;\n }\n\n /**\n * Create a chainable logger instance\n */\n chain(): LoggerChain {\n return new LoggerChainBuilder(this);\n }\n\n /**\n * Log at trace level\n */\n trace(message: string, context?: Record<string, unknown>): void {\n this.log(LogLevel.TRACE, message, context);\n }\n\n /**\n * Log at debug level\n */\n debug(message: string, context?: Record<string, unknown>): void {\n this.log(LogLevel.DEBUG, message, context);\n }\n\n /**\n * Log at info level\n */\n info(message: string, context?: Record<string, unknown>): void {\n this.log(LogLevel.INFO, message, context);\n }\n\n /**\n * Log at warn level\n */\n warn(message: string, context?: Record<string, unknown>): void {\n this.log(LogLevel.WARN, message, context);\n }\n\n /**\n * Log at error level\n */\n error(message: string, context?: Record<string, unknown>): void {\n this.log(LogLevel.ERROR, message, context);\n }\n\n /**\n * Internal log method\n */\n private log(\n level: LogLevel,\n message: string,\n context?: Record<string, unknown>\n ): void {\n if (level < this.level) {\n return;\n }\n\n const entry: LogEntry = {\n level,\n message,\n timestamp: this.enableTimestamp ? Date.now() : 0,\n prefix: this.defaultPrefix,\n };\n\n // Merge default context with provided context\n if (this.defaultContext || context) {\n entry.context = {\n ...this.defaultContext,\n ...context,\n };\n }\n\n this.handler(entry);\n }\n\n /**\n * Create a chainable logger with initial context\n */\n withContext(context: Record<string, unknown>): LoggerChain {\n return new LoggerChainBuilder(this).withContext(context);\n }\n\n /**\n * Create a chainable logger with initial prefix\n */\n withPrefix(prefix: string): LoggerChain {\n return new LoggerChainBuilder(this).withPrefix(prefix);\n }\n}\n\n/**\n * Chainable logger builder\n */\nclass LoggerChainBuilder implements LoggerChain {\n private logger: Logger;\n private context?: Record<string, unknown>;\n private metadata?: Record<string, unknown>;\n private errorObj?: Error;\n private prefix?: string;\n\n constructor(logger: Logger) {\n this.logger = logger;\n }\n\n withContext(context: Record<string, unknown>): LoggerChain {\n this.context = {\n ...this.context,\n ...context,\n };\n return this;\n }\n\n withMetadata(metadata: Record<string, unknown>): LoggerChain {\n this.metadata = {\n ...this.metadata,\n ...metadata,\n };\n return this;\n }\n\n withError(error: Error): LoggerChain {\n this.errorObj = error;\n return this;\n }\n\n withPrefix(prefix: string): LoggerChain {\n this.prefix = prefix;\n return this;\n }\n\n private createEntry(level: LogLevel, message: string): LogEntry {\n const entry: LogEntry = {\n level,\n message,\n timestamp: this.logger['enableTimestamp'] ? Date.now() : 0,\n prefix: this.prefix || this.logger['defaultPrefix'],\n };\n\n // Merge contexts\n const defaultContext = this.logger['defaultContext'];\n if (defaultContext || this.context) {\n entry.context = {\n ...defaultContext,\n ...this.context,\n };\n }\n\n if (this.metadata) {\n entry.metadata = this.metadata;\n }\n\n if (this.errorObj) {\n entry.error = this.errorObj;\n }\n\n return entry;\n }\n\n private log(level: LogLevel, message: string): void {\n if (level < this.logger.getLevel()) {\n return;\n }\n\n const entry = this.createEntry(level, message);\n this.logger['handler'](entry);\n }\n\n trace(message: string): void {\n this.log(LogLevel.TRACE, message);\n }\n\n debug(message: string): void {\n this.log(LogLevel.DEBUG, message);\n }\n\n info(message: string): void {\n this.log(LogLevel.INFO, message);\n }\n\n warn(message: string): void {\n this.log(LogLevel.WARN, message);\n }\n\n error(message: string): void {\n this.log(LogLevel.ERROR, message);\n }\n}\n","import { Logger } from './logger';\nimport { LogLevel } from './types';\n\nexport { Logger, LogLevel };\nexport type {\n LogEntry,\n LoggerOptions,\n LoggerChain,\n OutputHandler,\n} from './types';\n\n/**\n * Default logger instance\n */\nexport const defaultLogger = new Logger();\n\n/**\n * Convenience methods using the default logger\n */\nexport const log = {\n trace: (message: string, context?: Record<string, unknown>) =>\n defaultLogger.trace(message, context),\n debug: (message: string, context?: Record<string, unknown>) =>\n defaultLogger.debug(message, context),\n info: (message: string, context?: Record<string, unknown>) =>\n defaultLogger.info(message, context),\n warn: (message: string, context?: Record<string, unknown>) =>\n defaultLogger.warn(message, context),\n error: (message: string, context?: Record<string, unknown>) =>\n defaultLogger.error(message, context),\n setLevel: (level: LogLevel | keyof typeof LogLevel) =>\n defaultLogger.setLevel(level),\n withContext: (context: Record<string, unknown>) =>\n defaultLogger.withContext(context),\n withPrefix: (prefix: string) => defaultLogger.withPrefix(prefix),\n chain: () => defaultLogger.chain(),\n};\n\nexport default Logger;\n"],"names":["LogLevel","parseLogLevel","level","_LogLevel$level","INFO","createConsoleHandler","consoleMethods","_consoleMethods","TRACE","console","trace","debug","DEBUG","info","WARN","warn","ERROR","error","entry","method","log","parts","prefix","push","message","context","Object","keys","length","metadata","apply","Logger","options","handler","enableTimestamp","undefined","defaultContext","defaultPrefix","_proto","prototype","setLevel","getLevel","setHandler","setDefaultContext","setDefaultPrefix","chain","LoggerChainBuilder","timestamp","Date","now","_extends","withContext","withPrefix","logger","_proto2","withMetadata","withError","errorObj","createEntry","defaultLogger"],"mappings":";;;;;;;;;;;;;;;;;;;AAGA,WAAYA,QAAQ;EAClBA,yCAAS;EACTA,yCAAS;EACTA,uCAAQ;EACRA,uCAAQ;EACRA,yCAAS;EACTA,2CAAU;AACZ,CAAC,EAPWA,gBAAQ,KAARA,gBAAQ;;SCEJC,aAAaA,CAC3BC,KAAuC;;EAEvC,IAAI,OAAOA,KAAK,KAAK,QAAQ,EAAE;IAC7B,OAAOA,KAAK;;EAEd,QAAAC,eAAA,GAAOH,gBAAQ,CAACE,KAAK,CAAC,YAAAC,eAAA,GAAIH,gBAAQ,CAACI,IAAI;AACzC;AAKA,SAOgBC,oBAAoBA;;EAClC,IAAMC,cAAc,IAAAC,eAAA,OAAAA,eAAA,CACjBP,gBAAQ,CAACQ,KAAK,IAAGC,OAAO,CAACC,KAAK,IAAID,OAAO,CAACE,KAAK,EAAAJ,eAAA,CAC/CP,gBAAQ,CAACY,KAAK,IAAGH,OAAO,CAACE,KAAK,EAAAJ,eAAA,CAC9BP,gBAAQ,CAACI,IAAI,IAAGK,OAAO,CAACI,IAAI,EAAAN,eAAA,CAC5BP,gBAAQ,CAACc,IAAI,IAAGL,OAAO,CAACM,IAAI,EAAAR,eAAA,CAC5BP,gBAAQ,CAACgB,KAAK,IAAGP,OAAO,CAACQ,KAAK,EAAAV,eAAA,CAChC;EAED,OAAO,UAACW,KAAK;IACX,IAAMC,MAAM,GAAGb,cAAc,CAACY,KAAK,CAAChB,KAAK,CAAC,IAAIO,OAAO,CAACW,GAAG;IACzD,IAAMC,KAAK,GAAc,EAAE;IAG3B,IAAIH,KAAK,CAACI,MAAM,EAAE;MAChBD,KAAK,CAACE,IAAI,CAACL,KAAK,CAACI,MAAM,CAAC;;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AiC;IAAA,OACvDkC,aAAa,CAAC9C,IAAI,CAACW,OAAO,EAAEC,OAAO,CAAC;;EACtCV,IAAI,EAAE,SAAAA,KAACS,OAAe,EAAEC,OAAiC;IAAA,OACvDkC,aAAa,CAAC5C,IAAI,CAACS,OAAO,EAAEC,OAAO,CAAC;;EACtCR,KAAK,EAAE,SAAAA,MAACO,OAAe,EAAEC,OAAiC;IAAA,OACxDkC,aAAa,CAAC1C,KAAK,CAACO,OAAO,EAAEC,OAAO,CAAC;;EACvCe,QAAQ,EAAE,SAAAA,SAACtC,KAAuC;IAAA,OAChDyD,aAAa,CAACnB,QAAQ,CAACtC,KAAK,CAAC;;EAC/BiD,WAAW,EAAE,SAAAA,YAAC1B,OAAgC;IAAA,OAC5CkC,aAAa,CAACR,WAAW,CAAC1B,OAAO,CAAC;;EACpC2B,UAAU,EAAE,SAAAA,WAAC9B,MAAc;IAAA,OAAKqC,aAAa,CAACP,UAAU,CAAC9B,MAAM,CAAC;;EAChEuB,KAAK,EAAE,SAAAA;IAAA,OAAMc,aAAa,CAACd,KAAK,EAAE;;CACnC;;;;;;;"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";function e(){return(e=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var o in n)Object.prototype.hasOwnProperty.call(n,o)&&(e[o]=n[o])}return e}).apply(this,arguments)}var t;function n(e){var t;return"number"==typeof e?e:null!=(t=exports.LogLevel[e])?t:exports.LogLevel.INFO}Object.defineProperty(exports,"__esModule",{value:!0}),(t=exports.LogLevel||(exports.LogLevel={}))[t.TRACE=0]="TRACE",t[t.DEBUG=1]="DEBUG",t[t.INFO=2]="INFO",t[t.WARN=3]="WARN",t[t.ERROR=4]="ERROR",t[t.SILENT=5]="SILENT";var o=function(){function t(e){var t,o;void 0===e&&(e={}),this.level=e.level?n(e.level):exports.LogLevel.INFO,this.handler=e.handler||((t={})[exports.LogLevel.TRACE]=console.trace||console.debug,t[exports.LogLevel.DEBUG]=console.debug,t[exports.LogLevel.INFO]=console.info,t[exports.LogLevel.WARN]=console.warn,t[exports.LogLevel.ERROR]=console.error,o=t,function(e){var t=o[e.level]||console.log,n=[];e.prefix&&n.push(e.prefix),n.push(e.message),e.context&&Object.keys(e.context).length>0&&n.push("\nContext:",e.context),e.metadata&&Object.keys(e.metadata).length>0&&n.push("\nMetadata:",e.metadata),e.error&&n.push("\nError:",e.error),t.apply(void 0,n)}),this.enableTimestamp=void 0===e.enableTimestamp||e.enableTimestamp,this.defaultContext=e.defaultContext,this.defaultPrefix=e.defaultPrefix}var o=t.prototype;return o.setLevel=function(e){this.level=n(e)},o.getLevel=function(){return this.level},o.setHandler=function(e){this.handler=e},o.setDefaultContext=function(e){this.defaultContext=e},o.setDefaultPrefix=function(e){this.defaultPrefix=e},o.chain=function(){return new r(this)},o.trace=function(e,t){this.log(exports.LogLevel.TRACE,e,t)},o.debug=function(e,t){this.log(exports.LogLevel.DEBUG,e,t)},o.info=function(e,t){this.log(exports.LogLevel.INFO,e,t)},o.warn=function(e,t){this.log(exports.LogLevel.WARN,e,t)},o.error=function(e,t){this.log(exports.LogLevel.ERROR,e,t)},o.log=function(t,n,o){if(!(t<this.level)){var r={level:t,message:n,timestamp:this.enableTimestamp?Date.now():0,prefix:this.defaultPrefix};(this.defaultContext||o)&&(r.context=e({},this.defaultContext,o)),this.handler(r)}},o.withContext=function(e){return new r(this).withContext(e)},o.withPrefix=function(e){return new r(this).withPrefix(e)},t}(),r=function(){function t(e){this.logger=e}var n=t.prototype;return n.withContext=function(t){return this.context=e({},this.context,t),this},n.withMetadata=function(t){return this.metadata=e({},this.metadata,t),this},n.withError=function(e){return this.errorObj=e,this},n.withPrefix=function(e){return this.prefix=e,this},n.createEntry=function(t,n){var o={level:t,message:n,timestamp:this.logger.enableTimestamp?Date.now():0,prefix:this.prefix||this.logger.defaultPrefix},r=this.logger.defaultContext;return(r||this.context)&&(o.context=e({},r,this.context)),this.metadata&&(o.metadata=this.metadata),this.errorObj&&(o.error=this.errorObj),o},n.log=function(e,t){if(!(e<this.logger.getLevel())){var n=this.createEntry(e,t);this.logger.handler(n)}},n.trace=function(e){this.log(exports.LogLevel.TRACE,e)},n.debug=function(e){this.log(exports.LogLevel.DEBUG,e)},n.info=function(e){this.log(exports.LogLevel.INFO,e)},n.warn=function(e){this.log(exports.LogLevel.WARN,e)},n.error=function(e){this.log(exports.LogLevel.ERROR,e)},t}(),i=new o,s={trace:function(e,t){return i.trace(e,t)},debug:function(e,t){return i.debug(e,t)},info:function(e,t){return i.info(e,t)},warn:function(e,t){return i.warn(e,t)},error:function(e,t){return i.error(e,t)},setLevel:function(e){return i.setLevel(e)},withContext:function(e){return i.withContext(e)},withPrefix:function(e){return i.withPrefix(e)},chain:function(){return i.chain()}};exports.Logger=o,exports.default=o,exports.defaultLogger=i,exports.log=s;
|
|
2
|
+
//# sourceMappingURL=log.cjs.production.min.js.map
|