Types Reference
Complete TypeScript type definitions for logpare
Complete TypeScript type definitions for logpare.
Core Types
CompressionResult
Result object returned by compress() and compressText().
interface CompressionResult {
templates: Template[];
stats: CompressionStats;
formatted: string;
}Fields:
templates- Array of discovered templates, sorted by occurrence count (descending)stats- Compression statisticsformatted- String representation in the requested format
Template
Represents a discovered log template with metadata.
interface Template {
id: string;
pattern: string;
occurrences: number;
sampleVariables: string[][];
firstSeen: number;
lastSeen: number;
severity: Severity;
urlSamples: string[];
fullUrlSamples: string[];
statusCodeSamples: number[];
correlationIdSamples: string[];
durationSamples: string[];
isStackFrame: boolean;
}Fields:
id- Unique template identifierpattern- Template pattern with<*>wildcards for variablesoccurrences- Number of log lines matching this templatesampleVariables- Sample values captured from variables (limited bymaxSamples)firstSeen- Line number where template was first seenlastSeen- Line number where template was last seenseverity- Severity level:'error','warning', or'info'urlSamples- Extracted hostnames from URLsfullUrlSamples- Complete URLs found in matching logsstatusCodeSamples- HTTP status codes (e.g.,[200, 404, 500])correlationIdSamples- Trace/request IDs for distributed tracingdurationSamples- Timing values (e.g.,["45ms", "1.5s"])isStackFrame- Whether this template represents a stack frame
CompressionStats
Statistics about the compression operation.
interface CompressionStats {
inputLines: number;
uniqueTemplates: number;
compressionRatio: number;
estimatedTokenReduction: number;
processingTimeMs?: number;
}Fields:
inputLines- Number of input log lines processeduniqueTemplates- Number of unique templates discoveredcompressionRatio- Ratio of templates to input lines (0.0 to 1.0)estimatedTokenReduction- Estimated token savings as percentage (0-100)processingTimeMs- Time taken to process (milliseconds)
Options Types
CompressOptions
Options for compress() and compressText().
interface CompressOptions extends DrainOptions {
format?: OutputFormat;
maxTemplates?: number;
}Fields:
format- Output format:'summary','detailed', or'json'(default:'summary')maxTemplates- Maximum templates in formatted output (default:50)- Plus all fields from
DrainOptions
DrainOptions
Configuration for the Drain algorithm.
interface DrainOptions {
depth?: number;
simThreshold?: number;
maxChildren?: number;
maxClusters?: number;
maxSamples?: number;
preprocessing?: ParsingStrategy;
onProgress?: ProgressCallback;
}Fields:
depth- Parse tree depth (default:4)simThreshold- Similarity threshold 0-1 (default:0.4)maxChildren- Max children per tree node (default:100)maxClusters- Max total templates (default:1000)maxSamples- Sample variables per template (default:3)preprocessing- Custom preprocessing strategyonProgress- Progress reporting callback
Preprocessing Types
ParsingStrategy
Strategy for preprocessing and tokenizing log lines.
interface ParsingStrategy {
preprocess(line: string): string;
tokenize(line: string): string[];
getSimThreshold(depth: number): number;
}Methods:
preprocess(line)- Preprocess a log line (mask variables, normalize, etc.)tokenize(line)- Split preprocessed line into tokensgetSimThreshold(depth)- Get similarity threshold for a given tree depth
Example:
import { defineStrategy, DEFAULT_PATTERNS, WILDCARD } from 'logpare';
const customStrategy: ParsingStrategy = defineStrategy({
preprocess(line: string): string {
let result = line;
for (const [, pattern] of Object.entries(DEFAULT_PATTERNS)) {
result = result.replace(pattern, WILDCARD);
}
return result;
},
tokenize(line: string): string[] {
return line.split(/\s+/).filter(Boolean);
},
getSimThreshold(depth: number): number {
return depth <= 2 ? 0.3 : 0.4;
}
});Progress Types
ProgressCallback
Callback function for progress updates.
type ProgressCallback = (event: ProgressEvent) => void;ProgressEvent
Progress event data.
interface ProgressEvent {
processedLines: number;
totalLines?: number;
currentPhase: ProcessingPhase;
percentComplete?: number;
}Fields:
processedLines- Number of lines processed so fartotalLines- Total lines to process (if known)currentPhase- Current processing phasepercentComplete- Completion percentage 0-100 (only iftotalLinesknown)
ProcessingPhase
Current phase of the compression operation.
type ProcessingPhase = 'parsing' | 'clustering' | 'finalizing';Enum Types
Severity
Log severity level.
type Severity = 'error' | 'warning' | 'info';Automatically detected from log content:
'error'- ERROR, FATAL, Exception, Failed, TypeError, etc.'warning'- WARN, Warning, Deprecated, [Violation]'info'- Default for other logs
OutputFormat
Output format for compression results.
type OutputFormat = 'summary' | 'detailed' | 'json';'summary'- Compact template list with frequencies'detailed'- Full templates with all metadata'json'- Machine-readable JSON
Constants
WILDCARD
The wildcard placeholder used in templates.
const WILDCARD: '<*>';Example:
import { WILDCARD } from 'logpare';
const pattern = `ERROR Connection to ${WILDCARD} failed`;DEFAULT_PATTERNS
Built-in regex patterns for common log variables.
const DEFAULT_PATTERNS: {
ipv4: RegExp;
ipv6: RegExp;
uuid: RegExp;
timestamp: RegExp;
hexId: RegExp;
filepath: RegExp;
url: RegExp;
number: RegExp;
// ... more patterns
};Example:
import { DEFAULT_PATTERNS } from 'logpare';
// Use in custom preprocessing
const masked = line.replace(DEFAULT_PATTERNS.ipv4, '<*>');SEVERITY_PATTERNS
Regex patterns for severity detection.
const SEVERITY_PATTERNS: {
error: RegExp;
warning: RegExp;
};STACK_FRAME_PATTERNS
Regex patterns for stack frame detection.
const STACK_FRAME_PATTERNS: {
v8: RegExp;
firefox: RegExp;
chrome: RegExp;
};Utility Functions
detectSeverity()
Detect severity level from a log line.
function detectSeverity(line: string): Severity;Example:
import { detectSeverity } from 'logpare';
detectSeverity('ERROR Connection failed'); // 'error'
detectSeverity('WARN Deprecated API'); // 'warning'
detectSeverity('INFO Request completed'); // 'info'isStackFrame()
Check if a line is a stack frame.
function isStackFrame(line: string): boolean;Example:
import { isStackFrame } from 'logpare';
isStackFrame(' at Function.name (file.js:123:45)'); // true
isStackFrame('ERROR Connection failed'); // falseextractUrls()
Extract URLs/hostnames from a log line.
function extractUrls(line: string): string[];Example:
import { extractUrls } from 'logpare';
extractUrls('GET https://api.example.com/users');
// ['api.example.com']
extractUrls('Fetched http://cdn.example.com/image.png');
// ['cdn.example.com']defineStrategy()
Create a custom preprocessing strategy.
function defineStrategy(
overrides: Partial<ParsingStrategy>
): ParsingStrategy;Example:
import { defineStrategy } from 'logpare';
const strategy = defineStrategy({
tokenize: (line) => line.split(','),
getSimThreshold: (depth) => 0.5,
});