Files
next.orly.dev/pkg/bbolt/logger.go
woikos 9fed1261ad Add BBolt database backend for HDD-optimized archival relays (v0.48.0)
- BBolt B+tree backend with sequential access patterns for spinning disks
- Write batching (5000 events / 128MB / 30s flush) to reduce disk thrashing
- Adjacency list storage for graph data (one key per vertex, not per edge)
- Bloom filter for fast negative edge existence checks (~12MB for 10M edges)
- No query cache (saves RAM, B+tree reads are fast enough on HDD)
- Migration tool: orly migrate --from badger --to bbolt
- Configuration: ORLY_BBOLT_* environment variables

Files modified:
- app/config/config.go: Added BBolt configuration options
- main.go: Added migrate subcommand and BBolt config wiring
- pkg/database/factory.go: Added BBolt factory registration
- pkg/bbolt/*: New BBolt database backend implementation

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-06 06:50:58 +01:00

82 lines
2.0 KiB
Go

//go:build !(js && wasm)
package bbolt
import (
"fmt"
"runtime"
"strings"
"go.uber.org/atomic"
"lol.mleku.dev"
"lol.mleku.dev/log"
)
// Logger wraps the lol logger for BBolt
type Logger struct {
Level atomic.Int32
Label string
}
// NewLogger creates a new Logger instance
func NewLogger(level int, dataDir string) *Logger {
l := &Logger{Label: "bbolt"}
l.Level.Store(int32(level))
return l
}
// SetLogLevel updates the log level
func (l *Logger) SetLogLevel(level int) {
l.Level.Store(int32(level))
}
// Tracef logs a trace message
func (l *Logger) Tracef(format string, args ...interface{}) {
if l.Level.Load() >= int32(lol.Trace) {
s := l.Label + ": " + format
txt := fmt.Sprintf(s, args...)
_, file, line, _ := runtime.Caller(2)
log.T.F("%s\n%s:%d", strings.TrimSpace(txt), file, line)
}
}
// Debugf logs a debug message
func (l *Logger) Debugf(format string, args ...interface{}) {
if l.Level.Load() >= int32(lol.Debug) {
s := l.Label + ": " + format
txt := fmt.Sprintf(s, args...)
_, file, line, _ := runtime.Caller(2)
log.D.F("%s\n%s:%d", strings.TrimSpace(txt), file, line)
}
}
// Infof logs an info message
func (l *Logger) Infof(format string, args ...interface{}) {
if l.Level.Load() >= int32(lol.Info) {
s := l.Label + ": " + format
txt := fmt.Sprintf(s, args...)
_, file, line, _ := runtime.Caller(2)
log.I.F("%s\n%s:%d", strings.TrimSpace(txt), file, line)
}
}
// Warningf logs a warning message
func (l *Logger) Warningf(format string, args ...interface{}) {
if l.Level.Load() >= int32(lol.Warn) {
s := l.Label + ": " + format
txt := fmt.Sprintf(s, args...)
_, file, line, _ := runtime.Caller(2)
log.W.F("%s\n%s:%d", strings.TrimSpace(txt), file, line)
}
}
// Errorf logs an error message
func (l *Logger) Errorf(format string, args ...interface{}) {
if l.Level.Load() >= int32(lol.Error) {
s := l.Label + ": " + format
txt := fmt.Sprintf(s, args...)
_, file, line, _ := runtime.Caller(2)
log.E.F("%s\n%s:%d", strings.TrimSpace(txt), file, line)
}
}