createDrain()
Create a Drain instance for incremental or streaming log processing
Create a Drain instance for incremental or streaming log processing. Use this for advanced scenarios where you need fine-grained control over the compression pipeline.
Signature
Parameters
options
- Type:
DrainOptions - Required: No
Configuration options for the Drain algorithm.
options.depth
- Type:
number - Default:
4
Parse tree depth. Higher values create more specific templates.
options.simThreshold
- Type:
number - Default:
0.4 - Range:
0.0to1.0
Similarity threshold for template matching.
options.maxChildren
- Type:
number - Default:
100
Maximum children per parse tree node.
options.maxClusters
- Type:
number - Default:
1000
Maximum total templates allowed.
options.maxSamples
- Type:
number - Default:
3
Maximum sample variables per template.
options.preprocessing
- Type:
ParsingStrategy - Default: Built-in strategy
Custom preprocessing strategy.
options.onProgress
- Type:
ProgressCallback - Default:
undefined
Progress callback for monitoring long-running operations.
Return Value
Returns a Drain instance with the following methods:
process(line: string): void
Process a single log line and add it to the appropriate cluster.
addLogLines(lines: string[]): void
Process multiple log lines at once.
getClusters(): LogCluster[]
Get all discovered clusters (templates).
getResult(format?: OutputFormat): CompressionResult
Get compression results in the specified format.
Examples
Incremental Processing
Streaming Processing
Batch Processing with Progress
Custom Preprocessing
Accessing Clusters Directly
Real-time Monitoring
When to Use
Use createDrain() when:
- Processing very large log files that don't fit in memory
- Implementing streaming log analysis
- Building real-time log monitoring systems
- You need to process logs incrementally
- You want direct access to internal clusters
Use compress() or compressText() when:
- Processing complete log files that fit in memory
- You want a simple, one-step compression
- You don't need incremental updates
See Also
- compress() - Simple compression API
- compressText() - Text compression
- Custom Preprocessing - Define custom strategies
- Types Reference - TypeScript interfaces