@groundbrick/logger 0.0.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/README.md +257 -0
- package/dist/environment.d.ts +8 -0
- package/dist/environment.d.ts.map +1 -0
- package/dist/environment.js +13 -0
- package/dist/environment.js.map +1 -0
- package/dist/file-handlers.d.ts +45 -0
- package/dist/file-handlers.d.ts.map +1 -0
- package/dist/file-handlers.js +156 -0
- package/dist/file-handlers.js.map +1 -0
- package/dist/formatter.d.ts +10 -0
- package/dist/formatter.d.ts.map +1 -0
- package/dist/formatter.js +46 -0
- package/dist/formatter.js.map +1 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +9 -0
- package/dist/index.js.map +1 -0
- package/dist/logger.d.ts +6 -0
- package/dist/logger.d.ts.map +1 -0
- package/dist/logger.js +213 -0
- package/dist/logger.js.map +1 -0
- package/dist/outputs.d.ts +45 -0
- package/dist/outputs.d.ts.map +1 -0
- package/dist/outputs.js +225 -0
- package/dist/outputs.js.map +1 -0
- package/dist/types.d.ts +76 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/package.json +56 -0
package/README.md
ADDED
|
@@ -0,0 +1,257 @@
|
|
|
1
|
+
# @groundbrick/logger
|
|
2
|
+
|
|
3
|
+
A structured logging and error handling library for the microframework ecosystem.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- **Structured Logging**: JSON and pretty-print formats
|
|
8
|
+
- **Multiple Outputs**: Console, file, and custom handlers
|
|
9
|
+
- **Log Levels**: Debug, info, warn, error with filtering
|
|
10
|
+
- **Child Loggers**: Contextual logging with inheritance
|
|
11
|
+
- **Persistent Metadata**: Attach data to all logs from a logger instance
|
|
12
|
+
- **Performance Timing**: Built-in timer functionality
|
|
13
|
+
- **Error Handling**: Comprehensive error logging with stack traces
|
|
14
|
+
- **File Rotation**: Automatic log file rotation with size limits
|
|
15
|
+
- **TypeScript**: Full type safety and IntelliSense support
|
|
16
|
+
|
|
17
|
+
## Installation
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
npm install @groundbrick/logger
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## Quick Start
|
|
24
|
+
|
|
25
|
+
```typescript
|
|
26
|
+
import { createLogger } from '@groundbrick/logger';
|
|
27
|
+
|
|
28
|
+
const logger = createLogger();
|
|
29
|
+
|
|
30
|
+
logger.info('Application started');
|
|
31
|
+
logger.warn('This is a warning', { userId: '123' });
|
|
32
|
+
logger.error('Something went wrong', new Error('Database connection failed'));
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
## Configuration
|
|
36
|
+
|
|
37
|
+
### Basic Configuration
|
|
38
|
+
|
|
39
|
+
```typescript
|
|
40
|
+
import { createLogger } from '@groundbrick/logger';
|
|
41
|
+
|
|
42
|
+
const logger = createLogger({
|
|
43
|
+
level: 'debug',
|
|
44
|
+
format: 'json',
|
|
45
|
+
context: 'my-service',
|
|
46
|
+
outputs: [
|
|
47
|
+
{ type: 'console' },
|
|
48
|
+
{
|
|
49
|
+
type: 'file',
|
|
50
|
+
options: {
|
|
51
|
+
filePath: './logs/app.log',
|
|
52
|
+
maxSize: 10 * 1024 * 1024, // 10MB
|
|
53
|
+
maxFiles: 5
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
]
|
|
57
|
+
});
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
### Environment Variables
|
|
61
|
+
|
|
62
|
+
You can configure the logger using environment variables:
|
|
63
|
+
|
|
64
|
+
```bash
|
|
65
|
+
LOG_LEVEL=debug
|
|
66
|
+
LOG_FORMAT=json
|
|
67
|
+
NODE_ENV=production
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
## Usage Examples
|
|
71
|
+
|
|
72
|
+
### Basic Logging
|
|
73
|
+
|
|
74
|
+
```typescript
|
|
75
|
+
logger.debug('Debug information', { query: 'SELECT * FROM users' });
|
|
76
|
+
logger.info('User logged in', { userId: '123', ip: '192.168.1.1' });
|
|
77
|
+
logger.warn('Rate limit approaching', { requests: 95, limit: 100 });
|
|
78
|
+
logger.error('Database error', error, { operation: 'user-fetch' });
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
### Child Loggers
|
|
82
|
+
|
|
83
|
+
```typescript
|
|
84
|
+
const dbLogger = logger.child('database');
|
|
85
|
+
const userLogger = dbLogger.child('users');
|
|
86
|
+
|
|
87
|
+
userLogger.info('Fetching user'); // Context: "database:users"
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
### Persistent Metadata
|
|
91
|
+
|
|
92
|
+
```typescript
|
|
93
|
+
logger.addMetadata('version', '1.0.0');
|
|
94
|
+
logger.addMetadata('environment', 'production');
|
|
95
|
+
|
|
96
|
+
// All subsequent logs will include this metadata
|
|
97
|
+
logger.info('This log includes version and environment');
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
### Performance Timing
|
|
101
|
+
|
|
102
|
+
```typescript
|
|
103
|
+
const endTimer = logger.startTimer('database-query');
|
|
104
|
+
|
|
105
|
+
// Perform some operation
|
|
106
|
+
await db.query('SELECT * FROM users');
|
|
107
|
+
|
|
108
|
+
endTimer(); // Logs: "Timer database-query completed" with duration
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
### Custom Output Handler
|
|
112
|
+
|
|
113
|
+
```typescript
|
|
114
|
+
const logger = createLogger({
|
|
115
|
+
outputs: [
|
|
116
|
+
{
|
|
117
|
+
type: 'custom',
|
|
118
|
+
options: {
|
|
119
|
+
customHandler: async (entry) => {
|
|
120
|
+
// Send to external service
|
|
121
|
+
await sendToLogService(entry);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
]
|
|
126
|
+
});
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
### File Logging with Rotation
|
|
130
|
+
|
|
131
|
+
```typescript
|
|
132
|
+
const logger = createLogger({
|
|
133
|
+
outputs: [
|
|
134
|
+
{
|
|
135
|
+
type: 'file',
|
|
136
|
+
options: {
|
|
137
|
+
filePath: './logs/app.log',
|
|
138
|
+
maxSize: 5 * 1024 * 1024, // 5MB per file
|
|
139
|
+
maxFiles: 10 // Keep 10 files max
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
]
|
|
143
|
+
});
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
## Log Entry Structure
|
|
147
|
+
|
|
148
|
+
Each log entry follows this structure:
|
|
149
|
+
|
|
150
|
+
```typescript
|
|
151
|
+
interface LogEntry {
|
|
152
|
+
timestamp: string;
|
|
153
|
+
level: 'debug' | 'info' | 'warn' | 'error';
|
|
154
|
+
message: string;
|
|
155
|
+
context?: string;
|
|
156
|
+
metadata?: Record<string, any>;
|
|
157
|
+
error?: {
|
|
158
|
+
name: string;
|
|
159
|
+
message: string;
|
|
160
|
+
stack?: string;
|
|
161
|
+
code?: string | number;
|
|
162
|
+
};
|
|
163
|
+
request?: {
|
|
164
|
+
id?: string;
|
|
165
|
+
method?: string;
|
|
166
|
+
url?: string;
|
|
167
|
+
userAgent?: string;
|
|
168
|
+
ip?: string;
|
|
169
|
+
};
|
|
170
|
+
performance?: {
|
|
171
|
+
duration?: number;
|
|
172
|
+
memory?: NodeJS.MemoryUsage;
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
## Output Formats
|
|
178
|
+
|
|
179
|
+
### Pretty Format (Development)
|
|
180
|
+
|
|
181
|
+
```
|
|
182
|
+
2024-01-15T10:30:00.000Z INFO [my-service] User logged in
|
|
183
|
+
{
|
|
184
|
+
"userId": "123",
|
|
185
|
+
"ip": "192.168.1.1"
|
|
186
|
+
}
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
### JSON Format (Production)
|
|
190
|
+
|
|
191
|
+
```json
|
|
192
|
+
{
|
|
193
|
+
"timestamp": "2024-01-15T10:30:00.000Z",
|
|
194
|
+
"level": "info",
|
|
195
|
+
"message": "User logged in",
|
|
196
|
+
"context": "my-service",
|
|
197
|
+
"metadata": {
|
|
198
|
+
"userId": "123",
|
|
199
|
+
"ip": "192.168.1.1"
|
|
200
|
+
},
|
|
201
|
+
"performance": {
|
|
202
|
+
"memory": { ... }
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
## Integration with Other Packages
|
|
208
|
+
|
|
209
|
+
This logger is designed to integrate seamlessly with other microframework packages:
|
|
210
|
+
|
|
211
|
+
```typescript
|
|
212
|
+
// In repository layer
|
|
213
|
+
import { createLogger } from '@groundbrick/logger';
|
|
214
|
+
|
|
215
|
+
export class BaseRepository {
|
|
216
|
+
protected logger = createLogger().child('repository');
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
// In service layer
|
|
220
|
+
export class BaseService {
|
|
221
|
+
protected logger = createLogger().child('service');
|
|
222
|
+
}
|
|
223
|
+
```
|
|
224
|
+
|
|
225
|
+
## API Reference
|
|
226
|
+
|
|
227
|
+
### Logger Interface
|
|
228
|
+
|
|
229
|
+
```typescript
|
|
230
|
+
interface Logger {
|
|
231
|
+
debug(message: string, metadata?: Record<string, any>): void;
|
|
232
|
+
info(message: string, metadata?: Record<string, any>): void;
|
|
233
|
+
warn(message: string, metadata?: Record<string, any>): void;
|
|
234
|
+
error(message: string, error?: Error, metadata?: Record<string, any>): void;
|
|
235
|
+
child(context: string): Logger;
|
|
236
|
+
setLevel(level: LogLevel): void;
|
|
237
|
+
addMetadata(key: string, value: any): void;
|
|
238
|
+
startTimer(label: string): () => void;
|
|
239
|
+
}
|
|
240
|
+
```
|
|
241
|
+
|
|
242
|
+
### Configuration Options
|
|
243
|
+
|
|
244
|
+
```typescript
|
|
245
|
+
interface LoggerConfig {
|
|
246
|
+
level: 'debug' | 'info' | 'warn' | 'error';
|
|
247
|
+
format: 'json' | 'pretty';
|
|
248
|
+
includeTimestamp: boolean;
|
|
249
|
+
includeStack: boolean;
|
|
250
|
+
context?: string;
|
|
251
|
+
outputs: LogOutput[];
|
|
252
|
+
}
|
|
253
|
+
```
|
|
254
|
+
|
|
255
|
+
## License
|
|
256
|
+
|
|
257
|
+
MIT
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"environment.d.ts","sourceRoot":"","sources":["../src/environment.ts"],"names":[],"mappings":"AACA,MAAM,WAAW,kBAAkB;IACjC,MAAM,EAAE,OAAO,CAAC;IAChB,SAAS,EAAE,OAAO,CAAC;IACnB,WAAW,EAAE,OAAO,CAAC;CACtB;AAED,wBAAgB,iBAAiB,IAAI,kBAAkB,CAatD;AAED,eAAO,MAAM,GAAG,oBAAsB,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export function detectEnvironment() {
|
|
2
|
+
const isNode = typeof process !== 'undefined' &&
|
|
3
|
+
process.versions != null &&
|
|
4
|
+
process.versions.node != null;
|
|
5
|
+
const isBrowser = (typeof globalThis !== 'undefined' && 'window' in globalThis) ||
|
|
6
|
+
(typeof globalThis !== 'undefined' && 'document' in globalThis);
|
|
7
|
+
const isWebWorker = typeof globalThis !== 'undefined' &&
|
|
8
|
+
'importScripts' in globalThis &&
|
|
9
|
+
!isBrowser;
|
|
10
|
+
return { isNode, isBrowser, isWebWorker };
|
|
11
|
+
}
|
|
12
|
+
export const ENV = detectEnvironment();
|
|
13
|
+
//# sourceMappingURL=environment.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"environment.js","sourceRoot":"","sources":["../src/environment.ts"],"names":[],"mappings":"AAOA,MAAM,UAAU,iBAAiB;IAC/B,MAAM,MAAM,GAAG,OAAO,OAAO,KAAK,WAAW;QAC9B,OAAO,CAAC,QAAQ,IAAI,IAAI;QACxB,OAAO,CAAC,QAAQ,CAAC,IAAI,IAAI,IAAI,CAAC;IAE7C,MAAM,SAAS,GAAG,CAAC,OAAO,UAAU,KAAK,WAAW,IAAI,QAAQ,IAAI,UAAU,CAAC;QAC7D,CAAC,OAAO,UAAU,KAAK,WAAW,IAAI,UAAU,IAAI,UAAU,CAAC,CAAC;IAElF,MAAM,WAAW,GAAG,OAAO,UAAU,KAAK,WAAW;QACjC,eAAe,IAAI,UAAU;QAC7B,CAAC,SAAS,CAAC;IAE/B,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,WAAW,EAAE,CAAC;AAC5C,CAAC;AAED,MAAM,CAAC,MAAM,GAAG,GAAG,iBAAiB,EAAE,CAAC"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
export interface FileHandler {
|
|
2
|
+
write(content: string): Promise<void>;
|
|
3
|
+
initialize(): Promise<void>;
|
|
4
|
+
rotate?(): Promise<void>;
|
|
5
|
+
}
|
|
6
|
+
export interface FileConfig {
|
|
7
|
+
filePath: string;
|
|
8
|
+
maxSize?: number;
|
|
9
|
+
maxFiles?: number;
|
|
10
|
+
}
|
|
11
|
+
export declare class NodeFileHandler implements FileHandler {
|
|
12
|
+
private readonly config;
|
|
13
|
+
private currentFileSize;
|
|
14
|
+
private fileIndex;
|
|
15
|
+
private initialized;
|
|
16
|
+
constructor(config: FileConfig);
|
|
17
|
+
initialize(): Promise<void>;
|
|
18
|
+
write(content: string): Promise<void>;
|
|
19
|
+
rotate(): Promise<void>;
|
|
20
|
+
private getCurrentFilePath;
|
|
21
|
+
private getFilePathForIndex;
|
|
22
|
+
}
|
|
23
|
+
export declare class BrowserStorageHandler implements FileHandler {
|
|
24
|
+
private readonly storageKey;
|
|
25
|
+
private readonly maxEntries;
|
|
26
|
+
private readonly storage;
|
|
27
|
+
constructor(config: FileConfig);
|
|
28
|
+
initialize(): Promise<void>;
|
|
29
|
+
write(content: string): Promise<void>;
|
|
30
|
+
private getLogs;
|
|
31
|
+
retrieveLogs(): Array<{
|
|
32
|
+
timestamp: string;
|
|
33
|
+
content: string;
|
|
34
|
+
}>;
|
|
35
|
+
clearLogs(): void;
|
|
36
|
+
}
|
|
37
|
+
export declare class NoOpFileHandler implements FileHandler {
|
|
38
|
+
private readonly config;
|
|
39
|
+
private warned;
|
|
40
|
+
constructor(config: FileConfig);
|
|
41
|
+
initialize(): Promise<void>;
|
|
42
|
+
write(_content: string): Promise<void>;
|
|
43
|
+
}
|
|
44
|
+
export declare function createFileHandler(config: FileConfig): FileHandler;
|
|
45
|
+
//# sourceMappingURL=file-handlers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"file-handlers.d.ts","sourceRoot":"","sources":["../src/file-handlers.ts"],"names":[],"mappings":"AAGA,MAAM,WAAW,WAAW;IACxB,KAAK,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACtC,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IAC5B,MAAM,CAAC,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CAC5B;AAED,MAAM,WAAW,UAAU;IACvB,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,QAAQ,CAAC,EAAE,MAAM,CAAC;CACrB;AAGD,qBAAa,eAAgB,YAAW,WAAW;IAM3C,OAAO,CAAC,QAAQ,CAAC,MAAM;IAL3B,OAAO,CAAC,eAAe,CAAK;IAC5B,OAAO,CAAC,SAAS,CAAK;IACtB,OAAO,CAAC,WAAW,CAAS;gBAGP,MAAM,EAAE,UAAU;IAGjC,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;IAyB3B,KAAK,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAoBrC,MAAM,IAAI,OAAO,CAAC,IAAI,CAAC;IAkB7B,OAAO,CAAC,kBAAkB;IAI1B,OAAO,CAAC,mBAAmB;CAQ9B;AAGD,qBAAa,qBAAsB,YAAW,WAAW;IACrD,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAS;IACpC,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAS;IACpC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAM;gBAElB,MAAM,EAAE,UAAU;IAQxB,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;IAI3B,KAAK,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAkB3C,OAAO,CAAC,OAAO;IASR,YAAY,IAAI,KAAK,CAAC;QAAE,SAAS,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE,CAAC;IAK7D,SAAS,IAAI,IAAI;CAG3B;AAGD,qBAAa,eAAgB,YAAW,WAAW;IAGnC,OAAO,CAAC,QAAQ,CAAC,MAAM;IAFnC,OAAO,CAAC,MAAM,CAAS;gBAEM,MAAM,EAAE,UAAU;IAEzC,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;IAI3B,KAAK,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;CAM/C;AAGD,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,UAAU,GAAG,WAAW,CAQjE"}
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
import { ENV } from './environment.js';
|
|
2
|
+
// Node.js File Handler
|
|
3
|
+
export class NodeFileHandler {
|
|
4
|
+
config;
|
|
5
|
+
currentFileSize = 0;
|
|
6
|
+
fileIndex = 0;
|
|
7
|
+
initialized = false;
|
|
8
|
+
constructor(config) {
|
|
9
|
+
this.config = config;
|
|
10
|
+
}
|
|
11
|
+
async initialize() {
|
|
12
|
+
if (this.initialized)
|
|
13
|
+
return;
|
|
14
|
+
try {
|
|
15
|
+
const { mkdir, stat, writeFile } = await import('fs/promises');
|
|
16
|
+
const { dirname, resolve } = await import('path');
|
|
17
|
+
const dirPath = dirname(resolve(this.config.filePath));
|
|
18
|
+
await mkdir(dirPath, { recursive: true });
|
|
19
|
+
try {
|
|
20
|
+
const stats = await stat(this.getCurrentFilePath());
|
|
21
|
+
this.currentFileSize = stats.size;
|
|
22
|
+
}
|
|
23
|
+
catch {
|
|
24
|
+
// File doesn't exist, create it
|
|
25
|
+
await writeFile(this.getCurrentFilePath(), '', 'utf8');
|
|
26
|
+
this.currentFileSize = 0;
|
|
27
|
+
}
|
|
28
|
+
this.initialized = true;
|
|
29
|
+
}
|
|
30
|
+
catch (error) {
|
|
31
|
+
throw new Error(`Failed to initialize log file: ${error}`);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
async write(content) {
|
|
35
|
+
if (!this.initialized) {
|
|
36
|
+
await this.initialize();
|
|
37
|
+
}
|
|
38
|
+
try {
|
|
39
|
+
const { appendFile } = await import('fs/promises');
|
|
40
|
+
const logSize = Buffer.byteLength(content, 'utf8');
|
|
41
|
+
if (this.config.maxSize && this.currentFileSize + logSize > this.config.maxSize) {
|
|
42
|
+
await this.rotate();
|
|
43
|
+
}
|
|
44
|
+
await appendFile(this.getCurrentFilePath(), content, 'utf8');
|
|
45
|
+
this.currentFileSize += logSize;
|
|
46
|
+
}
|
|
47
|
+
catch (error) {
|
|
48
|
+
console.error('Failed to write to log file:', error);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
async rotate() {
|
|
52
|
+
this.fileIndex++;
|
|
53
|
+
this.currentFileSize = 0;
|
|
54
|
+
// Clean up old files
|
|
55
|
+
if (this.config.maxFiles && this.fileIndex >= this.config.maxFiles) {
|
|
56
|
+
const oldFileIndex = this.fileIndex - this.config.maxFiles;
|
|
57
|
+
const oldFilePath = this.getFilePathForIndex(oldFileIndex);
|
|
58
|
+
try {
|
|
59
|
+
const { unlink } = await import('fs/promises');
|
|
60
|
+
await unlink(oldFilePath);
|
|
61
|
+
}
|
|
62
|
+
catch {
|
|
63
|
+
// File might not exist, ignore error
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
getCurrentFilePath() {
|
|
68
|
+
return this.getFilePathForIndex(this.fileIndex);
|
|
69
|
+
}
|
|
70
|
+
getFilePathForIndex(index) {
|
|
71
|
+
if (index === 0) {
|
|
72
|
+
return this.config.filePath;
|
|
73
|
+
}
|
|
74
|
+
const extension = this.config.filePath.split('.').pop() || '';
|
|
75
|
+
const baseName = this.config.filePath.slice(0, -(extension.length + 1));
|
|
76
|
+
return `${baseName}.${index}.${extension}`;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
// Browser Storage Handler
|
|
80
|
+
export class BrowserStorageHandler {
|
|
81
|
+
storageKey;
|
|
82
|
+
maxEntries;
|
|
83
|
+
storage;
|
|
84
|
+
constructor(config) {
|
|
85
|
+
// Use filename as storage key
|
|
86
|
+
const filename = config.filePath.split('/').pop() || 'app-logs';
|
|
87
|
+
this.storageKey = `logger-${filename}`;
|
|
88
|
+
this.maxEntries = 1000; // Reasonable limit for browser storage
|
|
89
|
+
this.storage = globalThis.localStorage;
|
|
90
|
+
}
|
|
91
|
+
async initialize() {
|
|
92
|
+
// No initialization needed for browser storage
|
|
93
|
+
}
|
|
94
|
+
async write(content) {
|
|
95
|
+
try {
|
|
96
|
+
const logs = this.getLogs();
|
|
97
|
+
logs.push({
|
|
98
|
+
timestamp: new Date().toISOString(),
|
|
99
|
+
content: content.trim()
|
|
100
|
+
});
|
|
101
|
+
if (logs.length > this.maxEntries) {
|
|
102
|
+
logs.splice(0, logs.length - this.maxEntries);
|
|
103
|
+
}
|
|
104
|
+
this.storage.setItem(this.storageKey, JSON.stringify(logs));
|
|
105
|
+
}
|
|
106
|
+
catch (error) {
|
|
107
|
+
console.warn('Failed to write to browser storage:', error);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
getLogs() {
|
|
111
|
+
try {
|
|
112
|
+
return JSON.parse(this.storage.getItem(this.storageKey) || '[]');
|
|
113
|
+
}
|
|
114
|
+
catch {
|
|
115
|
+
return [];
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
// Utility method to retrieve logs
|
|
119
|
+
retrieveLogs() {
|
|
120
|
+
return this.getLogs();
|
|
121
|
+
}
|
|
122
|
+
// Utility method to clear logs
|
|
123
|
+
clearLogs() {
|
|
124
|
+
this.storage.removeItem(this.storageKey);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
// No-op Handler for unsupported environments
|
|
128
|
+
export class NoOpFileHandler {
|
|
129
|
+
config;
|
|
130
|
+
warned = false;
|
|
131
|
+
constructor(config) {
|
|
132
|
+
this.config = config;
|
|
133
|
+
}
|
|
134
|
+
async initialize() {
|
|
135
|
+
// No initialization needed
|
|
136
|
+
}
|
|
137
|
+
async write(_content) {
|
|
138
|
+
if (!this.warned) {
|
|
139
|
+
console.warn(`File logging to '${this.config.filePath}' not available in this environment`);
|
|
140
|
+
this.warned = true;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
// Factory function
|
|
145
|
+
export function createFileHandler(config) {
|
|
146
|
+
if (ENV.isNode) {
|
|
147
|
+
return new NodeFileHandler(config);
|
|
148
|
+
}
|
|
149
|
+
else if (ENV.isBrowser && typeof globalThis !== 'undefined' && 'localStorage' in globalThis) {
|
|
150
|
+
return new BrowserStorageHandler(config);
|
|
151
|
+
}
|
|
152
|
+
else {
|
|
153
|
+
return new NoOpFileHandler(config);
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
//# sourceMappingURL=file-handlers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"file-handlers.js","sourceRoot":"","sources":["../src/file-handlers.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,GAAG,EAAE,MAAM,kBAAkB,CAAC;AAcvC,uBAAuB;AACvB,MAAM,OAAO,eAAe;IAMH;IALb,eAAe,GAAG,CAAC,CAAC;IACpB,SAAS,GAAG,CAAC,CAAC;IACd,WAAW,GAAG,KAAK,CAAC;IAE5B,YACqB,MAAkB;QAAlB,WAAM,GAAN,MAAM,CAAY;IACnC,CAAC;IAEL,KAAK,CAAC,UAAU;QACZ,IAAI,IAAI,CAAC,WAAW;YAAE,OAAO;QAE7B,IAAI,CAAC;YACD,MAAM,EAAE,KAAK,EAAE,IAAI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CAAC,SAAS,IAAI,OAAO,UAAU,KAAK,WAAW,IAAI,cAAc,IAAI,UAAU,EAAE,CAAC;QAC5F,OAAO,IAAI,qBAAqB,CAAC,MAAM,CAAC,CAAC;IAC7C,CAAC;SAAM,CAAC;QACJ,OAAO,IAAI,eAAe,CAAC,MAAM,CAAC,CAAC;IACvC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { LogEntry } from './types.js';
|
|
2
|
+
export declare class LogFormatter {
|
|
3
|
+
private readonly colors;
|
|
4
|
+
formatJson(entry: LogEntry): string;
|
|
5
|
+
formatPretty(entry: LogEntry): string;
|
|
6
|
+
private formatTimestamp;
|
|
7
|
+
private formatLevel;
|
|
8
|
+
}
|
|
9
|
+
export declare const defaultFormatter: LogFormatter;
|
|
10
|
+
//# sourceMappingURL=formatter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"formatter.d.ts","sourceRoot":"","sources":["../src/formatter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAY,MAAM,YAAY,CAAC;AAEhD,qBAAa,YAAY;IACvB,OAAO,CAAC,QAAQ,CAAC,MAAM,CAQrB;IAEF,UAAU,CAAC,KAAK,EAAE,QAAQ,GAAG,MAAM;IAInC,YAAY,CAAC,KAAK,EAAE,QAAQ,GAAG,MAAM;IA6BrC,OAAO,CAAC,eAAe;IAIvB,OAAO,CAAC,WAAW;CAKpB;AAED,eAAO,MAAM,gBAAgB,cAAqB,CAAC"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
export class LogFormatter {
|
|
2
|
+
colors = {
|
|
3
|
+
debug: '\x1b[36m', // cyan
|
|
4
|
+
info: '\x1b[32m', // green
|
|
5
|
+
warn: '\x1b[33m', // yellow
|
|
6
|
+
error: '\x1b[31m', // red
|
|
7
|
+
reset: '\x1b[0m',
|
|
8
|
+
bold: '\x1b[1m',
|
|
9
|
+
dim: '\x1b[2m',
|
|
10
|
+
};
|
|
11
|
+
formatJson(entry) {
|
|
12
|
+
return JSON.stringify(entry);
|
|
13
|
+
}
|
|
14
|
+
formatPretty(entry) {
|
|
15
|
+
const timestamp = this.formatTimestamp(entry.timestamp);
|
|
16
|
+
const level = this.formatLevel(entry.level);
|
|
17
|
+
const context = entry.context ? `[${entry.context}]` : '';
|
|
18
|
+
const message = entry.message;
|
|
19
|
+
let output = `${timestamp} ${level} ${context} ${message}`.trim();
|
|
20
|
+
if (entry.metadata && Object.keys(entry.metadata).length > 0) {
|
|
21
|
+
output += `\n${this.colors.dim}${JSON.stringify(entry.metadata, null, 2)}${this.colors.reset}`;
|
|
22
|
+
}
|
|
23
|
+
if (entry.error?.stack) {
|
|
24
|
+
output += `\n${this.colors.dim}${entry.error.stack}${this.colors.reset}`;
|
|
25
|
+
}
|
|
26
|
+
if (entry.request) {
|
|
27
|
+
const req = entry.request;
|
|
28
|
+
const reqInfo = `${req.method} ${req.url} ${req.ip || ''} ${req.userAgent || ''}`.trim();
|
|
29
|
+
output += `\n${this.colors.dim}Request: ${reqInfo}${this.colors.reset}`;
|
|
30
|
+
}
|
|
31
|
+
if (entry.performance?.duration) {
|
|
32
|
+
output += `\n${this.colors.dim}Duration: ${entry.performance.duration}ms${this.colors.reset}`;
|
|
33
|
+
}
|
|
34
|
+
return output;
|
|
35
|
+
}
|
|
36
|
+
formatTimestamp(timestamp) {
|
|
37
|
+
return `${this.colors.dim}${timestamp}${this.colors.reset}`;
|
|
38
|
+
}
|
|
39
|
+
formatLevel(level) {
|
|
40
|
+
const color = this.colors[level];
|
|
41
|
+
const levelStr = level.toUpperCase().padEnd(5);
|
|
42
|
+
return `${color}${this.colors.bold}${levelStr}${this.colors.reset}`;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
export const defaultFormatter = new LogFormatter();
|
|
46
|
+
//# sourceMappingURL=formatter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"formatter.js","sourceRoot":"","sources":["../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,MAAM,CAAC,MAAM,gBAAgB,GAAG,IAAI,YAAY,EAAE,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { createLogger, createBrowserLogger, createServerLogger, defaultConfig } from './logger.js';
|
|
2
|
+
export { detectEnvironment, ENV } from './environment.js';
|
|
3
|
+
export type { Logger, LogEntry, LogLevel, LoggerConfig, LogOutput, ConsoleOutputOptions, FileOutputOptions, CustomOutputOptions, RemoteOutputOptions } from './types.js';
|
|
4
|
+
export { BaseOutput, ConsoleOutput, FileOutput, CustomOutput, BrowserConsoleOutput, RemoteOutput } from './outputs.js';
|
|
5
|
+
export { createFileHandler, NodeFileHandler, BrowserStorageHandler, NoOpFileHandler } from './file-handlers.js';
|
|
6
|
+
export declare const VERSION = "1.1.0";
|
|
7
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,mBAAmB,EAAE,kBAAkB,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AACnG,OAAO,EAAE,iBAAiB,EAAE,GAAG,EAAE,MAAM,kBAAkB,CAAC;AAC1D,YAAY,EACV,MAAM,EACN,QAAQ,EACR,QAAQ,EACR,YAAY,EACZ,SAAS,EACT,oBAAoB,EACpB,iBAAiB,EACjB,mBAAmB,EACnB,mBAAmB,EACpB,MAAM,YAAY,CAAC;AAGpB,OAAO,EAAE,UAAU,EAAE,aAAa,EAAE,UAAU,EAAE,YAAY,EAAE,oBAAoB,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAGvH,OAAO,EAAE,iBAAiB,EAAE,eAAe,EAAE,qBAAqB,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAGhH,eAAO,MAAM,OAAO,UAAU,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export { createLogger, createBrowserLogger, createServerLogger, defaultConfig } from './logger.js';
|
|
2
|
+
export { detectEnvironment, ENV } from './environment.js';
|
|
3
|
+
// Re-export for convenience
|
|
4
|
+
export { BaseOutput, ConsoleOutput, FileOutput, CustomOutput, BrowserConsoleOutput, RemoteOutput } from './outputs.js';
|
|
5
|
+
// File handler utilities for advanced use cases
|
|
6
|
+
export { createFileHandler, NodeFileHandler, BrowserStorageHandler, NoOpFileHandler } from './file-handlers.js';
|
|
7
|
+
// Package info
|
|
8
|
+
export const VERSION = '1.1.0';
|
|
9
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,mBAAmB,EAAE,kBAAkB,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AACnG,OAAO,EAAE,iBAAiB,EAAE,GAAG,EAAE,MAAM,kBAAkB,CAAC;AAa1D,4BAA4B;AAC5B,OAAO,EAAE,UAAU,EAAE,aAAa,EAAE,UAAU,EAAE,YAAY,EAAE,oBAAoB,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAEvH,gDAAgD;AAChD,OAAO,EAAE,iBAAiB,EAAE,eAAe,EAAE,qBAAqB,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAEhH,eAAe;AACf,MAAM,CAAC,MAAM,OAAO,GAAG,OAAO,CAAC"}
|
package/dist/logger.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { Logger, LoggerConfig } from './types.js';
|
|
2
|
+
export declare function createLogger(config?: Partial<LoggerConfig>): Logger;
|
|
3
|
+
export declare function createBrowserLogger(config?: Partial<LoggerConfig>): Logger;
|
|
4
|
+
export declare function createServerLogger(config?: Partial<LoggerConfig>): Logger;
|
|
5
|
+
export declare const defaultConfig: LoggerConfig;
|
|
6
|
+
//# sourceMappingURL=logger.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../src/logger.ts"],"names":[],"mappings":"AACA,OAAO,EAAsB,MAAM,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAmNtE,wBAAgB,YAAY,CAAC,MAAM,GAAE,OAAO,CAAC,YAAY,CAAM,GAAG,MAAM,CAQvE;AAGD,wBAAgB,mBAAmB,CAAC,MAAM,GAAE,OAAO,CAAC,YAAY,CAAM,GAAG,MAAM,CAY9E;AAGD,wBAAgB,kBAAkB,CAAC,MAAM,GAAE,OAAO,CAAC,YAAY,CAAM,GAAG,MAAM,CAiB7E;AAGD,eAAO,MAAM,aAAa,cAAqB,CAAC"}
|
package/dist/logger.js
ADDED
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
import { createOutput } from './outputs.js';
|
|
2
|
+
import { defaultFormatter } from './formatter.js';
|
|
3
|
+
import { ENV } from './environment.js';
|
|
4
|
+
class MicroLogger {
|
|
5
|
+
config;
|
|
6
|
+
persistentMetadata = {};
|
|
7
|
+
outputs = [];
|
|
8
|
+
constructor(config) {
|
|
9
|
+
this.config = config;
|
|
10
|
+
this.persistentMetadata = { ...config.metadata };
|
|
11
|
+
this.outputs = config.outputs?.map(createOutput) || [];
|
|
12
|
+
}
|
|
13
|
+
debug(message, metadata) {
|
|
14
|
+
if (this.shouldLog('debug')) {
|
|
15
|
+
this.log('debug', message, undefined, metadata);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
info(message, metadata) {
|
|
19
|
+
if (this.shouldLog('info')) {
|
|
20
|
+
this.log('info', message, undefined, metadata);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
warn(message, metadata) {
|
|
24
|
+
if (this.shouldLog('warn')) {
|
|
25
|
+
this.log('warn', message, undefined, metadata);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
error(message, error, metadata) {
|
|
29
|
+
if (this.shouldLog('error')) {
|
|
30
|
+
this.log('error', message, error, metadata);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
child(context, metadata) {
|
|
34
|
+
const childContext = this.config.context
|
|
35
|
+
? `${this.config.context}.${context}`
|
|
36
|
+
: context;
|
|
37
|
+
return new MicroLogger({
|
|
38
|
+
...this.config,
|
|
39
|
+
context: childContext,
|
|
40
|
+
metadata: { ...this.persistentMetadata, ...metadata }
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
addMetadata(key, value) {
|
|
44
|
+
this.persistentMetadata[key] = value;
|
|
45
|
+
}
|
|
46
|
+
removeMetadata(key) {
|
|
47
|
+
delete this.persistentMetadata[key];
|
|
48
|
+
}
|
|
49
|
+
clearMetadata() {
|
|
50
|
+
this.persistentMetadata = {};
|
|
51
|
+
}
|
|
52
|
+
startTimer(name) {
|
|
53
|
+
const startTime = performance.now();
|
|
54
|
+
const startMemory = ENV.isNode && typeof process !== 'undefined'
|
|
55
|
+
? process.memoryUsage()
|
|
56
|
+
: undefined;
|
|
57
|
+
return () => {
|
|
58
|
+
const duration = performance.now() - startTime;
|
|
59
|
+
const endMemory = ENV.isNode && typeof process !== 'undefined'
|
|
60
|
+
? process.memoryUsage()
|
|
61
|
+
: undefined;
|
|
62
|
+
this.info(`Timer ${name} completed`, {
|
|
63
|
+
timer: name,
|
|
64
|
+
duration: Math.round(duration * 100) / 100, // Round to 2 decimal places
|
|
65
|
+
...(startMemory && endMemory && {
|
|
66
|
+
memoryDelta: {
|
|
67
|
+
rss: endMemory.rss - startMemory.rss,
|
|
68
|
+
heapUsed: endMemory.heapUsed - startMemory.heapUsed,
|
|
69
|
+
heapTotal: endMemory.heapTotal - startMemory.heapTotal
|
|
70
|
+
}
|
|
71
|
+
})
|
|
72
|
+
});
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
// Browser-specific utility methods
|
|
76
|
+
retrieveStoredLogs() {
|
|
77
|
+
if (!ENV.isBrowser)
|
|
78
|
+
return null;
|
|
79
|
+
for (const output of this.outputs) {
|
|
80
|
+
if ('retrieveLogs' in output && typeof output.retrieveLogs === 'function') {
|
|
81
|
+
return output.retrieveLogs();
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
return null;
|
|
85
|
+
}
|
|
86
|
+
clearStoredLogs() {
|
|
87
|
+
if (!ENV.isBrowser)
|
|
88
|
+
return;
|
|
89
|
+
for (const output of this.outputs) {
|
|
90
|
+
if ('clearLogs' in output && typeof output.clearLogs === 'function') {
|
|
91
|
+
output.clearLogs();
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
shouldLog(level) {
|
|
96
|
+
const levels = ['debug', 'info', 'warn', 'error'];
|
|
97
|
+
const configLevel = this.config.level || 'info';
|
|
98
|
+
return levels.indexOf(level) >= levels.indexOf(configLevel);
|
|
99
|
+
}
|
|
100
|
+
log(level, message, error, metadata) {
|
|
101
|
+
const entry = this.createLogEntry(level, message, error, metadata);
|
|
102
|
+
const formatted = this.formatEntry(entry);
|
|
103
|
+
// Write to all outputs
|
|
104
|
+
for (const output of this.outputs) {
|
|
105
|
+
try {
|
|
106
|
+
const result = output.write(entry, formatted);
|
|
107
|
+
if (result instanceof Promise) {
|
|
108
|
+
result.catch(err => {
|
|
109
|
+
console.error('Failed to write to output:', err);
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
catch (err) {
|
|
114
|
+
console.error('Failed to write to output:', err);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
createLogEntry(level, message, error, metadata) {
|
|
119
|
+
const entry = {
|
|
120
|
+
timestamp: this.config.includeTimestamp ? new Date().toISOString() : '',
|
|
121
|
+
level,
|
|
122
|
+
message,
|
|
123
|
+
};
|
|
124
|
+
if (this.config.context) {
|
|
125
|
+
entry.context = this.config.context;
|
|
126
|
+
}
|
|
127
|
+
// Merge persistent metadata with provided metadata
|
|
128
|
+
const allMetadata = { ...this.persistentMetadata, ...metadata };
|
|
129
|
+
if (Object.keys(allMetadata).length > 0) {
|
|
130
|
+
entry.metadata = allMetadata;
|
|
131
|
+
}
|
|
132
|
+
if (error) {
|
|
133
|
+
entry.error = {
|
|
134
|
+
name: error.name,
|
|
135
|
+
message: error.message,
|
|
136
|
+
code: error.code,
|
|
137
|
+
};
|
|
138
|
+
if (this.config.includeStack && error.stack) {
|
|
139
|
+
entry.error.stack = error.stack;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
// Add memory usage if available and enabled
|
|
143
|
+
if (ENV.isNode && typeof process !== 'undefined' && process.memoryUsage) {
|
|
144
|
+
entry.performance = {
|
|
145
|
+
memory: process.memoryUsage(),
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
return entry;
|
|
149
|
+
}
|
|
150
|
+
formatEntry(entry) {
|
|
151
|
+
return this.config.format === 'json'
|
|
152
|
+
? defaultFormatter.formatJson(entry)
|
|
153
|
+
: defaultFormatter.formatPretty(entry);
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
// Environment-aware default configuration
|
|
157
|
+
function getDefaultConfig() {
|
|
158
|
+
const processEnv = (typeof process !== 'undefined' && process.env) || {};
|
|
159
|
+
const level = processEnv.LOG_LEVEL || 'info';
|
|
160
|
+
const format = processEnv.LOG_FORMAT || 'pretty';
|
|
161
|
+
return {
|
|
162
|
+
level,
|
|
163
|
+
format,
|
|
164
|
+
includeTimestamp: true,
|
|
165
|
+
includeStack: !ENV.isBrowser && processEnv.NODE_ENV !== 'production',
|
|
166
|
+
outputs: [{
|
|
167
|
+
type: 'console',
|
|
168
|
+
options: ENV.isBrowser ? { enhanced: true } : {}
|
|
169
|
+
}],
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
// Factory function with environment detection
|
|
173
|
+
export function createLogger(config = {}) {
|
|
174
|
+
const defaultConfig = getDefaultConfig();
|
|
175
|
+
const finalConfig = {
|
|
176
|
+
...defaultConfig,
|
|
177
|
+
...config,
|
|
178
|
+
};
|
|
179
|
+
return new MicroLogger(finalConfig);
|
|
180
|
+
}
|
|
181
|
+
// Browser-specific factory with enhanced defaults
|
|
182
|
+
export function createBrowserLogger(config = {}) {
|
|
183
|
+
const browserDefaults = {
|
|
184
|
+
format: 'pretty',
|
|
185
|
+
includeTimestamp: true,
|
|
186
|
+
includeStack: false,
|
|
187
|
+
outputs: [
|
|
188
|
+
{ type: 'console', options: { enhanced: true } },
|
|
189
|
+
...(config.outputs || [])
|
|
190
|
+
]
|
|
191
|
+
};
|
|
192
|
+
return createLogger({ ...browserDefaults, ...config });
|
|
193
|
+
}
|
|
194
|
+
// Node.js-specific factory with enhanced defaults
|
|
195
|
+
export function createServerLogger(config = {}) {
|
|
196
|
+
const processEnv = (typeof process !== 'undefined' && process.env) || {};
|
|
197
|
+
const level = processEnv.LOG_LEVEL || 'info';
|
|
198
|
+
const format = processEnv.LOG_FORMAT || 'pretty';
|
|
199
|
+
const serverDefaults = {
|
|
200
|
+
level,
|
|
201
|
+
format,
|
|
202
|
+
includeTimestamp: true,
|
|
203
|
+
includeStack: !ENV.isBrowser && processEnv.NODE_ENV !== 'production',
|
|
204
|
+
outputs: [{
|
|
205
|
+
type: 'console',
|
|
206
|
+
options: ENV.isBrowser ? { enhanced: true } : {}
|
|
207
|
+
}],
|
|
208
|
+
};
|
|
209
|
+
return createLogger({ ...serverDefaults, ...config });
|
|
210
|
+
}
|
|
211
|
+
// Convenience export
|
|
212
|
+
export const defaultConfig = getDefaultConfig();
|
|
213
|
+
//# sourceMappingURL=logger.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger.js","sourceRoot":"","sources":["../src/logger.ts"],"names":[],"mappings":"AAEA,OAAO,EAAc,YAAY,EAAE,MAAM,cAAc,CAAC;AACxD,OAAO,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAClD,OAAO,EAAE,GAAG,EAAE,MAAM,kBAAkB,CAAC;AAEvC,MAAM,WAAW;IAIO;IAHZ,kBAAkB,GA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AAE,IAAI;QACtB,YAAY,EAAE,CAAC,GAAG,CAAC,SAAS,IAAI,UAAU,CAAC,QAAQ,KAAK,YAAY;QACpE,OAAO,EAAE,CAAC;gBACN,IAAI,EAAE,SAAS;gBACf,OAAO,EAAE,GAAG,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE;aACnD,CAAC;KACL,CAAC;IAEF,OAAO,YAAY,CAAC,EAAE,GAAG,cAAc,EAAE,GAAG,MAAM,EAAE,CAAC,CAAC;AAC1D,CAAC;AAED,qBAAqB;AACrB,MAAM,CAAC,MAAM,aAAa,GAAG,gBAAgB,EAAE,CAAC"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { LogEntry, LogOutput } from './types.js';
|
|
2
|
+
export declare abstract class BaseOutput {
|
|
3
|
+
abstract write(entry: LogEntry, formatted: string): Promise<void> | void;
|
|
4
|
+
}
|
|
5
|
+
export declare class ConsoleOutput extends BaseOutput {
|
|
6
|
+
write(entry: LogEntry, formatted: string): void;
|
|
7
|
+
}
|
|
8
|
+
export declare class FileOutput extends BaseOutput {
|
|
9
|
+
private readonly filePath;
|
|
10
|
+
private readonly maxSize;
|
|
11
|
+
private readonly maxFiles;
|
|
12
|
+
private fileHandler;
|
|
13
|
+
private initPromise;
|
|
14
|
+
constructor(filePath: string, maxSize?: number, // 10MB
|
|
15
|
+
maxFiles?: number);
|
|
16
|
+
write(entry: LogEntry, formatted: string): Promise<void>;
|
|
17
|
+
retrieveLogs(): Array<{
|
|
18
|
+
timestamp: string;
|
|
19
|
+
content: string;
|
|
20
|
+
}> | null;
|
|
21
|
+
clearLogs(): void;
|
|
22
|
+
}
|
|
23
|
+
export declare class CustomOutput extends BaseOutput {
|
|
24
|
+
private readonly handler;
|
|
25
|
+
constructor(handler: (entry: LogEntry) => void | Promise<void>);
|
|
26
|
+
write(entry: LogEntry): Promise<void>;
|
|
27
|
+
}
|
|
28
|
+
export declare class BrowserConsoleOutput extends BaseOutput {
|
|
29
|
+
write(entry: LogEntry, formatted: string): void;
|
|
30
|
+
private getConsoleStyles;
|
|
31
|
+
}
|
|
32
|
+
export declare class RemoteOutput extends BaseOutput {
|
|
33
|
+
private readonly endpoint;
|
|
34
|
+
private readonly batchSize;
|
|
35
|
+
private readonly flushInterval;
|
|
36
|
+
constructor(endpoint: string, batchSize?: number, flushInterval?: number);
|
|
37
|
+
private batch;
|
|
38
|
+
private batchTimer;
|
|
39
|
+
write(entry: LogEntry): Promise<void>;
|
|
40
|
+
private startBatchProcessor;
|
|
41
|
+
private flush;
|
|
42
|
+
destroy(): void;
|
|
43
|
+
}
|
|
44
|
+
export declare function createOutput(config: LogOutput): BaseOutput;
|
|
45
|
+
//# sourceMappingURL=outputs.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"outputs.d.ts","sourceRoot":"","sources":["../src/outputs.ts"],"names":[],"mappings":"AACA,OAAO,EAAgE,QAAQ,EAAE,SAAS,EAAuB,MAAM,YAAY,CAAC;AAIpI,8BAAsB,UAAU;IAC9B,QAAQ,CAAC,KAAK,CAAC,KAAK,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI;CACzE;AAED,qBAAa,aAAc,SAAQ,UAAU;IAC3C,KAAK,CAAC,KAAK,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,GAAG,IAAI;CAIhD;AAED,qBAAa,UAAW,SAAQ,UAAU;IAKtC,OAAO,CAAC,QAAQ,CAAC,QAAQ;IACzB,OAAO,CAAC,QAAQ,CAAC,OAAO;IACxB,OAAO,CAAC,QAAQ,CAAC,QAAQ;IAN3B,OAAO,CAAC,WAAW,CAAc;IACjC,OAAO,CAAC,WAAW,CAA8B;gBAG9B,QAAQ,EAAE,MAAM,EAChB,OAAO,GAAE,MAAyB,EAAE,OAAO;IAC3C,QAAQ,GAAE,MAAU;IAUjC,KAAK,CA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+
export class BaseOutput {
|
|
4
|
+
}
|
|
5
|
+
export class ConsoleOutput extends BaseOutput {
|
|
6
|
+
write(entry, formatted) {
|
|
7
|
+
const method = entry.level === 'error' ? 'error' : entry.level === 'warn' ? 'warn' : 'log';
|
|
8
|
+
console[method](formatted);
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
export class FileOutput extends BaseOutput {
|
|
12
|
+
filePath;
|
|
13
|
+
maxSize;
|
|
14
|
+
maxFiles;
|
|
15
|
+
fileHandler;
|
|
16
|
+
initPromise = null;
|
|
17
|
+
constructor(filePath, maxSize = 10 * 1024 * 1024, // 10MB
|
|
18
|
+
maxFiles = 5) {
|
|
19
|
+
super();
|
|
20
|
+
this.filePath = filePath;
|
|
21
|
+
this.maxSize = maxSize;
|
|
22
|
+
this.maxFiles = maxFiles;
|
|
23
|
+
this.fileHandler = createFileHandler({
|
|
24
|
+
filePath: this.filePath,
|
|
25
|
+
maxSize: this.maxSize,
|
|
26
|
+
maxFiles: this.maxFiles
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
async write(entry, formatted) {
|
|
30
|
+
// Ensure initialization happens only once
|
|
31
|
+
if (!this.initPromise) {
|
|
32
|
+
this.initPromise = this.fileHandler.initialize();
|
|
33
|
+
}
|
|
34
|
+
try {
|
|
35
|
+
await this.initPromise;
|
|
36
|
+
if (entry.level === 'error' && entry.error) {
|
|
37
|
+
formatted += `\nError: ${entry.error.message}\nStack: ${entry.error.stack}`;
|
|
38
|
+
}
|
|
39
|
+
await this.fileHandler.write(formatted + '\n');
|
|
40
|
+
}
|
|
41
|
+
catch (error) {
|
|
42
|
+
console.error('Failed to write to file output:', error);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
// Utility method for browser storage handler
|
|
46
|
+
retrieveLogs() {
|
|
47
|
+
if (this.fileHandler instanceof BrowserStorageHandler) {
|
|
48
|
+
return this.fileHandler.retrieveLogs();
|
|
49
|
+
}
|
|
50
|
+
return null;
|
|
51
|
+
}
|
|
52
|
+
clearLogs() {
|
|
53
|
+
if (this.fileHandler instanceof BrowserStorageHandler) {
|
|
54
|
+
this.fileHandler.clearLogs();
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
export class CustomOutput extends BaseOutput {
|
|
59
|
+
handler;
|
|
60
|
+
constructor(handler) {
|
|
61
|
+
super();
|
|
62
|
+
this.handler = handler;
|
|
63
|
+
}
|
|
64
|
+
async write(entry) {
|
|
65
|
+
try {
|
|
66
|
+
await this.handler(entry);
|
|
67
|
+
}
|
|
68
|
+
catch (error) {
|
|
69
|
+
console.error('Custom log handler failed:', error);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
// Browser-specific output for structured logging
|
|
74
|
+
export class BrowserConsoleOutput extends BaseOutput {
|
|
75
|
+
write(entry, formatted) {
|
|
76
|
+
const styles = this.getConsoleStyles(entry.level);
|
|
77
|
+
if (ENV.isBrowser && console.groupCollapsed) {
|
|
78
|
+
console.groupCollapsed(`%c${entry.level.toUpperCase()}%c ${entry.message}`, styles.level, styles.message);
|
|
79
|
+
if (entry.metadata) {
|
|
80
|
+
console.log('Metadata:', entry.metadata);
|
|
81
|
+
}
|
|
82
|
+
if (entry.error) {
|
|
83
|
+
console.error('Error:', entry.error);
|
|
84
|
+
}
|
|
85
|
+
if (entry.performance) {
|
|
86
|
+
console.log('Performance:', entry.performance);
|
|
87
|
+
}
|
|
88
|
+
console.groupEnd();
|
|
89
|
+
}
|
|
90
|
+
else {
|
|
91
|
+
// Fallback to regular console
|
|
92
|
+
const method = entry.level === 'error' ? 'error' : entry.level === 'warn' ? 'warn' : 'log';
|
|
93
|
+
console[method](formatted);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
getConsoleStyles(level) {
|
|
97
|
+
const baseStyle = 'padding: 2px 4px; border-radius: 2px; font-weight: bold;';
|
|
98
|
+
switch (level) {
|
|
99
|
+
case 'error':
|
|
100
|
+
return {
|
|
101
|
+
level: `${baseStyle} background: #ff4444; color: white;`,
|
|
102
|
+
message: 'color: #ff4444;'
|
|
103
|
+
};
|
|
104
|
+
case 'warn':
|
|
105
|
+
return {
|
|
106
|
+
level: `${baseStyle} background: #ffaa00; color: white;`,
|
|
107
|
+
message: 'color: #ffaa00;'
|
|
108
|
+
};
|
|
109
|
+
case 'info':
|
|
110
|
+
return {
|
|
111
|
+
level: `${baseStyle} background: #0088ff; color: white;`,
|
|
112
|
+
message: 'color: #0088ff;'
|
|
113
|
+
};
|
|
114
|
+
case 'debug':
|
|
115
|
+
return {
|
|
116
|
+
level: `${baseStyle} background: #888888; color: white;`,
|
|
117
|
+
message: 'color: #888888;'
|
|
118
|
+
};
|
|
119
|
+
default:
|
|
120
|
+
return {
|
|
121
|
+
level: baseStyle,
|
|
122
|
+
message: ''
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
// Remote logging output for browser environments
|
|
128
|
+
export class RemoteOutput extends BaseOutput {
|
|
129
|
+
endpoint;
|
|
130
|
+
batchSize;
|
|
131
|
+
flushInterval;
|
|
132
|
+
constructor(endpoint, batchSize = 10, flushInterval = 5000 // 5 seconds
|
|
133
|
+
) {
|
|
134
|
+
super();
|
|
135
|
+
this.endpoint = endpoint;
|
|
136
|
+
this.batchSize = batchSize;
|
|
137
|
+
this.flushInterval = flushInterval;
|
|
138
|
+
this.startBatchProcessor();
|
|
139
|
+
}
|
|
140
|
+
batch = [];
|
|
141
|
+
batchTimer = null;
|
|
142
|
+
async write(entry) {
|
|
143
|
+
this.batch.push(entry);
|
|
144
|
+
if (this.batch.length >= this.batchSize) {
|
|
145
|
+
await this.flush();
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
startBatchProcessor() {
|
|
149
|
+
this.batchTimer = setInterval(() => {
|
|
150
|
+
if (this.batch.length > 0) {
|
|
151
|
+
this.flush().catch(error => {
|
|
152
|
+
console.error('Failed to flush log batch:', error);
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
}, this.flushInterval);
|
|
156
|
+
}
|
|
157
|
+
async flush() {
|
|
158
|
+
if (this.batch.length === 0)
|
|
159
|
+
return;
|
|
160
|
+
const logsToSend = this.batch.splice(0);
|
|
161
|
+
try {
|
|
162
|
+
const response = await fetch(this.endpoint, {
|
|
163
|
+
method: 'POST',
|
|
164
|
+
headers: {
|
|
165
|
+
'Content-Type': 'application/json',
|
|
166
|
+
},
|
|
167
|
+
body: JSON.stringify({ logs: logsToSend }),
|
|
168
|
+
});
|
|
169
|
+
if (!response.ok) {
|
|
170
|
+
throw new Error(`HTTP ${response.status}: ${response.statusText}`);
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
catch (error) {
|
|
174
|
+
console.error('Failed to send logs to remote endpoint:', error);
|
|
175
|
+
// Re-add logs to batch for retry (optional)
|
|
176
|
+
this.batch.unshift(...logsToSend);
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
// Cleanup method
|
|
180
|
+
destroy() {
|
|
181
|
+
if (this.batchTimer) {
|
|
182
|
+
clearInterval(this.batchTimer);
|
|
183
|
+
this.batchTimer = null;
|
|
184
|
+
}
|
|
185
|
+
if (this.batch.length > 0) {
|
|
186
|
+
this.flush().catch(console.error);
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
export function createOutput(config) {
|
|
191
|
+
switch (config.type) {
|
|
192
|
+
case 'console': {
|
|
193
|
+
const options = config.options;
|
|
194
|
+
// Use enhanced browser console in browser environments
|
|
195
|
+
if (ENV.isBrowser && options?.enhanced !== false) {
|
|
196
|
+
return new BrowserConsoleOutput();
|
|
197
|
+
}
|
|
198
|
+
return new ConsoleOutput();
|
|
199
|
+
}
|
|
200
|
+
case 'file': {
|
|
201
|
+
const options = config.options;
|
|
202
|
+
if (!options?.filePath) {
|
|
203
|
+
throw new Error('File output requires filePath option');
|
|
204
|
+
}
|
|
205
|
+
return new FileOutput(options.filePath, options.maxSize, options.maxFiles);
|
|
206
|
+
}
|
|
207
|
+
case 'custom': {
|
|
208
|
+
const options = config.options;
|
|
209
|
+
if (!options?.customHandler) {
|
|
210
|
+
throw new Error('Custom output requires customHandler option');
|
|
211
|
+
}
|
|
212
|
+
return new CustomOutput(options.customHandler);
|
|
213
|
+
}
|
|
214
|
+
case 'remote': {
|
|
215
|
+
const options = config.options;
|
|
216
|
+
if (!options?.endpoint) {
|
|
217
|
+
throw new Error('Remote output requires endpoint option');
|
|
218
|
+
}
|
|
219
|
+
return new RemoteOutput(options.endpoint, options.batchSize, options.flushInterval);
|
|
220
|
+
}
|
|
221
|
+
default:
|
|
222
|
+
throw new Error(`Unknown output type: ${config.type}`);
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
//# sourceMappingURL=outputs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"outputs.js","sourceRoot":"","sources":["../src/outputs.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,iBAAiB,EAAe,qBAAqB,EAAE,MAAM,oBAAoB,CAAC;AAC3F,OAAO,EAAE,GAAG,EAAE,MAAM,kBAAkB,CAAC;AAEvC,MAAM,OAAgB,UAAU;CAE/B;AAED,MAAM,OAAO,aAAc,SAAQ,UAAU;IAC3C,KAAK,CAAC,KAAe,EAAE,SAAiB;QACtC,MAAM,MAAM,GAAG,KAAK,CAAC,KAAK,KAAK,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK,KAAK,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,KAAK,CAAC;QAC3F,OAAO,CAAC,MAAM,CAAC,CAAC,SAAS,CAAC,CAAC;IAC7B,CAAC;CACF;AAED,MAAM,OAAO,UAAW,SAAQ,UAAU;IAKrB;IACA;IACA;IANX,WAAW,CAAc;IACzB,WAAW,GAAyB,IAAI,CAAC;IAEjD,YACmB,QAAgB,EAChB,UAAkB,EAAE,GAAG,IAAI,GAA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AAU,CACnB,OAAO,CAAC,QAAQ,EAChB,OAAO,CAAC,OAAO,EACf,OAAO,CAAC,QAAQ,CACjB,CAAC;QACJ,CAAC;QAED,KAAK,QAAQ,CAAC,CAAC,CAAC;YACd,MAAM,OAAO,GAAG,MAAM,CAAC,OAA0C,CAAC;YAClE,IAAI,CAAC,OAAO,EAAE,aAAa,EAAE,CAAC;gBAC5B,MAAM,IAAI,KAAK,CAAC,6CAA6C,CAAC,CAAC;YACjE,CAAC;YACD,OAAO,IAAI,YAAY,CAAC,OAAO,CAAC,aAAa,CAAC,CAAC;QACjD,CAAC;QAED,KAAK,QAAQ,CAAC,CAAC,CAAC;YACd,MAAM,OAAO,GAAG,MAAM,CAAC,OAA0C,CAAC;YAClE,IAAI,CAAC,OAAO,EAAE,QAAQ,EAAE,CAAC;gBACvB,MAAM,IAAI,KAAK,CAAC,wCAAwC,CAAC,CAAC;YAC5D,CAAC;YACD,OAAO,IAAI,YAAY,CACrB,OAAO,CAAC,QAAQ,EAChB,OAAO,CAAC,SAAS,EACjB,OAAO,CAAC,aAAa,CACtB,CAAC;QACJ,CAAC;QAED;YACE,MAAM,IAAI,KAAK,CAAC,wBAAyB,MAAc,CAAC,IAAI,EAAE,CAAC,CAAC;IACpE,CAAC;AACH,CAAC"}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
export type LogLevel = 'debug' | 'info' | 'warn' | 'error';
|
|
2
|
+
export interface LogEntry {
|
|
3
|
+
timestamp: string;
|
|
4
|
+
level: LogLevel;
|
|
5
|
+
message: string;
|
|
6
|
+
context?: string;
|
|
7
|
+
metadata?: Record<string, any>;
|
|
8
|
+
error?: {
|
|
9
|
+
name: string;
|
|
10
|
+
message: string;
|
|
11
|
+
stack?: string;
|
|
12
|
+
code?: string | number;
|
|
13
|
+
};
|
|
14
|
+
request?: {
|
|
15
|
+
id?: string;
|
|
16
|
+
method?: string;
|
|
17
|
+
url?: string;
|
|
18
|
+
userAgent?: string;
|
|
19
|
+
ip?: string;
|
|
20
|
+
};
|
|
21
|
+
performance?: {
|
|
22
|
+
duration?: number;
|
|
23
|
+
memory?: NodeJS.MemoryUsage;
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
export interface LoggerConfig {
|
|
27
|
+
level?: LogLevel;
|
|
28
|
+
format?: 'json' | 'pretty';
|
|
29
|
+
context?: string;
|
|
30
|
+
includeTimestamp?: boolean;
|
|
31
|
+
includeStack?: boolean;
|
|
32
|
+
metadata?: Record<string, any>;
|
|
33
|
+
outputs?: LogOutput[];
|
|
34
|
+
}
|
|
35
|
+
export interface LogOutput {
|
|
36
|
+
type: 'console' | 'file' | 'custom' | 'remote';
|
|
37
|
+
options?: ConsoleOutputOptions | FileOutputOptions | CustomOutputOptions | RemoteOutputOptions;
|
|
38
|
+
}
|
|
39
|
+
export interface ConsoleOutputOptions {
|
|
40
|
+
enhanced?: boolean;
|
|
41
|
+
}
|
|
42
|
+
export interface FileOutputOptions {
|
|
43
|
+
filePath: string;
|
|
44
|
+
maxSize?: number;
|
|
45
|
+
maxFiles?: number;
|
|
46
|
+
}
|
|
47
|
+
export interface CustomOutputOptions {
|
|
48
|
+
customHandler: (entry: LogEntry) => void | Promise<void>;
|
|
49
|
+
}
|
|
50
|
+
export interface RemoteOutputOptions {
|
|
51
|
+
endpoint: string;
|
|
52
|
+
batchSize?: number;
|
|
53
|
+
flushInterval?: number;
|
|
54
|
+
headers?: Record<string, string>;
|
|
55
|
+
}
|
|
56
|
+
export interface Logger {
|
|
57
|
+
debug(message: string, metadata?: Record<string, any>): void;
|
|
58
|
+
info(message: string, metadata?: Record<string, any>): void;
|
|
59
|
+
warn(message: string, metadata?: Record<string, any>): void;
|
|
60
|
+
error(message: string, error?: Error, metadata?: Record<string, any>): void;
|
|
61
|
+
child(context: string, metadata?: Record<string, any>): Logger;
|
|
62
|
+
addMetadata(key: string, value: any): void;
|
|
63
|
+
removeMetadata(key: string): void;
|
|
64
|
+
clearMetadata(): void;
|
|
65
|
+
startTimer(name: string): () => void;
|
|
66
|
+
retrieveStoredLogs?(): Array<{
|
|
67
|
+
timestamp: string;
|
|
68
|
+
content: string;
|
|
69
|
+
}> | null;
|
|
70
|
+
clearStoredLogs?(): void;
|
|
71
|
+
}
|
|
72
|
+
export interface LogFormatter {
|
|
73
|
+
formatJson(entry: LogEntry): string;
|
|
74
|
+
formatPretty(entry: LogEntry): string;
|
|
75
|
+
}
|
|
76
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AACA,MAAM,MAAM,QAAQ,GAAG,OAAO,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC;AAE3D,MAAM,WAAW,QAAQ;IACrB,SAAS,EAAE,MAAM,CAAC;IAClB,KAAK,EAAE,QAAQ,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAC/B,KAAK,CAAC,EAAE;QACJ,IAAI,EAAE,MAAM,CAAC;QACb,OAAO,EAAE,MAAM,CAAC;QAChB,KAAK,CAAC,EAAE,MAAM,CAAC;QACf,IAAI,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;KAC1B,CAAC;IACF,OAAO,CAAC,EAAE;QACN,EAAE,CAAC,EAAE,MAAM,CAAC;QACZ,MAAM,CAAC,EAAE,MAAM,CAAC;QAChB,GAAG,CAAC,EAAE,MAAM,CAAC;QACb,SAAS,CAAC,EAAE,MAAM,CAAC;QACnB,EAAE,CAAC,EAAE,MAAM,CAAC;KACf,CAAC;IACF,WAAW,CAAC,EAAE;QACV,QAAQ,CAAC,EAAE,MAAM,CAAC;QAClB,MAAM,CAAC,EAAE,MAAM,CAAC,WAAW,CAAC;KAC/B,CAAC;CACL;AAED,MAAM,WA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EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,IAAI,CAAC;IAC5D,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,IAAI,CAAC;IAC5D,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,KAAK,EAAE,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,IAAI,CAAC;IAE5E,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,MAAM,CAAC;IAC/D,WAAW,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,GAAG,IAAI,CAAC;IAC3C,cAAc,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAAC;IAClC,aAAa,IAAI,IAAI,CAAC;IAEtB,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,IAAI,CAAC;IAGrC,kBAAkB,CAAC,IAAI,KAAK,CAAC;QAAE,SAAS,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE,CAAC,GAAG,IAAI,CAAC;IAC5E,eAAe,CAAC,IAAI,IAAI,CAAC;CAC5B;AAED,MAAM,WAAW,YAAY;IACzB,UAAU,CAAC,KAAK,EAAE,QAAQ,GAAG,MAAM,CAAC;IACpC,YAAY,CAAC,KAAK,EAAE,QAAQ,GAAG,MAAM,CAAC;CACzC"}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
|
package/package.json
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@groundbrick/logger",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "Structured logging with multiple outputs and performance timing for TypeScript applications",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.js",
|
|
7
|
+
"module": "./dist/index.mjs",
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"import": "./dist/index.js",
|
|
12
|
+
"require": "./dist/index.js",
|
|
13
|
+
"types": "./dist/index.d.ts"
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
"files": [
|
|
17
|
+
"dist/**/*",
|
|
18
|
+
"README.md",
|
|
19
|
+
"LICENSE"
|
|
20
|
+
],
|
|
21
|
+
"scripts": {
|
|
22
|
+
"build": "tsc",
|
|
23
|
+
"dev": "tsc --watch",
|
|
24
|
+
"clean": "rm -rf dist *.tsbuildinfo"
|
|
25
|
+
},
|
|
26
|
+
"keywords": [
|
|
27
|
+
"typescript",
|
|
28
|
+
"logging",
|
|
29
|
+
"structured-logging",
|
|
30
|
+
"microframework",
|
|
31
|
+
"performance",
|
|
32
|
+
"file-logging",
|
|
33
|
+
"console-logging"
|
|
34
|
+
],
|
|
35
|
+
"author": "Cleiton Marques <cleiton.marques@200.systems>",
|
|
36
|
+
"license": "MIT",
|
|
37
|
+
"repository": {
|
|
38
|
+
"type": "git",
|
|
39
|
+
"url": "git+https://github.com/200Systems/bitbrick-microframework.git",
|
|
40
|
+
"directory": "packages/logger"
|
|
41
|
+
},
|
|
42
|
+
"bugs": {
|
|
43
|
+
"url": "https://github.com/200Systems/bitbrick-microframework/issues"
|
|
44
|
+
},
|
|
45
|
+
"homepage": "https://github.com/200Systems/bitbrick-microframework/tree/main/packages/logger#readme",
|
|
46
|
+
"devDependencies": {
|
|
47
|
+
"@types/node": "^20.19.8",
|
|
48
|
+
"typescript": "^5.8.3"
|
|
49
|
+
},
|
|
50
|
+
"engines": {
|
|
51
|
+
"node": ">=18.0.0"
|
|
52
|
+
},
|
|
53
|
+
"publishConfig": {
|
|
54
|
+
"access": "public"
|
|
55
|
+
}
|
|
56
|
+
}
|