yinzerflow 0.3.1 → 0.4.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 +1 -1
- package/docs/configuration/advanced-configuration-options.md +1 -1
- package/docs/configuration/configuration-patterns.md +1 -1
- package/docs/core/logging.md +130 -0
- package/docs/security/security-overview.md +2 -2
- package/docs/start-here.md +2 -2
- package/index.d.ts +52 -26
- package/index.js +18 -18
- package/index.js.map +15 -14
- package/package.json +1 -1
- package/docs/security/logging.md +0 -348
package/README.md
CHANGED
|
@@ -41,7 +41,7 @@ await app.listen();
|
|
|
41
41
|
- **[Getting Started](docs/start-here.md)** - Complete guide and examples
|
|
42
42
|
- **[Routes](docs/routes.md)** - Routing system and handlers
|
|
43
43
|
- **[Request/Response](docs/request.md)** - Request and response objects
|
|
44
|
-
- **[Logging](docs/logging.md)** - Logging configuration and customization
|
|
44
|
+
- **[Logging](docs/core/logging.md)** - Logging configuration and customization
|
|
45
45
|
- **[Advanced Configuration](docs/advanced-configuration-options.md)** - Detailed configuration options
|
|
46
46
|
|
|
47
47
|
## 🛡️ Security
|
|
@@ -210,7 +210,7 @@ await app.listen();
|
|
|
210
210
|
|
|
211
211
|
### Logging Configuration
|
|
212
212
|
|
|
213
|
-
Control framework logging output with built-in Pittsburgh personality or custom logging libraries. See [Logging Documentation](
|
|
213
|
+
Control framework logging output with built-in Pittsburgh personality or custom logging libraries. See [Logging Documentation](../core/logging.md) for detailed setup, custom logger integration, and advanced use cases.
|
|
214
214
|
|
|
215
215
|
```typescript
|
|
216
216
|
const app = new YinzerFlow({
|
|
@@ -443,7 +443,7 @@ For detailed configuration options, see:
|
|
|
443
443
|
- **[Body Parsing Security](../security/body-parsing.md)** - Body parser configuration
|
|
444
444
|
- **[CORS Security](../security/cors.md)** - CORS configuration
|
|
445
445
|
- **[IP Security](../security/ip-security.md)** - IP security configuration
|
|
446
|
-
- **[Logging Security](../
|
|
446
|
+
- **[Logging Security](../core/logging.md)** - Logging configuration
|
|
447
447
|
|
|
448
448
|
## Common Issues and Solutions
|
|
449
449
|
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
# Logging
|
|
2
|
+
|
|
3
|
+
YinzerFlow provides a flexible logging system with built-in Pittsburgh personality and performance tracking.
|
|
4
|
+
|
|
5
|
+
## Configuration
|
|
6
|
+
|
|
7
|
+
```typescript
|
|
8
|
+
import { YinzerFlow, createLogger } from 'yinzerflow';
|
|
9
|
+
|
|
10
|
+
const logger = createLogger({
|
|
11
|
+
prefix: 'MYAPP',
|
|
12
|
+
logLevel: 'info'
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
const server = new YinzerFlow({
|
|
16
|
+
port: 3000,
|
|
17
|
+
logger,
|
|
18
|
+
networkLogs: true
|
|
19
|
+
});
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
### Configuration Options
|
|
23
|
+
|
|
24
|
+
| Option | Type | Default | Description |
|
|
25
|
+
|--------|------|---------|-------------|
|
|
26
|
+
| `logLevel` | `'off' \| 'error' \| 'warn' \| 'info'` | `'info'` | Minimum log level to output |
|
|
27
|
+
| `prefix` | `string` | `'YINZER'` | Prefix for log messages |
|
|
28
|
+
| `logger` | `Logger` | `undefined` | Custom logger implementation (Winston, Pino, etc.) |
|
|
29
|
+
| `networkLogs` | `boolean` | `false` | Enable nginx-style network request logging |
|
|
30
|
+
| `networkLogger` | `Logger` | `undefined` | Custom logger for network logs (can be same as `logger` or different) |
|
|
31
|
+
|
|
32
|
+
## Examples
|
|
33
|
+
|
|
34
|
+
### Basic Example
|
|
35
|
+
|
|
36
|
+
```typescript
|
|
37
|
+
import { log } from 'yinzerflow';
|
|
38
|
+
|
|
39
|
+
// Use the shared logger (default YINZER prefix)
|
|
40
|
+
log.info('Application started');
|
|
41
|
+
log.warn('Deprecated feature used');
|
|
42
|
+
log.error('Operation failed');
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
### Custom Logger
|
|
46
|
+
|
|
47
|
+
```typescript
|
|
48
|
+
import { createLogger } from 'yinzerflow';
|
|
49
|
+
|
|
50
|
+
const dbLogger = createLogger({
|
|
51
|
+
prefix: 'DATABASE',
|
|
52
|
+
logLevel: 'error'
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
dbLogger.error('Connection failed');
|
|
56
|
+
// Output: [DATABASE] ❌ [timestamp] [ERROR] Connection failed - aw jeez
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
### Unified Network and App Logging
|
|
60
|
+
|
|
61
|
+
```typescript
|
|
62
|
+
import { YinzerFlow, createLogger } from 'yinzerflow';
|
|
63
|
+
|
|
64
|
+
const logger = createLogger({ prefix: 'APP', logLevel: 'info' });
|
|
65
|
+
|
|
66
|
+
const server = new YinzerFlow({
|
|
67
|
+
port: 3000,
|
|
68
|
+
logger,
|
|
69
|
+
networkLogs: true,
|
|
70
|
+
networkLogger: logger // Route network logs to same logger
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
// Both app and network logs go to the same custom logger
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
## Common Use Cases
|
|
77
|
+
|
|
78
|
+
- **Debug Development Issues**: Use default logger with `networkLogs: true` for comprehensive debugging
|
|
79
|
+
- **Track Application Errors**: Use `logLevel: 'error'` to capture only critical errors
|
|
80
|
+
- **Monitor Component Health**: Create isolated loggers per subsystem with custom prefixes
|
|
81
|
+
- **Integrate External Logging**: Use custom logger implementation for Winston, Pino, etc.
|
|
82
|
+
- **Silent Operation**: Set `logLevel: 'off'` for environments with external log management
|
|
83
|
+
- **Script and Utility Logging**: Use shared `log` instance in standalone scripts and database seeds
|
|
84
|
+
|
|
85
|
+
## Methods
|
|
86
|
+
|
|
87
|
+
### `createLogger(options?): Logger`
|
|
88
|
+
|
|
89
|
+
Creates a logger instance with isolated state.
|
|
90
|
+
|
|
91
|
+
**Parameters:**
|
|
92
|
+
- `logLevel?: 'off' | 'error' | 'warn' | 'info'` - Minimum log level (default: 'info')
|
|
93
|
+
- `prefix?: string` - Log message prefix (default: 'YINZER')
|
|
94
|
+
- `logger?: Logger` - Custom logger implementation
|
|
95
|
+
|
|
96
|
+
**Returns:** Logger with `info`, `warn`, `error`, and `levels` methods.
|
|
97
|
+
|
|
98
|
+
### Logger Methods
|
|
99
|
+
|
|
100
|
+
- `info(...args): void` - Log info-level messages
|
|
101
|
+
- `warn(...args): void` - Log warning messages
|
|
102
|
+
- `error(...args): void` - Log error messages
|
|
103
|
+
- `levels` - Access to log level constants
|
|
104
|
+
|
|
105
|
+
## Properties
|
|
106
|
+
|
|
107
|
+
### Log Levels
|
|
108
|
+
|
|
109
|
+
- `off` (0): No logging
|
|
110
|
+
- `error` (1): Only errors
|
|
111
|
+
- `warn` (2): Warnings and errors
|
|
112
|
+
- `info` (3): All messages (most verbose)
|
|
113
|
+
|
|
114
|
+
## Security Considerations
|
|
115
|
+
|
|
116
|
+
YinzerFlow implements several security measures for safe logging:
|
|
117
|
+
|
|
118
|
+
### 🛡️ Safe Data Handling
|
|
119
|
+
- **Problem**: Logging sensitive data can expose secrets in log files
|
|
120
|
+
- **YinzerFlow Solution**: Uses native `console.log` formatting to prevent accidental serialization of sensitive objects
|
|
121
|
+
|
|
122
|
+
### 🛡️ Log Level Protection
|
|
123
|
+
- **Problem**: Verbose logging in production can impact performance and expose internal details
|
|
124
|
+
- **YinzerFlow Solution**: Configurable log levels with early returns to minimize overhead when logging is disabled
|
|
125
|
+
|
|
126
|
+
### 🛡️ Logger Isolation
|
|
127
|
+
- **Problem**: Custom loggers could interfere with framework logging
|
|
128
|
+
- **YinzerFlow Solution**: Clean interface boundaries and isolated logger instances prevent conflicts
|
|
129
|
+
|
|
130
|
+
These security measures ensure YinzerFlow's logging implementation follows security best practices and prevents common attack vectors while maintaining spec compliance.
|
|
@@ -124,7 +124,7 @@ app.onError(({ response }, error) => {
|
|
|
124
124
|
### 🛡️ Logging Security
|
|
125
125
|
**Protection**: Log injection, sensitive data exposure
|
|
126
126
|
**Implementation**: Structured logging, sensitive data filtering
|
|
127
|
-
**Documentation**: [Logging Security](
|
|
127
|
+
**Documentation**: [Logging Security](../core/logging.md)
|
|
128
128
|
|
|
129
129
|
```typescript
|
|
130
130
|
const secureApp = new YinzerFlow({
|
|
@@ -272,7 +272,7 @@ For detailed security documentation:
|
|
|
272
272
|
- **[Body Parsing](./body-parsing.md)** - File upload and JSON parsing security
|
|
273
273
|
- **[CORS](./cors.md)** - Cross-origin request security
|
|
274
274
|
- **[IP Security](./ip-security.md)** - Client IP validation and protection
|
|
275
|
-
- **[Logging](
|
|
275
|
+
- **[Logging](../core/logging.md)** - Secure logging practices
|
|
276
276
|
- **[Error Handling](../core/error-handling.md)** - Secure error handling patterns
|
|
277
277
|
|
|
278
278
|
For security issues or questions:
|
package/docs/start-here.md
CHANGED
|
@@ -120,7 +120,7 @@ For custom shutdown handling, see [Advanced Configuration](./advanced-configurat
|
|
|
120
120
|
- **[Body Parsing](./security/body-parsing.md)** - Secure parsing of JSON, file uploads, and form data with DoS protection
|
|
121
121
|
- **[CORS](./security/cors.md)** - Cross-Origin Resource Sharing with comprehensive security measures
|
|
122
122
|
- **[IP Security](./security/ip-security.md)** - Client IP validation and spoofing protection for load balancers and CDNs
|
|
123
|
-
- **[Logging](./
|
|
123
|
+
- **[Logging](./core/logging.md)** - Flexible logging with custom logger support and Pittsburgh personality
|
|
124
124
|
- **[Configuration Patterns](./configuration/configuration-patterns.md)** - Common configuration patterns and best practices
|
|
125
125
|
- **[Advanced Configuration](./configuration/advanced-configuration-options.md)** - Fine-tune security, performance, and functionality
|
|
126
126
|
|
|
@@ -164,7 +164,7 @@ For custom shutdown handling, see [Advanced Configuration](./advanced-configurat
|
|
|
164
164
|
1. **Start with Routes**: Learn the routing system in [routes.md](./routes.md)
|
|
165
165
|
2. **Understand Requests**: Explore request handling in [request.md](./request.md)
|
|
166
166
|
3. **Configure Security**: Set up IP security and CORS in [ip-security.md](./ip-security.md) and [cors.md](./cors.md)
|
|
167
|
-
4. **Customize Logging**: Implement custom loggers in [logging.md](./logging.md)
|
|
167
|
+
4. **Customize Logging**: Implement custom loggers in [logging.md](./core/logging.md)
|
|
168
168
|
5. **Advanced Configuration**: Fine-tune settings in [advanced-configuration-options.md](./advanced-configuration-options.md)
|
|
169
169
|
|
|
170
170
|
## Examples
|
package/index.d.ts
CHANGED
|
@@ -1559,12 +1559,31 @@ declare const logLevels: {
|
|
|
1559
1559
|
readonly warn: "warn";
|
|
1560
1560
|
readonly info: "info";
|
|
1561
1561
|
};
|
|
1562
|
+
/**
|
|
1563
|
+
* YinzerFlow Logging Levels
|
|
1564
|
+
*
|
|
1565
|
+
* String-based logging levels for intuitive configuration:
|
|
1566
|
+
* - 'off': No logging at all. Mainly used for network logging internally, but feel free to use it for other purposes.
|
|
1567
|
+
* - 'error': Only errors
|
|
1568
|
+
* - 'warn': Warnings and errors (includes security warnings, slow requests)
|
|
1569
|
+
* - 'info': Info, warnings, and errors (standard application logging)
|
|
1570
|
+
*
|
|
1571
|
+
* Network logging is controlled separately via boolean networkLogging config.
|
|
1572
|
+
*/
|
|
1573
|
+
export type LogLevel = CreateEnum<typeof logLevels>;
|
|
1562
1574
|
export interface Logger {
|
|
1563
1575
|
info: (...args: Array<unknown>) => void;
|
|
1564
1576
|
warn: (...args: Array<unknown>) => void;
|
|
1565
1577
|
error: (...args: Array<unknown>) => void;
|
|
1566
|
-
|
|
1567
|
-
|
|
1578
|
+
}
|
|
1579
|
+
export interface LoggerConfig {
|
|
1580
|
+
logLevel?: LogLevel | undefined;
|
|
1581
|
+
prefix?: string | undefined;
|
|
1582
|
+
logger?: {
|
|
1583
|
+
info: (...args: Array<unknown>) => void;
|
|
1584
|
+
warn: (...args: Array<unknown>) => void;
|
|
1585
|
+
error: (...args: Array<unknown>) => void;
|
|
1586
|
+
} | undefined;
|
|
1568
1587
|
}
|
|
1569
1588
|
/**
|
|
1570
1589
|
* Internal CORS Configuration Options
|
|
@@ -1870,19 +1889,16 @@ export interface InternalServerConfiguration {
|
|
|
1870
1889
|
*/
|
|
1871
1890
|
host: string;
|
|
1872
1891
|
/**
|
|
1873
|
-
*
|
|
1874
|
-
*
|
|
1875
|
-
*
|
|
1876
|
-
* -
|
|
1877
|
-
*
|
|
1878
|
-
* @
|
|
1879
|
-
|
|
1880
|
-
|
|
1881
|
-
|
|
1882
|
-
*
|
|
1883
|
-
* If provided, this logger will be used instead of the built-in YinzerFlow logger
|
|
1884
|
-
* Must implement the Logger interface
|
|
1885
|
-
* @default undefined (uses built-in logger)
|
|
1892
|
+
* Custom logger instance
|
|
1893
|
+
*
|
|
1894
|
+
* Use createLogger() to create logger instances with custom configuration
|
|
1895
|
+
* @default undefined (uses built-in logger with default settings)
|
|
1896
|
+
*
|
|
1897
|
+
* @example
|
|
1898
|
+
* ```typescript
|
|
1899
|
+
* const logger = createLogger({ prefix: 'APP', logLevel: 'info' });
|
|
1900
|
+
* new YinzerFlow({ logger });
|
|
1901
|
+
* ```
|
|
1886
1902
|
*/
|
|
1887
1903
|
logger?: Logger;
|
|
1888
1904
|
/**
|
|
@@ -1923,10 +1939,16 @@ export interface InternalServerConfiguration {
|
|
|
1923
1939
|
autoGracefulShutdown: boolean;
|
|
1924
1940
|
}
|
|
1925
1941
|
export type HttpMethodHandlers = Record<Lowercase<keyof typeof httpMethod>, InternalSetupMethod>;
|
|
1926
|
-
export type RouteGroupMethod = (prefix: string, callback: (group:
|
|
1942
|
+
export type RouteGroupMethod = (prefix: string, callback: (group: RouteGroup) => void, options?: InternalRouteRegistryOptions) => RouteGroup;
|
|
1927
1943
|
export interface InternalGroupApp extends HttpMethodHandlers {
|
|
1928
1944
|
readonly group: RouteGroupMethod;
|
|
1929
1945
|
}
|
|
1946
|
+
/**
|
|
1947
|
+
* Route group instance that provides HTTP method handlers and nested group support.
|
|
1948
|
+
*
|
|
1949
|
+
* @see {@link InternalGroupApp} for internal implementation details
|
|
1950
|
+
*/
|
|
1951
|
+
export type RouteGroup = InternalGroupApp;
|
|
1930
1952
|
/**
|
|
1931
1953
|
* Main setup interface for configuring YinzerFlow routes, hooks, and middleware.
|
|
1932
1954
|
*
|
|
@@ -2300,7 +2322,7 @@ declare class SetupImpl implements InternalSetupImpl {
|
|
|
2300
2322
|
patch(path: string, handler: HandlerCallback<any>, options?: InternalRouteRegistryOptions): void;
|
|
2301
2323
|
delete(path: string, handler: HandlerCallback<any>, options?: InternalRouteRegistryOptions): void;
|
|
2302
2324
|
options(path: string, handler: HandlerCallback<any>, options?: InternalRouteRegistryOptions): void;
|
|
2303
|
-
group(prefix: string, callback: (group:
|
|
2325
|
+
group(prefix: string, callback: (group: RouteGroup) => void, options?: InternalRouteRegistryOptions): RouteGroup;
|
|
2304
2326
|
beforeAll(handlers: Array<HandlerCallback<any>>, options?: InternalGlobalHookOptions): void;
|
|
2305
2327
|
afterAll(handlers: Array<HandlerCallback<any>>, options?: InternalGlobalHookOptions): void;
|
|
2306
2328
|
onError(handler: HandlerCallback<any>): void;
|
|
@@ -2322,19 +2344,23 @@ export declare class YinzerFlow extends SetupImpl {
|
|
|
2322
2344
|
};
|
|
2323
2345
|
private _setupGracefulShutdown;
|
|
2324
2346
|
}
|
|
2347
|
+
declare const LOG_LEVELS: {
|
|
2348
|
+
readonly off: 0;
|
|
2349
|
+
readonly error: 1;
|
|
2350
|
+
readonly warn: 2;
|
|
2351
|
+
readonly info: 3;
|
|
2352
|
+
};
|
|
2353
|
+
export declare const createLogger: (initialConfig?: LoggerConfig) => {
|
|
2354
|
+
info: (...args: Array<unknown>) => void;
|
|
2355
|
+
warn: (...args: Array<unknown>) => void;
|
|
2356
|
+
error: (...args: Array<unknown>) => void;
|
|
2357
|
+
levels: typeof LOG_LEVELS;
|
|
2358
|
+
};
|
|
2325
2359
|
export declare const log: {
|
|
2326
|
-
setLogLevel: (level: "error" | "info" | "off" | "warn") => void;
|
|
2327
|
-
setCustomLogger: (logger: Logger) => void;
|
|
2328
2360
|
info: (...args: Array<unknown>) => void;
|
|
2329
2361
|
warn: (...args: Array<unknown>) => void;
|
|
2330
2362
|
error: (...args: Array<unknown>) => void;
|
|
2331
|
-
|
|
2332
|
-
levels: {
|
|
2333
|
-
readonly off: 0;
|
|
2334
|
-
readonly error: 1;
|
|
2335
|
-
readonly warn: 2;
|
|
2336
|
-
readonly info: 3;
|
|
2337
|
-
};
|
|
2363
|
+
levels: typeof LOG_LEVELS;
|
|
2338
2364
|
};
|
|
2339
2365
|
|
|
2340
2366
|
export {};
|