logan-logger 1.0.0
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/LICENSE +9 -0
- package/README.md +245 -0
- package/dist/__vite-browser-external-BcPniuRQ.js +2 -0
- package/dist/__vite-browser-external-BcPniuRQ.js.map +1 -0
- package/dist/__vite-browser-external-DYxpcVy9.mjs +5 -0
- package/dist/__vite-browser-external-DYxpcVy9.mjs.map +1 -0
- package/dist/index.d.ts +376 -0
- package/dist/index.esm.js +642 -0
- package/dist/index.esm.js.map +1 -0
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -0
- package/package.json +73 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Logan Lindquist
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
6
|
+
|
|
7
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
8
|
+
|
|
9
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,245 @@
|
|
|
1
|
+
# Logan Logger
|
|
2
|
+
|
|
3
|
+
[](https://github.com/llbbl/logan-logger-ts/actions/workflows/ci.yml)
|
|
4
|
+
[](https://jsr.io/@logan/logger)
|
|
5
|
+
|
|
6
|
+
A universal TypeScript logging library that works consistently across all JavaScript runtimes: Node.js, Deno, Bun, browsers, and WebAssembly environments.
|
|
7
|
+
|
|
8
|
+
## Features
|
|
9
|
+
|
|
10
|
+
- ð **Universal Runtime Support** - Works in Node.js, Deno, Bun, browsers, and WebAssembly
|
|
11
|
+
- ðŠķ **Zero Dependencies** - Core functionality with no required dependencies
|
|
12
|
+
- ⥠**Performance First** - Lazy evaluation, zero-allocation logging, minimal memory footprint
|
|
13
|
+
- ðŊ **TypeScript Native** - Full type safety with comprehensive type definitions
|
|
14
|
+
- ð§ **Flexible Configuration** - Environment-based auto-configuration or manual setup
|
|
15
|
+
- ð **Safe Serialization** - Handles circular references, Error objects, and sensitive data filtering
|
|
16
|
+
- ðĻ **Rich Browser Support** - Console styling, performance marks, grouping
|
|
17
|
+
- ð **Structured Logging** - Rich metadata support with child loggers
|
|
18
|
+
|
|
19
|
+
## Quick Start
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
npm install logan-logger
|
|
23
|
+
# or
|
|
24
|
+
pnpm add logan-logger
|
|
25
|
+
# or
|
|
26
|
+
yarn add logan-logger
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
### Basic Usage
|
|
30
|
+
|
|
31
|
+
```typescript
|
|
32
|
+
import { createLogger, LogLevel } from 'logan-logger';
|
|
33
|
+
|
|
34
|
+
// Create logger with automatic environment configuration
|
|
35
|
+
const logger = createLogger({
|
|
36
|
+
level: LogLevel.DEBUG,
|
|
37
|
+
colorize: true
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
// Basic logging
|
|
41
|
+
logger.info('Application started');
|
|
42
|
+
logger.warn('Configuration missing', { file: 'config.json' });
|
|
43
|
+
logger.error('Database connection failed', { error: new Error('Connection failed') });
|
|
44
|
+
|
|
45
|
+
// Child loggers with additional context
|
|
46
|
+
const requestLogger = logger.child({
|
|
47
|
+
requestId: 'req-123',
|
|
48
|
+
userId: 'user-456'
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
requestLogger.info('Processing request', { endpoint: '/api/users' });
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
### Advanced Features
|
|
55
|
+
|
|
56
|
+
#### Lazy Evaluation for Performance
|
|
57
|
+
```typescript
|
|
58
|
+
// Function is only called if debug level is enabled
|
|
59
|
+
logger.debug(() => `Expensive computation: ${computeHeavyValue()}`);
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
#### Environment-Based Configuration
|
|
63
|
+
```typescript
|
|
64
|
+
import { createLoggerForEnvironment } from 'logan-logger';
|
|
65
|
+
|
|
66
|
+
// Automatically configures based on NODE_ENV
|
|
67
|
+
const logger = createLoggerForEnvironment();
|
|
68
|
+
// Production: ERROR level, JSON format
|
|
69
|
+
// Development: DEBUG level, colored console
|
|
70
|
+
// Test: WARN level
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
#### Runtime-Specific Features
|
|
74
|
+
|
|
75
|
+
**Node.js with Winston:**
|
|
76
|
+
```typescript
|
|
77
|
+
import { NodeLogger, createMorganStream } from 'logan-logger';
|
|
78
|
+
|
|
79
|
+
const logger = new NodeLogger({
|
|
80
|
+
transports: [
|
|
81
|
+
{ type: 'file', options: { filename: 'app.log' } }
|
|
82
|
+
]
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
// Express/Morgan integration
|
|
86
|
+
app.use(morgan('combined', { stream: createMorganStream(logger) }));
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
**Browser with Performance:**
|
|
90
|
+
```typescript
|
|
91
|
+
import { PerformanceLogger } from 'logan-logger';
|
|
92
|
+
|
|
93
|
+
const logger = new PerformanceLogger();
|
|
94
|
+
|
|
95
|
+
logger.mark('api-start');
|
|
96
|
+
// ... API call
|
|
97
|
+
logger.measure('api-duration', 'api-start');
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
#### Safe Data Handling
|
|
101
|
+
```typescript
|
|
102
|
+
import { filterSensitiveData } from 'logan-logger';
|
|
103
|
+
|
|
104
|
+
const userData = {
|
|
105
|
+
name: 'John Doe',
|
|
106
|
+
email: 'john@example.com',
|
|
107
|
+
password: 'secret123', // Will be filtered
|
|
108
|
+
apiKey: 'sk_live_...' // Will be filtered
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
const safeData = filterSensitiveData(userData);
|
|
112
|
+
logger.info('User processed', safeData);
|
|
113
|
+
// Logs: { name: 'John Doe', email: 'john@example.com', password: '[REDACTED]', apiKey: '[REDACTED]' }
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
## Runtime Support
|
|
117
|
+
|
|
118
|
+
| Runtime | Status | Implementation | Features |
|
|
119
|
+
|---------|--------|----------------|----------|
|
|
120
|
+
| Node.js 20+ | â
Full | Winston + Console | File logging, transports, Morgan integration |
|
|
121
|
+
| Bun | â
Full | Node.js adapter | Same as Node.js |
|
|
122
|
+
| Browser | â
Full | Console API | CSS styling, performance marks, grouping |
|
|
123
|
+
| Deno | â
Basic | Console adapter | Console logging (native implementation planned) |
|
|
124
|
+
| WebWorker | â
Basic | Console adapter | Basic console logging |
|
|
125
|
+
| WebAssembly | â
Basic | Console adapter | Message passing to host |
|
|
126
|
+
|
|
127
|
+
## Configuration
|
|
128
|
+
|
|
129
|
+
### Log Levels
|
|
130
|
+
```typescript
|
|
131
|
+
enum LogLevel {
|
|
132
|
+
DEBUG = 0, // Most verbose
|
|
133
|
+
INFO = 1, // General information
|
|
134
|
+
WARN = 2, // Warning messages
|
|
135
|
+
ERROR = 3, // Error messages
|
|
136
|
+
SILENT = 4 // No output
|
|
137
|
+
}
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
### Environment Variables
|
|
141
|
+
```bash
|
|
142
|
+
LOG_LEVEL=debug # debug, info, warn, error, silent
|
|
143
|
+
LOG_FORMAT=json # json, text
|
|
144
|
+
LOG_TIMESTAMP=true # true, false
|
|
145
|
+
LOG_COLOR=false # true, false
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
> **ð See [Environment Variables Documentation](./docs/environment-variables.md) for complete details, examples, and runtime-specific considerations.**
|
|
149
|
+
|
|
150
|
+
### Configuration Options
|
|
151
|
+
```typescript
|
|
152
|
+
interface LoggerConfig {
|
|
153
|
+
level: LogLevel;
|
|
154
|
+
format: 'json' | 'text' | 'custom';
|
|
155
|
+
timestamp: boolean;
|
|
156
|
+
colorize: boolean;
|
|
157
|
+
metadata: Record<string, any>;
|
|
158
|
+
transports?: TransportConfig[];
|
|
159
|
+
}
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
## API Reference
|
|
163
|
+
|
|
164
|
+
### Core Methods
|
|
165
|
+
```typescript
|
|
166
|
+
interface ILogger {
|
|
167
|
+
debug(message: string | (() => string), metadata?: any): void;
|
|
168
|
+
info(message: string | (() => string), metadata?: any): void;
|
|
169
|
+
warn(message: string | (() => string), metadata?: any): void;
|
|
170
|
+
error(message: string | (() => string), metadata?: any): void;
|
|
171
|
+
|
|
172
|
+
setLevel(level: LogLevel): void;
|
|
173
|
+
getLevel(): LogLevel;
|
|
174
|
+
child(metadata: Record<string, any>): ILogger;
|
|
175
|
+
}
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
### Factory Functions
|
|
179
|
+
```typescript
|
|
180
|
+
// Create logger with explicit configuration
|
|
181
|
+
createLogger(config?: Partial<LoggerConfig>): ILogger;
|
|
182
|
+
|
|
183
|
+
// Create logger based on environment
|
|
184
|
+
createLoggerForEnvironment(): ILogger;
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
## Development
|
|
188
|
+
|
|
189
|
+
### Setup
|
|
190
|
+
```bash
|
|
191
|
+
git clone <repository>
|
|
192
|
+
cd logan-logger-ts
|
|
193
|
+
pnpm install
|
|
194
|
+
```
|
|
195
|
+
|
|
196
|
+
### Commands
|
|
197
|
+
```bash
|
|
198
|
+
# Development
|
|
199
|
+
pnpm dev # Run with bun
|
|
200
|
+
pnpm test # Test watch mode
|
|
201
|
+
pnpm test:run # Single test run
|
|
202
|
+
pnpm test:ui # Test UI
|
|
203
|
+
|
|
204
|
+
# Building
|
|
205
|
+
pnpm build # Full build
|
|
206
|
+
pnpm typecheck # Type checking
|
|
207
|
+
pnpm lint # Code linting
|
|
208
|
+
|
|
209
|
+
# Specific tests
|
|
210
|
+
vitest run tests/logger.test.ts
|
|
211
|
+
```
|
|
212
|
+
|
|
213
|
+
## Architecture
|
|
214
|
+
|
|
215
|
+
Logan Logger uses a **Factory + Adapter pattern**:
|
|
216
|
+
|
|
217
|
+
1. **Runtime Detection** - Automatically detects the current JavaScript environment
|
|
218
|
+
2. **Factory Creation** - Creates the appropriate logger implementation
|
|
219
|
+
3. **Runtime Adapters** - Optimized implementations for each environment
|
|
220
|
+
4. **Unified Interface** - Consistent API across all runtimes
|
|
221
|
+
|
|
222
|
+
### File Structure
|
|
223
|
+
```
|
|
224
|
+
src/
|
|
225
|
+
âââ core/ # Core interfaces and factory
|
|
226
|
+
âââ runtime/ # Runtime-specific implementations
|
|
227
|
+
âââ utils/ # Utilities (serialization, config, runtime detection)
|
|
228
|
+
âââ index.ts # Main exports
|
|
229
|
+
```
|
|
230
|
+
|
|
231
|
+
## Contributing
|
|
232
|
+
|
|
233
|
+
1. Fork the repository
|
|
234
|
+
2. Create a feature branch
|
|
235
|
+
3. Add tests for new functionality
|
|
236
|
+
4. Ensure all tests pass: `pnpm test:run`
|
|
237
|
+
5. Submit a pull request
|
|
238
|
+
|
|
239
|
+
## License
|
|
240
|
+
|
|
241
|
+
MIT License - see LICENSE file for details.
|
|
242
|
+
|
|
243
|
+
## Credits
|
|
244
|
+
|
|
245
|
+
Created by Logan Lindquist Land
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"__vite-browser-external-BcPniuRQ.js","sources":["../__vite-browser-external"],"sourcesContent":["export default {}"],"names":["__viteBrowserExternal"],"mappings":"gFAAA,MAAAA,EAAe,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"__vite-browser-external-DYxpcVy9.mjs","sources":["../__vite-browser-external"],"sourcesContent":["export default {}"],"names":["__viteBrowserExternal"],"mappings":"AAAA,MAAAA,IAAe,CAAA;"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,376 @@
|
|
|
1
|
+
export declare abstract class BaseLogger implements ILogger {
|
|
2
|
+
protected level: LogLevel;
|
|
3
|
+
protected config: Partial<LoggerConfig>;
|
|
4
|
+
protected runtime: RuntimeName;
|
|
5
|
+
protected childMetadata: Record<string, any>;
|
|
6
|
+
constructor(config?: Partial<LoggerConfig>);
|
|
7
|
+
debug(message: LogMessage, metadata?: any): void;
|
|
8
|
+
info(message: LogMessage, metadata?: any): void;
|
|
9
|
+
warn(message: LogMessage, metadata?: any): void;
|
|
10
|
+
error(message: LogMessage, metadata?: any): void;
|
|
11
|
+
log(level: LogLevel, message: LogMessage, metadata?: any): void;
|
|
12
|
+
setLevel(level: LogLevel): void;
|
|
13
|
+
getLevel(): LogLevel;
|
|
14
|
+
child(metadata: Record<string, any>): ILogger;
|
|
15
|
+
protected shouldLog(level: LogLevel): boolean;
|
|
16
|
+
protected abstract writeLog(entry: LogEntry): void;
|
|
17
|
+
protected abstract createChild(): BaseLogger;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export declare class BrowserLogger extends BaseLogger {
|
|
21
|
+
constructor(config?: Partial<LoggerConfig>);
|
|
22
|
+
protected writeLog(entry: LogEntry): void;
|
|
23
|
+
protected createChild(): BaseLogger;
|
|
24
|
+
private formatMessage;
|
|
25
|
+
private getConsoleStyle;
|
|
26
|
+
private shouldLogInProduction;
|
|
27
|
+
protected shouldLog(level: LogLevel): boolean;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export declare class ConsoleGroupLogger extends BrowserLogger {
|
|
31
|
+
private groupStack;
|
|
32
|
+
group(label: string): void;
|
|
33
|
+
groupCollapsed(label: string): void;
|
|
34
|
+
groupEnd(): void;
|
|
35
|
+
time(label: string): void;
|
|
36
|
+
timeEnd(label: string): void;
|
|
37
|
+
trace(message: string, metadata?: any): void;
|
|
38
|
+
count(label?: string): void;
|
|
39
|
+
countReset(label?: string): void;
|
|
40
|
+
table(data: any): void;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Convenience function for creating a logger instance.
|
|
45
|
+
* @param config - Optional configuration for the logger
|
|
46
|
+
* @returns A logger instance appropriate for the current runtime
|
|
47
|
+
* @example
|
|
48
|
+
* ```typescript
|
|
49
|
+
* import { createLogger, LogLevel } from 'logan-logger';
|
|
50
|
+
*
|
|
51
|
+
* const logger = createLogger({
|
|
52
|
+
* level: LogLevel.DEBUG,
|
|
53
|
+
* colorize: true
|
|
54
|
+
* });
|
|
55
|
+
*
|
|
56
|
+
* logger.info('Hello world!');
|
|
57
|
+
* ```
|
|
58
|
+
*/
|
|
59
|
+
export declare function createLogger(config?: Partial<LoggerConfig>): ILogger;
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Create a logger with configuration based on the current environment.
|
|
63
|
+
* Automatically detects production/development/test environments and
|
|
64
|
+
* sets appropriate log levels and formatting.
|
|
65
|
+
* @returns A logger instance configured for the current environment
|
|
66
|
+
*/
|
|
67
|
+
export declare function createLoggerForEnvironment(): ILogger;
|
|
68
|
+
|
|
69
|
+
export declare function createMorganStream(logger: NodeLogger): {
|
|
70
|
+
write: (message: string) => void;
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Detects the current JavaScript runtime environment and its capabilities.
|
|
75
|
+
* @returns Information about the detected runtime
|
|
76
|
+
* @example
|
|
77
|
+
* ```typescript
|
|
78
|
+
* const runtime = detectRuntime();
|
|
79
|
+
* console.log(`Running on: ${runtime.name} ${runtime.version}`);
|
|
80
|
+
* ```
|
|
81
|
+
*/
|
|
82
|
+
export declare function detectRuntime(): RuntimeInfo;
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Filter out sensitive data from an object before logging.
|
|
86
|
+
* @param obj - The object to filter
|
|
87
|
+
* @param sensitiveKeys - Array of key names to redact (case-insensitive)
|
|
88
|
+
* @returns A new object with sensitive values replaced with '[REDACTED]'
|
|
89
|
+
* @example
|
|
90
|
+
* ```typescript
|
|
91
|
+
* const data = { username: 'john', password: 'secret123' };
|
|
92
|
+
* const filtered = filterSensitiveData(data);
|
|
93
|
+
* // Result: { username: 'john', password: '[REDACTED]' }
|
|
94
|
+
* ```
|
|
95
|
+
*/
|
|
96
|
+
export declare function filterSensitiveData(obj: any, sensitiveKeys?: string[]): any;
|
|
97
|
+
|
|
98
|
+
export declare function formatLogEntry(entry: LogEntry, format?: 'json' | 'text'): string;
|
|
99
|
+
|
|
100
|
+
export declare function getDefaultConfig(): LoggerConfig;
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Main logger interface providing methods for logging at different levels.
|
|
104
|
+
* This interface is implemented by all logger implementations across different runtimes.
|
|
105
|
+
*/
|
|
106
|
+
export declare interface ILogger {
|
|
107
|
+
/**
|
|
108
|
+
* Log a debug message. Only shown when log level is DEBUG.
|
|
109
|
+
* @param message - The message to log (string or lazy function)
|
|
110
|
+
* @param metadata - Optional structured data to include
|
|
111
|
+
*/
|
|
112
|
+
debug(message: LogMessage, metadata?: any): void;
|
|
113
|
+
/**
|
|
114
|
+
* Log an informational message.
|
|
115
|
+
* @param message - The message to log (string or lazy function)
|
|
116
|
+
* @param metadata - Optional structured data to include
|
|
117
|
+
*/
|
|
118
|
+
info(message: LogMessage, metadata?: any): void;
|
|
119
|
+
/**
|
|
120
|
+
* Log a warning message.
|
|
121
|
+
* @param message - The message to log (string or lazy function)
|
|
122
|
+
* @param metadata - Optional structured data to include
|
|
123
|
+
*/
|
|
124
|
+
warn(message: LogMessage, metadata?: any): void;
|
|
125
|
+
/**
|
|
126
|
+
* Log an error message.
|
|
127
|
+
* @param message - The message to log (string or lazy function)
|
|
128
|
+
* @param metadata - Optional structured data to include
|
|
129
|
+
*/
|
|
130
|
+
error(message: LogMessage, metadata?: any): void;
|
|
131
|
+
/**
|
|
132
|
+
* Log a message at a specific level.
|
|
133
|
+
* @param level - The log level
|
|
134
|
+
* @param message - The message to log (string or lazy function)
|
|
135
|
+
* @param metadata - Optional structured data to include
|
|
136
|
+
*/
|
|
137
|
+
log(level: LogLevel, message: LogMessage, metadata?: any): void;
|
|
138
|
+
/**
|
|
139
|
+
* Set the minimum log level for this logger.
|
|
140
|
+
* @param level - The minimum log level
|
|
141
|
+
*/
|
|
142
|
+
setLevel(level: LogLevel): void;
|
|
143
|
+
/**
|
|
144
|
+
* Get the current minimum log level.
|
|
145
|
+
* @returns The current log level
|
|
146
|
+
*/
|
|
147
|
+
getLevel(): LogLevel;
|
|
148
|
+
/**
|
|
149
|
+
* Create a child logger with additional metadata.
|
|
150
|
+
* @param metadata - Additional metadata to include in all child log messages
|
|
151
|
+
* @returns A new logger instance with the additional metadata
|
|
152
|
+
*/
|
|
153
|
+
child(metadata: Record<string, any>): ILogger;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* Interface for logger adapters that handle the actual log output.
|
|
158
|
+
* This abstraction allows different implementations for different runtimes.
|
|
159
|
+
*/
|
|
160
|
+
export declare interface ILoggerAdapter {
|
|
161
|
+
/**
|
|
162
|
+
* Write a log entry to the output destination.
|
|
163
|
+
* @param entry - The log entry to write
|
|
164
|
+
*/
|
|
165
|
+
log(entry: LogEntry): void;
|
|
166
|
+
/**
|
|
167
|
+
* Set the minimum log level for this adapter.
|
|
168
|
+
* @param level - The minimum log level
|
|
169
|
+
*/
|
|
170
|
+
setLevel(level: LogLevel): void;
|
|
171
|
+
/**
|
|
172
|
+
* Get the current minimum log level.
|
|
173
|
+
* @returns The current log level
|
|
174
|
+
*/
|
|
175
|
+
getLevel(): LogLevel;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
/**
|
|
179
|
+
* Check if the current runtime is a browser.
|
|
180
|
+
* @returns True if running in a browser
|
|
181
|
+
*/
|
|
182
|
+
export declare function isBrowser(): boolean;
|
|
183
|
+
|
|
184
|
+
/**
|
|
185
|
+
* Check if the current runtime is Bun.
|
|
186
|
+
* @returns True if running in Bun
|
|
187
|
+
*/
|
|
188
|
+
export declare function isBun(): boolean;
|
|
189
|
+
|
|
190
|
+
/**
|
|
191
|
+
* Check if the current runtime is Deno.
|
|
192
|
+
* @returns True if running in Deno
|
|
193
|
+
*/
|
|
194
|
+
export declare function isDeno(): boolean;
|
|
195
|
+
|
|
196
|
+
/**
|
|
197
|
+
* Check if the current runtime is Node.js.
|
|
198
|
+
* @returns True if running in Node.js
|
|
199
|
+
*/
|
|
200
|
+
export declare function isNode(): boolean;
|
|
201
|
+
|
|
202
|
+
export declare function loadConfigFromEnvironment(): Partial<LoggerConfig>;
|
|
203
|
+
|
|
204
|
+
export declare function loadConfigFromFile(configPath?: string): Promise<Partial<LoggerConfig>>;
|
|
205
|
+
|
|
206
|
+
export declare const log: {
|
|
207
|
+
debug: (message: string, meta?: any) => void;
|
|
208
|
+
info: (message: string, meta?: any) => void;
|
|
209
|
+
warn: (message: string, meta?: any) => void;
|
|
210
|
+
error: (message: string, meta?: any) => void;
|
|
211
|
+
};
|
|
212
|
+
|
|
213
|
+
/**
|
|
214
|
+
* Internal representation of a log entry.
|
|
215
|
+
*/
|
|
216
|
+
export declare interface LogEntry {
|
|
217
|
+
/** When the log entry was created */
|
|
218
|
+
timestamp: Date;
|
|
219
|
+
/** Log level of this entry */
|
|
220
|
+
level: LogLevel;
|
|
221
|
+
/** The log message */
|
|
222
|
+
message: string;
|
|
223
|
+
/** Additional structured data */
|
|
224
|
+
metadata?: Record<string, any>;
|
|
225
|
+
/** Runtime that generated this log entry */
|
|
226
|
+
runtime: RuntimeName;
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
export declare const logger: ILogger;
|
|
230
|
+
|
|
231
|
+
/**
|
|
232
|
+
* Configuration options for creating a logger instance.
|
|
233
|
+
*/
|
|
234
|
+
export declare interface LoggerConfig {
|
|
235
|
+
/** Minimum log level to output */
|
|
236
|
+
level: LogLevel;
|
|
237
|
+
/** Output format for log messages */
|
|
238
|
+
format: 'json' | 'text' | 'custom';
|
|
239
|
+
/** Whether to include timestamps in log output */
|
|
240
|
+
timestamp: boolean;
|
|
241
|
+
/** Whether to colorize log output (if supported) */
|
|
242
|
+
colorize: boolean;
|
|
243
|
+
/** Default metadata to include with all log messages */
|
|
244
|
+
metadata: Record<string, any>;
|
|
245
|
+
/** Transport configurations for log output */
|
|
246
|
+
transports?: TransportConfig[];
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
/**
|
|
250
|
+
* Factory class for creating logger instances based on the detected runtime.
|
|
251
|
+
*/
|
|
252
|
+
export declare class LoggerFactory {
|
|
253
|
+
/**
|
|
254
|
+
* Create a logger instance appropriate for the current runtime.
|
|
255
|
+
* @param config - Optional configuration for the logger
|
|
256
|
+
* @returns A logger instance
|
|
257
|
+
*/
|
|
258
|
+
static create(config?: Partial<LoggerConfig>): ILogger;
|
|
259
|
+
/**
|
|
260
|
+
* Create a child logger with additional metadata.
|
|
261
|
+
* @param parent - The parent logger instance
|
|
262
|
+
* @param metadata - Additional metadata to include in all child log messages
|
|
263
|
+
* @returns A new logger instance with the additional metadata
|
|
264
|
+
*/
|
|
265
|
+
static createChild(parent: ILogger, metadata: Record<string, any>): ILogger;
|
|
266
|
+
private static mergeConfig;
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
/**
|
|
270
|
+
* Log levels in ascending order of severity.
|
|
271
|
+
* Used to filter which messages should be logged.
|
|
272
|
+
*/
|
|
273
|
+
export declare enum LogLevel {
|
|
274
|
+
/** Debug messages - most verbose */
|
|
275
|
+
DEBUG = 0,
|
|
276
|
+
/** Informational messages */
|
|
277
|
+
INFO = 1,
|
|
278
|
+
/** Warning messages */
|
|
279
|
+
WARN = 2,
|
|
280
|
+
/** Error messages */
|
|
281
|
+
ERROR = 3,
|
|
282
|
+
/** No messages - silent mode */
|
|
283
|
+
SILENT = 4
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
/**
|
|
287
|
+
* String representation of log levels.
|
|
288
|
+
*/
|
|
289
|
+
export declare type LogLevelString = 'debug' | 'info' | 'warn' | 'error' | 'silent';
|
|
290
|
+
|
|
291
|
+
export declare function logLevelToString(level: LogLevel): string;
|
|
292
|
+
|
|
293
|
+
/**
|
|
294
|
+
* A log message can be a string or a function that returns a string.
|
|
295
|
+
* Functions enable lazy evaluation for expensive log message generation.
|
|
296
|
+
*/
|
|
297
|
+
export declare type LogMessage = string | (() => string);
|
|
298
|
+
|
|
299
|
+
export declare function mergeConfigs(...configs: Partial<LoggerConfig>[]): LoggerConfig;
|
|
300
|
+
|
|
301
|
+
export declare class NodeLogger extends BaseLogger {
|
|
302
|
+
private winston?;
|
|
303
|
+
constructor(config?: Partial<LoggerConfig>);
|
|
304
|
+
private initializeWinston;
|
|
305
|
+
private createWinstonLogger;
|
|
306
|
+
protected writeLog(entry: LogEntry): void;
|
|
307
|
+
protected createChild(): BaseLogger;
|
|
308
|
+
private writeToConsole;
|
|
309
|
+
private getWinstonLevel;
|
|
310
|
+
setLevel(level: LogLevel): void;
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
export declare class PerformanceLogger extends BrowserLogger {
|
|
314
|
+
mark(name: string): void;
|
|
315
|
+
measure(name: string, startMark?: string, endMark?: string): void;
|
|
316
|
+
clearMarks(name?: string): void;
|
|
317
|
+
clearMeasures(name?: string): void;
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
/**
|
|
321
|
+
* Capabilities that a runtime may or may not support.
|
|
322
|
+
*/
|
|
323
|
+
export declare interface RuntimeCapabilities {
|
|
324
|
+
/** Whether the runtime supports file system operations */
|
|
325
|
+
fileSystem: boolean;
|
|
326
|
+
/** Whether the runtime supports colored console output */
|
|
327
|
+
colorSupport: boolean;
|
|
328
|
+
/** Whether the runtime provides process information */
|
|
329
|
+
processInfo: boolean;
|
|
330
|
+
/** Whether the runtime supports streams */
|
|
331
|
+
streams: boolean;
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
/**
|
|
335
|
+
* Information about the detected JavaScript runtime environment.
|
|
336
|
+
*/
|
|
337
|
+
export declare interface RuntimeInfo {
|
|
338
|
+
/** The name of the runtime */
|
|
339
|
+
name: RuntimeName;
|
|
340
|
+
/** Version string of the runtime (if available) */
|
|
341
|
+
version?: string;
|
|
342
|
+
/** Capabilities supported by this runtime */
|
|
343
|
+
capabilities: RuntimeCapabilities;
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
/**
|
|
347
|
+
* Supported JavaScript runtime environments.
|
|
348
|
+
*/
|
|
349
|
+
export declare type RuntimeName = 'node' | 'deno' | 'bun' | 'browser' | 'webworker' | 'unknown';
|
|
350
|
+
|
|
351
|
+
/**
|
|
352
|
+
* Safely stringify an object to JSON, handling circular references,
|
|
353
|
+
* Error objects, functions, and other non-serializable values.
|
|
354
|
+
* @param obj - The object to stringify
|
|
355
|
+
* @param space - Number of spaces for pretty-printing (optional)
|
|
356
|
+
* @returns JSON string representation
|
|
357
|
+
*/
|
|
358
|
+
export declare function safeStringify(obj: any, space?: number): string;
|
|
359
|
+
|
|
360
|
+
export declare function serializeError(error: any): any;
|
|
361
|
+
|
|
362
|
+
export declare function stringToLogLevel(level: string): LogLevel;
|
|
363
|
+
|
|
364
|
+
/**
|
|
365
|
+
* Configuration for a specific log transport (output destination).
|
|
366
|
+
*/
|
|
367
|
+
export declare interface TransportConfig {
|
|
368
|
+
/** Type of transport */
|
|
369
|
+
type: 'console' | 'file' | 'http' | 'custom';
|
|
370
|
+
/** Minimum log level for this transport */
|
|
371
|
+
level?: LogLevel;
|
|
372
|
+
/** Transport-specific options */
|
|
373
|
+
options: Record<string, any>;
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
export { }
|