start the path to rust
This commit is contained in:
117
dist_ts/mail/delivery/smtpserver/utils/adaptive-logging.d.ts
vendored
Normal file
117
dist_ts/mail/delivery/smtpserver/utils/adaptive-logging.d.ts
vendored
Normal file
@@ -0,0 +1,117 @@
|
||||
/**
|
||||
* Adaptive SMTP Logging System
|
||||
* Automatically switches between logging modes based on server load (active connections)
|
||||
* to maintain performance during high-concurrency scenarios
|
||||
*/
|
||||
import * as plugins from '../../../../plugins.js';
|
||||
import { SecurityLogLevel, SecurityEventType } from '../constants.js';
|
||||
import type { ISmtpSession } from '../interfaces.js';
|
||||
import type { LogLevel, ISmtpLogOptions } from './logging.js';
|
||||
/**
|
||||
* Log modes based on server load
|
||||
*/
|
||||
export declare enum LogMode {
|
||||
VERBOSE = "VERBOSE",// < 20 connections: Full detailed logging
|
||||
REDUCED = "REDUCED",// 20-40 connections: Limited command/response logging, full error logging
|
||||
MINIMAL = "MINIMAL"
|
||||
}
|
||||
/**
|
||||
* Configuration for adaptive logging thresholds
|
||||
*/
|
||||
export interface IAdaptiveLogConfig {
|
||||
verboseThreshold: number;
|
||||
reducedThreshold: number;
|
||||
aggregationInterval: number;
|
||||
maxAggregatedEntries: number;
|
||||
}
|
||||
/**
|
||||
* Connection metadata for aggregation tracking
|
||||
*/
|
||||
interface IConnectionTracker {
|
||||
activeConnections: number;
|
||||
peakConnections: number;
|
||||
totalConnections: number;
|
||||
connectionsPerSecond: number;
|
||||
lastConnectionTime: number;
|
||||
}
|
||||
/**
|
||||
* Adaptive SMTP Logger that scales logging based on server load
|
||||
*/
|
||||
export declare class AdaptiveSmtpLogger {
|
||||
private static instance;
|
||||
private currentMode;
|
||||
private config;
|
||||
private aggregatedEntries;
|
||||
private aggregationTimer;
|
||||
private connectionTracker;
|
||||
private constructor();
|
||||
/**
|
||||
* Get singleton instance
|
||||
*/
|
||||
static getInstance(config?: Partial<IAdaptiveLogConfig>): AdaptiveSmtpLogger;
|
||||
/**
|
||||
* Update active connection count and adjust log mode if needed
|
||||
*/
|
||||
updateConnectionCount(activeConnections: number): void;
|
||||
/**
|
||||
* Track new connection for rate calculation
|
||||
*/
|
||||
trackConnection(): void;
|
||||
/**
|
||||
* Get current logging mode
|
||||
*/
|
||||
getCurrentMode(): LogMode;
|
||||
/**
|
||||
* Get connection statistics
|
||||
*/
|
||||
getConnectionStats(): IConnectionTracker;
|
||||
/**
|
||||
* Log a message with adaptive behavior
|
||||
*/
|
||||
log(level: LogLevel, message: string, options?: ISmtpLogOptions): void;
|
||||
/**
|
||||
* Log command with adaptive behavior
|
||||
*/
|
||||
logCommand(command: string, socket: plugins.net.Socket | plugins.tls.TLSSocket, session?: ISmtpSession): void;
|
||||
/**
|
||||
* Log response with adaptive behavior
|
||||
*/
|
||||
logResponse(response: string, socket: plugins.net.Socket | plugins.tls.TLSSocket): void;
|
||||
/**
|
||||
* Log connection event with adaptive behavior
|
||||
*/
|
||||
logConnection(socket: plugins.net.Socket | plugins.tls.TLSSocket, eventType: 'connect' | 'close' | 'error', session?: ISmtpSession, error?: Error): void;
|
||||
/**
|
||||
* Log security event (always logged regardless of mode)
|
||||
*/
|
||||
logSecurityEvent(level: SecurityLogLevel, type: SecurityEventType, message: string, details: Record<string, any>, ipAddress?: string, domain?: string, success?: boolean): void;
|
||||
/**
|
||||
* Determine appropriate log mode based on connection count
|
||||
*/
|
||||
private determineLogMode;
|
||||
/**
|
||||
* Switch to a new log mode
|
||||
*/
|
||||
private switchLogMode;
|
||||
/**
|
||||
* Add entry to aggregation buffer
|
||||
*/
|
||||
private aggregateEntry;
|
||||
/**
|
||||
* Start the aggregation timer
|
||||
*/
|
||||
private startAggregationTimer;
|
||||
/**
|
||||
* Flush aggregated entries to logs
|
||||
*/
|
||||
private flushAggregatedEntries;
|
||||
/**
|
||||
* Cleanup resources
|
||||
*/
|
||||
destroy(): void;
|
||||
}
|
||||
/**
|
||||
* Default instance for easy access
|
||||
*/
|
||||
export declare const adaptiveLogger: AdaptiveSmtpLogger;
|
||||
export {};
|
||||
Reference in New Issue
Block a user