gala-log-parser
March 1, 2026 · View on GitHub
Go libraries, functional pipelines, zero boilerplate.
GALA calls Go standard library packages directly — strings, strconv, fmt — while wrapping the results in functional pipelines. Parse structured logs, aggregate stats, and pattern-match findings, all without leaving the type system.
// Aggregate endpoint stats with FoldLeft + HashMap
val statsMap = entries.FoldLeft(EmptyHashMap[string, EndpointStats](), (acc, entry) => {
val path = entry.Path
val existing = acc.GetOrElse(path, EndpointStats(path, 0, 0, 0))
val errs = if (isError(entry.Lvl)) 1 else 0
val updated = existing.Copy(
Count = existing.Count + 1,
TotalMs = existing.TotalMs + entry.DurationMs,
Errors = existing.Errors + errs,
)
return acc.Put(path, updated)
})
No map[string]*T nil checks. No if _, ok := m[k]; !ok { ... }. Just a fold.
What This Showcases
| Go Package | How It's Used | GALA Feature |
|---|---|---|
strings | strings.Fields(), strings.SplitN() for tokenizing logfmt | Direct Go stdlib calls |
strconv | strconv.Atoi() for parsing durations and status codes | Go multi-return handling |
fmt | fmt.Sprintf() / fmt.Printf() for formatted output | Same API, less ceremony |
| GALA Feature | Where Used |
|---|---|
| Sealed types | Level (5 variants), Finding (3 variants with typed data) |
| Pattern matching | parseLevel, formatFinding, error filtering |
| Expression functions | levelName, isError, severityWeight — one-line definitions |
| Immutable structs | LogEntry, EndpointStats with .Copy() for updates |
Option[T] | parseLine returns Option[LogEntry] instead of (T, bool) |
HashMap | Field parsing, endpoint grouping via FoldLeft |
Array ops | Filter, Map, FoldLeft, AppendAll, ForEach |
GALA vs Go: Side-by-Side
Log Levels
| GALA | Go |
|---|---|
|
|
The Go version needs default: return "UNKNOWN" — a case that can never happen but the compiler can't prove it. GALA's exhaustive match eliminates it.
Aggregation
| GALA | Go |
|---|---|
|
|
Findings
| GALA | Go |
|---|---|
|
|
In Go, every Finding carries every field — most of them unused. Adding a new variant means remembering to update the switch. In GALA, each variant carries exactly its data, and the compiler enforces handling.
Running
Install GALA (instructions), then:
# GALA version
cd examples/log_analyzer && gala run
# Go equivalent (for comparison)
cd go_equivalent/log_analyzer && go run main.go
Both produce identical output.
Sample Output
=== Log Analysis Report ===
Processed: 20 entries
Time range: 2024-03-15T08:00:12Z .. 2024-03-15T08:01:05Z
--- Severity Breakdown ---
DEBUG 1 ( 5.0%)
INFO 10 (50.0%)
WARN 3 (15.0%)
ERROR 5 (25.0%)
FATAL 1 ( 5.0%)
--- Top Endpoints (by request count) ---
/api/users 7 reqs avg 161ms 0 errors
/api/orders 5 reqs avg 1082ms 2 errors
/api/payments 4 reqs avg 2510ms 4 errors
/api/products 4 reqs avg 245ms 0 errors
--- Findings ---
Error spike: 6 errors out of 20 entries (30.0%)
Slow endpoint: /api/orders (avg 1082ms, threshold 1000ms)
Slow endpoint: /api/payments (avg 2510ms, threshold 1000ms)
High error rate: /api/payments (100.0% failed)
--- Error Details ---
2024-03-15T08:00:22Z ERROR POST /api/payments: connection_refused
2024-03-15T08:00:34Z ERROR POST /api/payments: gateway_timeout
2024-03-15T08:00:46Z ERROR POST /api/orders: service_unavailable
2024-03-15T08:00:52Z ERROR PUT /api/payments: database_locked
2024-03-15T08:01:01Z ERROR POST /api/payments: connection_reset
2024-03-15T08:01:05Z FATAL POST /api/orders: out_of_memory
Key GALA Features Demonstrated
- Sealed types as data models —
LevelandFindingcarry variant-specific data without flat structs - Expression functions —
levelName,isError,severityWeightare single-expression definitions - Option[T] for safe parsing —
parseLinereturnsOption[LogEntry], no(T, bool)pattern - HashMap + FoldLeft — immutable accumulation replaces
map[string]*Twith nil checks - Array pipelines —
Filter,Map,AppendAll,ForEachreplace manual for-loops - Struct Copy() —
existing.Copy(Count = ...)for immutable updates - Direct Go stdlib —
strings.Fields(),strconv.Atoi(),fmt.Sprintf()work unchanged
Links
- GALA Language — compiler and standard library
- gala-state — state machine showcase
- Language Specification — full reference