v0.13.1 folder restructure, test script added, format adapter async fix

This commit is contained in:
2026-07-17 09:09:00 -04:00
parent a48514a2eb
commit e96ede32ae
49 changed files with 402 additions and 206 deletions
+62
View File
@@ -0,0 +1,62 @@
package source
import (
"strings"
"time"
"logwisp/internal/core"
)
// Source represents an input data stream for log entries
type Source interface {
// Capabilities returns a slice of supported Source capabilities
Capabilities() []core.Capability
// Subscribe returns a channel that receives log entries from the source
Subscribe() <-chan core.LogEntry
// Start begins reading from the source
Start() error
// Stop gracefully shuts down the source
Stop()
// SourceStats contains statistics about a source
GetStats() SourceStats
}
// SourceStats contains statistics about a source
type SourceStats struct {
ID string
Type string
TotalEntries uint64
DroppedEntries uint64
StartTime time.Time
LastEntryTime time.Time
Details map[string]any
}
// ExtractLogLevel heuristically determines the log level from a line of text
func ExtractLogLevel(line string) string {
patterns := []struct {
patterns []string
level string
}{
{[]string{"[ERROR]", "ERROR:", " ERROR ", "ERR:", "[ERR]", "FATAL:", "[FATAL]"}, "ERROR"},
{[]string{"[WARN]", "WARN:", " WARN ", "WARNING:", "[WARNING]"}, "WARN"},
{[]string{"[INFO]", "INFO:", " INFO ", "[INF]", "INF:"}, "INFO"},
{[]string{"[DEBUG]", "DEBUG:", " DEBUG ", "[DBG]", "DBG:"}, "DEBUG"},
{[]string{"[TRACE]", "TRACE:", " TRACE "}, "TRACE"},
}
upperLine := strings.ToUpper(line)
for _, group := range patterns {
for _, pattern := range group.patterns {
if strings.Contains(upperLine, pattern) {
return group.level
}
}
}
return ""
}