yinzerflow 0.6.14 → 0.7.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/CHANGELOG.md +17 -0
- package/docs/configuration/configuration.md +34 -65
- package/docs/core/logging.md +654 -347
- package/index.d.ts +205 -73
- package/index.js +21 -21
- package/index.js.map +23 -22
- package/package.json +25 -28
package/index.d.ts
CHANGED
|
@@ -984,24 +984,26 @@ interface Response$1 {
|
|
|
984
984
|
}
|
|
985
985
|
/**
|
|
986
986
|
Time duration string format
|
|
987
|
-
|
|
988
|
-
Format: number followed by unit (s, m, h, d)
|
|
989
|
-
|
|
987
|
+
|
|
988
|
+
Format: number followed by unit (ms, s, m, h, d)
|
|
989
|
+
|
|
990
990
|
Units:
|
|
991
|
+
- ms: milliseconds
|
|
991
992
|
- s: seconds
|
|
992
993
|
- m: minutes
|
|
993
994
|
- h: hours
|
|
994
995
|
- d: days
|
|
995
|
-
|
|
996
|
+
|
|
996
997
|
@example
|
|
997
998
|
```typescript
|
|
998
|
-
'
|
|
999
|
-
'
|
|
1000
|
-
'
|
|
1001
|
-
'
|
|
999
|
+
'500ms' // 500 milliseconds
|
|
1000
|
+
'30s' // 30 seconds
|
|
1001
|
+
'15m' // 15 minutes
|
|
1002
|
+
'2h' // 2 hours
|
|
1003
|
+
'1d' // 1 day
|
|
1002
1004
|
```
|
|
1003
1005
|
*/
|
|
1004
|
-
export type TimeString = `${number}${"d" | "h" | "m" | "s"}`;
|
|
1006
|
+
export type TimeString = `${number}${"d" | "h" | "m" | "ms" | "s"}`;
|
|
1005
1007
|
export interface InternalCookieOptions {
|
|
1006
1008
|
/**
|
|
1007
1009
|
* Expiration date/time for the cookie
|
|
@@ -1479,6 +1481,11 @@ export interface InternalHookRegistryImpl {
|
|
|
1479
1481
|
_addAfterHooks: (handlers: Array<HandlerCallback>, options?: InternalGlobalHookOptions) => void;
|
|
1480
1482
|
_addOnError: (handler: HandlerCallback) => void;
|
|
1481
1483
|
_addOnNotFound: (handler: HandlerCallback) => void;
|
|
1484
|
+
setLogger: (logger: {
|
|
1485
|
+
info: (...args: Array<unknown>) => void;
|
|
1486
|
+
warn: (...args: Array<unknown>) => void;
|
|
1487
|
+
error: (...args: Array<unknown>) => void;
|
|
1488
|
+
}) => void;
|
|
1482
1489
|
}
|
|
1483
1490
|
/**
|
|
1484
1491
|
* Internal route registry implementation for managing route storage and lookup.
|
|
@@ -1887,33 +1894,52 @@ export declare const logLevels: {
|
|
|
1887
1894
|
readonly error: "error";
|
|
1888
1895
|
readonly warn: "warn";
|
|
1889
1896
|
readonly info: "info";
|
|
1897
|
+
readonly debug: "debug";
|
|
1890
1898
|
};
|
|
1891
1899
|
/**
|
|
1892
1900
|
* YinzerFlow Logging Levels
|
|
1893
1901
|
*
|
|
1894
1902
|
* String-based logging levels for intuitive configuration:
|
|
1895
|
-
* - 'off': No logging at all
|
|
1903
|
+
* - 'off': No logging at all
|
|
1896
1904
|
* - 'error': Only errors
|
|
1897
|
-
* - 'warn': Warnings and errors (includes security warnings
|
|
1905
|
+
* - 'warn': Warnings and errors (includes security warnings)
|
|
1898
1906
|
* - 'info': Info, warnings, and errors (standard application logging)
|
|
1907
|
+
* - 'debug': All messages including verbose connection details
|
|
1899
1908
|
*
|
|
1900
|
-
*
|
|
1909
|
+
* Access logging is controlled separately via `logging.requests` config.
|
|
1901
1910
|
*/
|
|
1902
1911
|
export type LogLevel = CreateEnum<typeof logLevels>;
|
|
1903
1912
|
export interface Logger {
|
|
1904
1913
|
info: (...args: Array<unknown>) => void;
|
|
1905
1914
|
warn: (...args: Array<unknown>) => void;
|
|
1906
1915
|
error: (...args: Array<unknown>) => void;
|
|
1916
|
+
debug?: ((...args: Array<unknown>) => void) | undefined;
|
|
1907
1917
|
}
|
|
1908
1918
|
export interface LoggerConfig {
|
|
1909
|
-
|
|
1919
|
+
level?: LogLevel | undefined;
|
|
1910
1920
|
prefix?: string | undefined;
|
|
1911
|
-
|
|
1912
|
-
info: (...args: Array<unknown>) => void;
|
|
1913
|
-
warn: (...args: Array<unknown>) => void;
|
|
1914
|
-
error: (...args: Array<unknown>) => void;
|
|
1915
|
-
} | undefined;
|
|
1921
|
+
logLevel?: LogLevel | undefined;
|
|
1916
1922
|
}
|
|
1923
|
+
/**
|
|
1924
|
+
* Byte size string format
|
|
1925
|
+
*
|
|
1926
|
+
* Format: number followed by unit (b, kb, mb, gb)
|
|
1927
|
+
*
|
|
1928
|
+
* Units:
|
|
1929
|
+
* - b: bytes
|
|
1930
|
+
* - kb: kilobytes (1024 bytes)
|
|
1931
|
+
* - mb: megabytes (1048576 bytes)
|
|
1932
|
+
* - gb: gigabytes (1073741824 bytes)
|
|
1933
|
+
*
|
|
1934
|
+
* @example
|
|
1935
|
+
* ```typescript
|
|
1936
|
+
* '512b' // 512 bytes
|
|
1937
|
+
* '256kb' // 256 kilobytes
|
|
1938
|
+
* '1mb' // 1 megabyte
|
|
1939
|
+
* '2gb' // 2 gigabytes
|
|
1940
|
+
* ```
|
|
1941
|
+
*/
|
|
1942
|
+
export type ByteString = `${number}${"b" | "gb" | "kb" | "mb"}`;
|
|
1917
1943
|
export declare const rateLimitAlgorithm: {
|
|
1918
1944
|
readonly slidingWindowCounter: "sliding-window-counter";
|
|
1919
1945
|
};
|
|
@@ -2380,32 +2406,14 @@ export interface InternalServerOptions {
|
|
|
2380
2406
|
*/
|
|
2381
2407
|
host: string;
|
|
2382
2408
|
/**
|
|
2383
|
-
*
|
|
2409
|
+
* Logging configuration — controls app logger, access logs, and diagnostics.
|
|
2384
2410
|
*
|
|
2385
|
-
*
|
|
2386
|
-
*
|
|
2387
|
-
*
|
|
2388
|
-
*
|
|
2389
|
-
* ```typescript
|
|
2390
|
-
* const logger = createLogger({ prefix: 'APP', logLevel: 'info' });
|
|
2391
|
-
* new YinzerFlow({ logger });
|
|
2392
|
-
* ```
|
|
2393
|
-
*/
|
|
2394
|
-
logger?: Logger;
|
|
2395
|
-
/**
|
|
2396
|
-
* Network request/response logging (nginx-style logs)
|
|
2397
|
-
* Completely separate from application logs - simple on/off toggle
|
|
2398
|
-
* @default false
|
|
2399
|
-
*/
|
|
2400
|
-
networkLogs: boolean;
|
|
2401
|
-
/**
|
|
2402
|
-
* Custom logger for network logs (optional)
|
|
2403
|
-
* If provided, network logs will be routed to this logger instead of built-in formatting
|
|
2404
|
-
* Can be the same as the application logger or a different one
|
|
2405
|
-
* Useful for unified monitoring (e.g., Winston with Datadog transport for both app and network logs)
|
|
2406
|
-
* @default undefined (uses built-in network logging)
|
|
2411
|
+
* Three independent channels:
|
|
2412
|
+
* - **App logger**: Developer logs + framework errors/warnings (gated by `level`)
|
|
2413
|
+
* - **Access log**: nginx-style request/response lines (gated by `requests` on/off)
|
|
2414
|
+
* - **Diagnostics**: Framework health monitoring (gated by individual thresholds)
|
|
2407
2415
|
*/
|
|
2408
|
-
|
|
2416
|
+
logging: InternalLoggingOptions;
|
|
2409
2417
|
/**
|
|
2410
2418
|
* Cross-Origin Resource Sharing configuration
|
|
2411
2419
|
*/
|
|
@@ -2442,6 +2450,92 @@ export interface InternalServerOptions {
|
|
|
2442
2450
|
*/
|
|
2443
2451
|
gracefulShutdownTimeout: TimeString | number;
|
|
2444
2452
|
}
|
|
2453
|
+
/**
|
|
2454
|
+
* Internal Logging Configuration
|
|
2455
|
+
* Controls three independent channels: app logger, access logs, and diagnostics.
|
|
2456
|
+
*/
|
|
2457
|
+
export interface InternalLoggingOptions {
|
|
2458
|
+
/**
|
|
2459
|
+
* Log level threshold — messages at this severity and above are output.
|
|
2460
|
+
* From least to most severe: debug → info → warn → error.
|
|
2461
|
+
* @default 'warn'
|
|
2462
|
+
*/
|
|
2463
|
+
level: LogLevel;
|
|
2464
|
+
/**
|
|
2465
|
+
* Log line prefix shown in brackets, e.g. [YINZER]
|
|
2466
|
+
* @default 'YINZER'
|
|
2467
|
+
*/
|
|
2468
|
+
prefix: string;
|
|
2469
|
+
/**
|
|
2470
|
+
* Enable Pittsburgh personality phrases in log output
|
|
2471
|
+
* @default true
|
|
2472
|
+
*/
|
|
2473
|
+
personality: boolean;
|
|
2474
|
+
/**
|
|
2475
|
+
* Enable nginx-style access logs (one line per request/response)
|
|
2476
|
+
* @default false
|
|
2477
|
+
*/
|
|
2478
|
+
requests: boolean;
|
|
2479
|
+
/**
|
|
2480
|
+
* Custom logger for application logs (optional)
|
|
2481
|
+
* If provided, app logs route to this logger instead of built-in formatting
|
|
2482
|
+
* @default undefined
|
|
2483
|
+
*/
|
|
2484
|
+
logger?: Logger;
|
|
2485
|
+
/**
|
|
2486
|
+
* Custom logger for access logs (optional)
|
|
2487
|
+
* If provided, access logs route to this logger instead of built-in formatting
|
|
2488
|
+
* @default undefined
|
|
2489
|
+
*/
|
|
2490
|
+
accessLogger?: Logger;
|
|
2491
|
+
/**
|
|
2492
|
+
* Framework diagnostics — health monitoring independent of app log level.
|
|
2493
|
+
* All thresholds default to false (disabled). Set a threshold to enable.
|
|
2494
|
+
*/
|
|
2495
|
+
diagnostics: InternalDiagnosticsOptions;
|
|
2496
|
+
}
|
|
2497
|
+
/**
|
|
2498
|
+
* Internal Diagnostics Configuration
|
|
2499
|
+
* Framework health monitoring that fires independently of the app log level.
|
|
2500
|
+
* Even with `level: 'off'`, diagnostics still fire when thresholds are exceeded.
|
|
2501
|
+
*/
|
|
2502
|
+
export interface InternalDiagnosticsOptions {
|
|
2503
|
+
/**
|
|
2504
|
+
* Log requests slower than this threshold
|
|
2505
|
+
* @default false (disabled)
|
|
2506
|
+
* @example '500ms' or 500 (milliseconds)
|
|
2507
|
+
*/
|
|
2508
|
+
slowRequests: TimeString | number | false;
|
|
2509
|
+
/**
|
|
2510
|
+
* Log responses larger than this threshold
|
|
2511
|
+
* @default false (disabled)
|
|
2512
|
+
* @example '1mb' or 1048576 (bytes)
|
|
2513
|
+
*/
|
|
2514
|
+
largeResponses: ByteString | number | false;
|
|
2515
|
+
/**
|
|
2516
|
+
* Log requests with bodies larger than this threshold
|
|
2517
|
+
* @default false (disabled)
|
|
2518
|
+
* @example '1mb' or 1048576 (bytes)
|
|
2519
|
+
*/
|
|
2520
|
+
largeRequests: ByteString | number | false;
|
|
2521
|
+
/**
|
|
2522
|
+
* Log periodic memory/heap usage at this interval
|
|
2523
|
+
* @default false (disabled)
|
|
2524
|
+
* @example '30s' or 30000 (milliseconds)
|
|
2525
|
+
*/
|
|
2526
|
+
memory: TimeString | number | false;
|
|
2527
|
+
/**
|
|
2528
|
+
* Log event loop lag exceeding this threshold
|
|
2529
|
+
* @default false (disabled)
|
|
2530
|
+
* @example '100ms' or 100 (milliseconds)
|
|
2531
|
+
*/
|
|
2532
|
+
eventLoop: TimeString | number | false;
|
|
2533
|
+
/**
|
|
2534
|
+
* Log rate limit hits
|
|
2535
|
+
* @default false (disabled)
|
|
2536
|
+
*/
|
|
2537
|
+
rateLimits: boolean;
|
|
2538
|
+
}
|
|
2445
2539
|
export type HttpMethodHandlers = Record<Lowercase<keyof typeof httpMethod>, InternalSetupMethod>;
|
|
2446
2540
|
export type RouteGroupMethod = (prefix: string, callback: (group: RouteGroup) => void, options?: InternalRouteRegistryOptions) => RouteGroup;
|
|
2447
2541
|
export interface InternalGroupApp extends HttpMethodHandlers {
|
|
@@ -2778,6 +2872,14 @@ export interface InternalSetupImpl extends Setup {
|
|
|
2778
2872
|
readonly _configuration: InternalServerOptions;
|
|
2779
2873
|
readonly _routeRegistry: InternalRouteRegistryImpl;
|
|
2780
2874
|
readonly _hooks: InternalHookRegistryImpl;
|
|
2875
|
+
/** Per-instance logger. Set by `_configureLogging()` in YinzerFlow. */
|
|
2876
|
+
_log: {
|
|
2877
|
+
info: (...args: Array<unknown>) => void;
|
|
2878
|
+
warn: (...args: Array<unknown>) => void;
|
|
2879
|
+
error: (...args: Array<unknown>) => void;
|
|
2880
|
+
debug: (...args: Array<unknown>) => void;
|
|
2881
|
+
table: (data: unknown, ...additionalArgs: Array<unknown>) => void;
|
|
2882
|
+
};
|
|
2781
2883
|
}
|
|
2782
2884
|
declare class HookRegistryImpl implements InternalHookRegistryImpl {
|
|
2783
2885
|
readonly _beforeRouting: Set<{
|
|
@@ -2794,6 +2896,12 @@ declare class HookRegistryImpl implements InternalHookRegistryImpl {
|
|
|
2794
2896
|
}>;
|
|
2795
2897
|
_onError: HandlerCallback;
|
|
2796
2898
|
_onNotFound: HandlerCallback;
|
|
2899
|
+
private _logger;
|
|
2900
|
+
setLogger(logger: {
|
|
2901
|
+
info: (...args: Array<unknown>) => void;
|
|
2902
|
+
warn: (...args: Array<unknown>) => void;
|
|
2903
|
+
error: (...args: Array<unknown>) => void;
|
|
2904
|
+
}): void;
|
|
2797
2905
|
constructor();
|
|
2798
2906
|
_addBeforeRoutingHooks(handlers: Array<HandlerCallback>, options?: InternalGlobalHookOptions): void;
|
|
2799
2907
|
_addBeforeHooks(handlers: Array<HandlerCallback>, options?: InternalGlobalHookOptions): void;
|
|
@@ -2827,29 +2935,30 @@ declare class HookRegistryImpl implements InternalHookRegistryImpl {
|
|
|
2827
2935
|
* // Basic configuration with logging
|
|
2828
2936
|
* const app = new YinzerFlow({
|
|
2829
2937
|
* port: 8080,
|
|
2830
|
-
*
|
|
2831
|
-
* networkLogs: true
|
|
2938
|
+
* logging: { level: 'info', requests: true }
|
|
2832
2939
|
* });
|
|
2833
2940
|
*
|
|
2834
2941
|
* // Full configuration example
|
|
2835
2942
|
* const app = new YinzerFlow({
|
|
2836
2943
|
* port: 3000,
|
|
2837
2944
|
* host: '0.0.0.0',
|
|
2838
|
-
*
|
|
2839
|
-
*
|
|
2840
|
-
*
|
|
2945
|
+
* logging: {
|
|
2946
|
+
* level: 'debug',
|
|
2947
|
+
* personality: true,
|
|
2948
|
+
* requests: true,
|
|
2949
|
+
* logger: {
|
|
2950
|
+
* info: (message, ...args) => console.log(`[APP] ${message}`, ...args),
|
|
2951
|
+
* warn: (message, ...args) => console.warn(`[APP] ${message}`, ...args),
|
|
2952
|
+
* error: (message, ...args) => console.error(`[APP] ${message}`, ...args),
|
|
2953
|
+
* debug: (message, ...args) => console.debug(`[APP] ${message}`, ...args)
|
|
2954
|
+
* }
|
|
2955
|
+
* },
|
|
2841
2956
|
* cors: {
|
|
2842
2957
|
* enabled: true,
|
|
2843
2958
|
* origin: ['https://example.com', 'https://app.example.com'],
|
|
2844
2959
|
* methods: ['GET', 'POST', 'PUT', 'DELETE'],
|
|
2845
2960
|
* headers: ['Content-Type', 'Authorization'],
|
|
2846
2961
|
* credentials: true
|
|
2847
|
-
* },
|
|
2848
|
-
* logger: {
|
|
2849
|
-
* info: (message, ...args) => console.log(`[APP] ${message}`, ...args),
|
|
2850
|
-
* warn: (message, ...args) => console.warn(`[APP] ${message}`, ...args),
|
|
2851
|
-
* error: (message, ...args) => console.error(`[APP] ${message}`, ...args),
|
|
2852
|
-
* debug: (message, ...args) => console.debug(`[APP] ${message}`, ...args)
|
|
2853
2962
|
* }
|
|
2854
2963
|
* });
|
|
2855
2964
|
* ```
|
|
@@ -2949,10 +3058,48 @@ declare class RouteRegistryImpl implements InternalRouteRegistryImpl {
|
|
|
2949
3058
|
private _storeParameterizedRoute;
|
|
2950
3059
|
private _findParameterizedRoute;
|
|
2951
3060
|
}
|
|
3061
|
+
declare const loggerBrand: unique symbol;
|
|
3062
|
+
declare const LOG_LEVELS: {
|
|
3063
|
+
readonly off: 0;
|
|
3064
|
+
readonly error: 1;
|
|
3065
|
+
readonly warn: 2;
|
|
3066
|
+
readonly info: 3;
|
|
3067
|
+
readonly debug: 4;
|
|
3068
|
+
};
|
|
3069
|
+
export declare const createLogger: (initialConfig?: LoggerConfig & {
|
|
3070
|
+
personality?: boolean;
|
|
3071
|
+
logger?: Logger | null | undefined;
|
|
3072
|
+
}) => {
|
|
3073
|
+
info: (...args: Array<unknown>) => void;
|
|
3074
|
+
warn: (...args: Array<unknown>) => void;
|
|
3075
|
+
error: (...args: Array<unknown>) => void;
|
|
3076
|
+
debug: (...args: Array<unknown>) => void;
|
|
3077
|
+
table: (data: unknown, ...additionalArgs: Array<unknown>) => void;
|
|
3078
|
+
levels: typeof LOG_LEVELS;
|
|
3079
|
+
[loggerBrand]: {
|
|
3080
|
+
level: string;
|
|
3081
|
+
prefix: string;
|
|
3082
|
+
personality: boolean;
|
|
3083
|
+
};
|
|
3084
|
+
};
|
|
3085
|
+
declare const log: {
|
|
3086
|
+
info: (...args: Array<unknown>) => void;
|
|
3087
|
+
warn: (...args: Array<unknown>) => void;
|
|
3088
|
+
error: (...args: Array<unknown>) => void;
|
|
3089
|
+
debug: (...args: Array<unknown>) => void;
|
|
3090
|
+
table: (data: unknown, ...additionalArgs: Array<unknown>) => void;
|
|
3091
|
+
levels: typeof LOG_LEVELS;
|
|
3092
|
+
[loggerBrand]: {
|
|
3093
|
+
level: string;
|
|
3094
|
+
prefix: string;
|
|
3095
|
+
personality: boolean;
|
|
3096
|
+
};
|
|
3097
|
+
};
|
|
2952
3098
|
declare class SetupImpl implements InternalSetupImpl {
|
|
2953
3099
|
readonly _configuration: InternalServerOptions;
|
|
2954
3100
|
readonly _routeRegistry: RouteRegistryImpl;
|
|
2955
3101
|
readonly _hooks: HookRegistryImpl;
|
|
3102
|
+
_log: typeof log;
|
|
2956
3103
|
constructor(customConfiguration?: ServerOptions);
|
|
2957
3104
|
get(path: string, handler: HandlerCallback<any>, options?: InternalRouteRegistryOptions): void;
|
|
2958
3105
|
head(path: string, handler: HandlerCallback<any>, options?: InternalRouteRegistryOptions): void;
|
|
@@ -2972,8 +3119,13 @@ export declare class YinzerFlow extends SetupImpl {
|
|
|
2972
3119
|
private _isListening;
|
|
2973
3120
|
private _server?;
|
|
2974
3121
|
private _globalRateLimiter?;
|
|
3122
|
+
private _diagnostics?;
|
|
2975
3123
|
private readonly _maxBufferSize;
|
|
3124
|
+
private _accessLog?;
|
|
3125
|
+
private _accessLogEnabled;
|
|
2976
3126
|
constructor(configuration?: ServerOptions);
|
|
3127
|
+
get log(): typeof YinzerFlow._log;
|
|
3128
|
+
private _configureLogging;
|
|
2977
3129
|
private _setupServer;
|
|
2978
3130
|
private _processRequest;
|
|
2979
3131
|
private _handleRequestError;
|
|
@@ -2991,26 +3143,6 @@ export declare class YinzerFlow extends SetupImpl {
|
|
|
2991
3143
|
};
|
|
2992
3144
|
private _setupGracefulShutdown;
|
|
2993
3145
|
}
|
|
2994
|
-
declare const LOG_LEVELS: {
|
|
2995
|
-
readonly off: 0;
|
|
2996
|
-
readonly error: 1;
|
|
2997
|
-
readonly warn: 2;
|
|
2998
|
-
readonly info: 3;
|
|
2999
|
-
};
|
|
3000
|
-
export declare const createLogger: (initialConfig?: LoggerConfig) => {
|
|
3001
|
-
info: (...args: Array<unknown>) => void;
|
|
3002
|
-
warn: (...args: Array<unknown>) => void;
|
|
3003
|
-
error: (...args: Array<unknown>) => void;
|
|
3004
|
-
table: (data: unknown, ...additionalArgs: Array<unknown>) => void;
|
|
3005
|
-
levels: typeof LOG_LEVELS;
|
|
3006
|
-
};
|
|
3007
|
-
export declare const log: {
|
|
3008
|
-
info: (...args: Array<unknown>) => void;
|
|
3009
|
-
warn: (...args: Array<unknown>) => void;
|
|
3010
|
-
error: (...args: Array<unknown>) => void;
|
|
3011
|
-
table: (data: unknown, ...additionalArgs: Array<unknown>) => void;
|
|
3012
|
-
levels: typeof LOG_LEVELS;
|
|
3013
|
-
};
|
|
3014
3146
|
export declare const corsHook: (config: InternalCorsEnabledOptions) => HandlerCallback;
|
|
3015
3147
|
export declare const rateLimitHook: <T extends HandlerCallbackGenerics>(rateLimitOptions: RateLimitOptions) => HandlerCallback<T>;
|
|
3016
3148
|
export declare const colors: {
|