loganalyst

package
v0.1.21 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 18, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package loganalyst queries structured logs and produces AI-powered or fallback natural-language summaries of agent sessions, issues, failures, and arbitrary time ranges.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Analyst

type Analyst struct {
	// contains filtered or unexported fields
}

Analyst coordinates log querying, AI summarization, and caching.

func New

func New(logs LogQuerier, ollama OllamaClient, logger *zap.Logger) *Analyst

New creates an Analyst. If ollama is nil the analyst produces structured fallback summaries instead of AI-generated text.

func (*Analyst) Summarize

func (a *Analyst) Summarize(ctx context.Context, scope ScopeFilter) (summary *Summary, err error)

Summarize returns a natural-language summary for the given scope. Results are cached for 5 minutes.

type LogQuerier

type LogQuerier interface {
	Query(ctx context.Context, f logstore.QueryFilter) ([]logstore.LogEntry, error)
}

LogQuerier abstracts the logstore for testing.

type OllamaAnalystHTTP

type OllamaAnalystHTTP struct {
	// contains filtered or unexported fields
}

OllamaAnalystHTTP is a minimal HTTP client for the Ollama /api/generate endpoint. It does not stream; it waits for the full response.

func NewOllamaAnalystClient

func NewOllamaAnalystClient(url, model string, timeout time.Duration) *OllamaAnalystHTTP

NewOllamaAnalystClient creates a client that calls the Ollama generate API.

func (*OllamaAnalystHTTP) Generate

func (c *OllamaAnalystHTTP) Generate(ctx context.Context, prompt string) (text string, err error)

Generate sends a prompt to Ollama and returns the generated text.

type OllamaClient

type OllamaClient interface {
	Generate(ctx context.Context, prompt string) (string, error)
}

OllamaClient abstracts the Ollama generate API for testing.

type ScopeFilter

type ScopeFilter struct {
	Type  ScopeType `json:"type"`
	ID    string    `json:"id"`    // session ID or issue number as string
	Since time.Time `json:"since"` // for timerange/failures
	Until time.Time `json:"until"` // for timerange
}

ScopeFilter selects which logs to analyze.

type ScopeType

type ScopeType string

ScopeType identifies what dimension of logs to summarize.

const (
	// ScopeSession summarizes logs for a single agent session.
	ScopeSession ScopeType = "session"
	// ScopeIssue summarizes logs related to a specific issue number.
	ScopeIssue ScopeType = "issue"
	// ScopeTimeRange summarizes logs within an explicit time window.
	ScopeTimeRange ScopeType = "timerange"
	// ScopeFailures summarizes only error-level logs since a given time.
	ScopeFailures ScopeType = "failures"
)

type Summary

type Summary struct {
	Scope        ScopeFilter `json:"scope"`
	Text         string      `json:"text"`
	TotalEntries int         `json:"total_entries"`
	ErrorCount   int         `json:"error_count"`
	WarnCount    int         `json:"warn_count"`
	Components   []string    `json:"components"`
	AIGenerated  bool        `json:"ai_generated"`
	GeneratedAt  time.Time   `json:"generated_at"`
}

Summary is the result of a log analysis.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL