Advanced configuration options for Fluent Logger including security authentication, TLS encryption, event transmission modes, and performance optimization settings.
Configure shared key authentication for secure communication with Fluentd.
interface SecurityOptions {
clientHostname?: string; // Client hostname for authentication
sharedKey?: string; // Shared key for authentication
username?: string; // Username for authentication
password?: string; // Password for authentication
}Usage Examples:
const logger = require('fluent-logger');
// Shared key authentication
const sender = logger.createFluentSender('secure', {
host: 'secure-fluentd.example.com',
port: 24224,
security: {
clientHostname: 'web-server-01.example.com',
sharedKey: 'very-secret-shared-key-12345'
}
});
// Username/password authentication
const authSender = logger.createFluentSender('auth', {
host: 'auth-fluentd.example.com',
port: 24224,
security: {
clientHostname: 'api-server.example.com',
sharedKey: 'shared-secret',
username: 'log-client',
password: 'client-password-123'
}
});Enable TLS encryption for secure data transmission.
interface TLSConfiguration {
tls?: boolean; // Enable TLS encryption
tlsOptions?: { // TLS connection options
ca?: Buffer | string; // Certificate Authority
cert?: Buffer | string; // Client certificate
key?: Buffer | string; // Client private key
passphrase?: string; // Private key passphrase
rejectUnauthorized?: boolean; // Verify server certificate
[key: string]: any; // Additional TLS options
};
}Usage Examples:
const fs = require('fs');
const logger = require('fluent-logger');
// Basic TLS
const tlsSender = logger.createFluentSender('secure', {
host: 'secure-logs.example.com',
port: 24224,
tls: true,
tlsOptions: {
ca: fs.readFileSync('/path/to/ca-cert.pem'),
rejectUnauthorized: true
}
});
// Mutual TLS authentication
const mutualTlsSender = logger.createFluentSender('mutual-tls', {
host: 'mtls-logs.example.com',
port: 24224,
tls: true,
tlsOptions: {
ca: fs.readFileSync('/path/to/ca-cert.pem'),
cert: fs.readFileSync('/path/to/client-cert.pem'),
key: fs.readFileSync('/path/to/client-key.pem'),
passphrase: 'client-key-password'
},
security: {
clientHostname: 'api-client.example.com',
sharedKey: 'mutual-tls-shared-key'
}
});Configure different event transmission protocols for performance optimization.
type EventMode = 'Message' | 'PackedForward' | 'CompressedPackedForward';
interface EventModeOptions {
eventMode?: EventMode; // Event transmission mode (default: 'Message')
flushInterval?: number; // Flush interval in ms for PackedForward modes (default: 100)
messageQueueSizeLimit?: number; // Queue size limit for Message mode (default: 0, unlimited)
sendQueueSizeLimit?: number; // Queue size limit in bytes (default: 8MB)
}Usage Examples:
// Message mode (default) - individual message transmission
const messageSender = logger.createFluentSender('app', {
host: 'localhost',
port: 24224,
eventMode: 'Message',
messageQueueSizeLimit: 1000 // Limit queue size
});
// PackedForward mode - batched transmission for high throughput
const packedSender = logger.createFluentSender('metrics', {
host: 'metrics-server.example.com',
port: 24224,
eventMode: 'PackedForward',
flushInterval: 50, // Flush every 50ms
sendQueueSizeLimit: 16 * 1024 * 1024 // 16MB queue limit
});
// CompressedPackedForward mode - compressed batches for network efficiency
const compressedSender = logger.createFluentSender('logs', {
host: 'log-aggregator.example.com',
port: 24224,
eventMode: 'CompressedPackedForward',
flushInterval: 200, // Flush every 200ms for better compression
sendQueueSizeLimit: 32 * 1024 * 1024 // 32MB queue limit
});Advanced connection settings for reliability and performance.
interface ConnectionOptions {
timeout?: number; // Socket timeout in seconds (default: 3.0)
enableReconnect?: boolean; // Enable automatic reconnection (default: true)
reconnectInterval?: number; // Reconnect interval in ms (default: 600000)
requireAckResponse?: boolean; // Wait for acknowledgment (default: false)
ackResponseTimeout?: number; // Ack timeout in ms (default: 190000)
}Usage Examples:
// High-reliability configuration
const reliableSender = logger.createFluentSender('critical', {
host: 'ha-fluentd.example.com',
port: 24224,
timeout: 10.0, // 10 second timeout
enableReconnect: true,
reconnectInterval: 30000, // Reconnect every 30 seconds
requireAckResponse: true, // Wait for acknowledgment
ackResponseTimeout: 60000 // 60 second ack timeout
});
// Fast, fire-and-forget configuration
const fastSender = logger.createFluentSender('analytics', {
host: 'analytics-fluentd.example.com',
port: 24224,
timeout: 1.0, // 1 second timeout
enableReconnect: false, // No automatic reconnection
requireAckResponse: false // No acknowledgment required
});Use Unix domain sockets instead of TCP for local communication.
interface UnixSocketOptions {
path?: string; // Unix domain socket path (overrides host/port)
}Usage Examples:
// Unix domain socket configuration
const unixSender = logger.createFluentSender('local', {
path: '/var/run/fluentd/fluentd.sock',
timeout: 5.0
});
// TLS over Unix domain socket
const tlsUnixSender = logger.createFluentSender('secure-local', {
path: '/var/run/fluentd/secure.sock',
tls: true,
tlsOptions: {
ca: fs.readFileSync('/etc/ssl/fluentd-ca.pem')
}
});Configure timestamp precision for event timing.
interface TimestampOptions {
milliseconds?: boolean; // Use millisecond precision (default: false, uses seconds)
}Usage Examples:
// High-precision timestamps
const precisionSender = logger.createFluentSender('precise', {
host: 'localhost',
port: 24224,
milliseconds: true // Use millisecond precision
});
// Standard precision (default)
const standardSender = logger.createFluentSender('standard', {
host: 'localhost',
port: 24224,
milliseconds: false // Use second precision
});Configure internal logging for debugging and monitoring.
interface LoggingOptions {
internalLogger?: { // Internal logger object (default: console)
info(message: string, ...args: any[]): void;
error(message: string, ...args: any[]): void;
};
}Usage Examples:
// Custom internal logger
const customLogger = {
info: (message, ...args) => {
console.log(`[FLUENT-INFO] ${message}`, ...args);
},
error: (message, ...args) => {
console.error(`[FLUENT-ERROR] ${message}`, ...args);
}
};
const monitoredSender = logger.createFluentSender('monitored', {
host: 'localhost',
port: 24224,
internalLogger: customLogger,
enableReconnect: true
});
// Disable internal logging
const silentSender = logger.createFluentSender('silent', {
host: 'localhost',
port: 24224,
internalLogger: {
info: () => {},
error: () => {}
}
});const fs = require('fs');
const logger = require('fluent-logger');
// Production-ready configuration with all advanced options
const productionSender = logger.createFluentSender('production', {
// Connection settings
host: 'production-fluentd.example.com',
port: 24224,
timeout: 5.0,
// Reliability settings
enableReconnect: true,
reconnectInterval: 120000, // 2 minutes
requireAckResponse: true,
ackResponseTimeout: 30000, // 30 seconds
// Performance settings
eventMode: 'CompressedPackedForward',
flushInterval: 100,
sendQueueSizeLimit: 16 * 1024 * 1024, // 16MB
milliseconds: true,
// Security settings
tls: true,
tlsOptions: {
ca: fs.readFileSync('/etc/ssl/fluentd-ca.pem'),
cert: fs.readFileSync('/etc/ssl/client-cert.pem'),
key: fs.readFileSync('/etc/ssl/client-key.pem'),
passphrase: process.env.CLIENT_KEY_PASSPHRASE
},
security: {
clientHostname: 'web-app-01.production.example.com',
sharedKey: process.env.FLUENTD_SHARED_KEY,
username: 'production-client',
password: process.env.FLUENTD_PASSWORD
},
// Monitoring
internalLogger: {
info: (msg, ...args) => console.log(`[FLUENT] ${msg}`, ...args),
error: (msg, ...args) => console.error(`[FLUENT-ERROR] ${msg}`, ...args)
}
});