all repos — llm_aggregator @ 6e3abd0665fe86906baf2db7652595d393f2ffc3

A CLI tool to aggregate RSS feeds and summarise them with LLMs

internal/progress/progress.go (view raw)

 1package progress
 2
 3import (
 4	"fmt"
 5	"io"
 6)
 7
 8// Logger provides logging interface for the aggregator
 9type Logger interface {
10	Logf(format string, args ...any)
11	Warningf(format string, args ...any)
12	Debugf(format string, args ...any)
13}
14
15// Progress provides progress reporting interface for TUI
16type Progress interface {
17	Logger
18	SetStage(stage string)
19	SetSubStage(status string)
20	SetArticleCount(total, processed int)
21}
22
23// SimpleLogger implements Logger with io.Writer output
24type SimpleLogger struct {
25	writer io.Writer
26	debug  bool
27}
28
29// NewSimpleLogger creates a new SimpleLogger
30func NewSimpleLogger(writer io.Writer, debug bool) *SimpleLogger {
31	return &SimpleLogger{
32		writer: writer,
33		debug:  debug,
34	}
35}
36
37func (sl *SimpleLogger) Logf(format string, args ...any) {
38	fmt.Fprintf(sl.writer, format+"\n", args...)
39}
40
41func (sl *SimpleLogger) Warningf(format string, args ...any) {
42	fmt.Fprintf(sl.writer, "Warning: "+format+"\n", args...)
43}
44
45func (sl *SimpleLogger) Debugf(format string, args ...any) {
46	if sl.debug {
47		fmt.Fprintf(sl.writer, "Debug: "+format+"\n", args...)
48	}
49}
50
51// NoopLogger implements Logger with no output
52type NoopLogger struct{}
53
54func (nl *NoopLogger) Logf(format string, args ...any)     {}
55func (nl *NoopLogger) Warningf(format string, args ...any) {}
56func (nl *NoopLogger) Debugf(format string, args ...any)   {}
57
58// Context provides progress context for components
59type Context struct {
60	logger Logger
61}
62
63// NewContext creates a new progress context
64func NewContext(logger Logger) *Context {
65	return &Context{
66		logger: logger,
67	}
68}
69
70// Logf logs a message
71func (c *Context) Logf(format string, args ...any) {
72	if c.logger != nil {
73		c.logger.Logf(format, args...)
74	}
75}
76
77// Warningf logs a warning
78func (c *Context) Warningf(format string, args ...any) {
79	if c.logger != nil {
80		c.logger.Warningf(format, args...)
81	}
82}
83
84// Debugf logs a debug message
85func (c *Context) Debugf(format string, args ...any) {
86	if c.logger != nil {
87		c.logger.Debugf(format, args...)
88	}
89}
90