utils

package
v0.0.64 Latest Latest
Warning

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

Go to latest
Published: Aug 20, 2025 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Overview

Package utils provides common utilities for devloop.

This package contains shared functionality used across the devloop ecosystem: - Logging infrastructure with colored prefix support - Color management for terminal output - Log management and streaming capabilities - Prefix writers for enhanced output formatting

Logging

The package provides structured logging with prefix support:

logger := utils.NewDevloopLogger(true, 10, colorManager)
logger.LogWithPrefix("build", "Starting build process")
// Output: [build     ] Starting build process

Color Management

Color management provides consistent terminal coloring:

colorManager := utils.NewColorManager(true)
coloredText := colorManager.FormatPrefix("[build]", rule)

Log Streaming

Log streaming enables real-time log access:

logManager := utils.NewLogManager(logsDir)
err := logManager.StreamLogs("ruleName", "filter", stream)

Prefix Writers

Enhanced output writers with prefix and color support:

writer := utils.NewColoredPrefixWriter(writers, "[prefix] ", colorManager, rule)
writer.Write([]byte("Hello World"))
// Output: [prefix] Hello World (with colors)

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func InitGlobalLogger added in v0.0.30

func InitGlobalLogger(prefixLogs bool, prefixMaxLength int, colorManager ColorFormatter)

InitGlobalLogger initializes the global logger with configuration

func LogDevloop added in v0.0.30

func LogDevloop(format string, args ...any)

LogDevloop logs a devloop message using the global logger

func LogGateway added in v0.0.30

func LogGateway(format string, args ...any)

LogGateway logs a gateway message using the global logger

func LogMCP added in v0.0.30

func LogMCP(format string, args ...any)

LogMCP logs an MCP message using the global logger

func StripColorCodes added in v0.0.30

func StripColorCodes(input string) string

StripColorCodes removes ANSI color codes from a string using regex

Types

type ColorFormatter added in v0.0.30

type ColorFormatter interface {
	IsEnabled() bool
	FormatPrefix(prefix string, rule any) string
}

ColorFormatter interface for formatting colored prefixes

type ColorManager added in v0.0.30

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

ColorManager handles color assignment and formatting for rule output

func NewColorManager added in v0.0.30

func NewColorManager(settings ColorSettings) *ColorManager

NewColorManager creates a new color manager with the given settings

func (*ColorManager) DisableColors added in v0.0.30

func (cm *ColorManager) DisableColors()

DisableColors explicitly disables color output for this ColorManager only

func (*ColorManager) FormatPrefix added in v0.0.30

func (cm *ColorManager) FormatPrefix(prefix string, rule interface{}) string

FormatPrefix applies color formatting to a prefix string

func (*ColorManager) GetColorForRule added in v0.0.30

func (cm *ColorManager) GetColorForRule(rule ColorRule) *color.Color

GetColorForRule returns the appropriate color for a given rule

func (*ColorManager) GetColoredString added in v0.0.30

func (cm *ColorManager) GetColoredString(text string, rule ColorRule) string

GetColoredString returns a colored version of the input string for the given rule

func (*ColorManager) IsEnabled added in v0.0.30

func (cm *ColorManager) IsEnabled() bool

IsEnabled returns whether color formatting is enabled

type ColorRule added in v0.0.30

type ColorRule interface {
	GetName() string
	GetColor() string
	GetPrefix() string
}

ColorRule represents a rule that can have colors applied to it

type ColorSettings added in v0.0.30

type ColorSettings interface {
	GetColorLogs() bool
	GetColorScheme() string
	GetCustomColors() map[string]string
}

ColorSettings represents the color configuration needed by ColorManager

type ColoredPrefixWriter added in v0.0.30

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

ColoredPrefixWriter is an enhanced io.Writer that adds colored prefixes to each line of output It separates terminal output (with colors) from file output (without colors)

func NewColoredPrefixWriter added in v0.0.30

func NewColoredPrefixWriter(writers []io.Writer, prefix string, colorManager *ColorManager, rule Nameable) *ColoredPrefixWriter

NewColoredPrefixWriter creates a new ColoredPrefixWriter

func (*ColoredPrefixWriter) UpdatePrefix added in v0.0.30

func (cpw *ColoredPrefixWriter) UpdatePrefix(newPrefix string)

UpdatePrefix updates the prefix and regenerates the colored version

func (*ColoredPrefixWriter) Write added in v0.0.30

func (cpw *ColoredPrefixWriter) Write(p []byte) (n int, err error)

Write implements the io.Writer interface with color support

func (*ColoredPrefixWriter) WriteToFileOnly added in v0.0.30

func (cpw *ColoredPrefixWriter) WriteToFileOnly(p []byte) (n int, err error)

WriteToFileOnly writes output only to file writers (without colors)

func (*ColoredPrefixWriter) WriteToTerminalOnly added in v0.0.30

func (cpw *ColoredPrefixWriter) WriteToTerminalOnly(p []byte) (n int, err error)

WriteToTerminalOnly writes output only to terminal writers (with colors)

type DevloopLogger added in v0.0.30

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

DevloopLogger provides consistent logging across all components

func NewDevloopLogger added in v0.0.30

func NewDevloopLogger(prefixLogs bool, prefixMaxLength int, colorManager ColorFormatter) *DevloopLogger

NewDevloopLogger creates a new logger with the given configuration

func (*DevloopLogger) LogWithPrefix added in v0.0.30

func (dl *DevloopLogger) LogWithPrefix(prefix, format string, args ...any)

LogWithPrefix logs a message with the specified prefix (e.g., "devloop", "gateway", "mcp")

type LogManager added in v0.0.30

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

LogManager manages log files and provides streaming capabilities.

func NewLogManager added in v0.0.30

func NewLogManager(logDir string) (*LogManager, error)

NewLogManager creates a new LogManager instance.

func (*LogManager) Close added in v0.0.30

func (lm *LogManager) Close() error

Close closes the LogManager and cleans up resources.

func (*LogManager) GetWriter added in v0.0.30

func (lm *LogManager) GetWriter(ruleName string) (io.Writer, error)

GetWriter returns an io.Writer for a specific rule's log file.

func (*LogManager) SignalFinished added in v0.0.30

func (lm *LogManager) SignalFinished(ruleName string)

SignalFinished signals that a rule's execution has finished.

func (*LogManager) StreamLogs added in v0.0.30

func (lm *LogManager) StreamLogs(ruleName, filter string, timeoutSeconds int64, writer *gocurrent.Writer[*pb.StreamLogsResponse]) error

StreamLogs streams logs for a given rule to the provided gocurrent Writer.

type LoggerConfig added in v0.0.30

type LoggerConfig struct {
	PrefixLogs      bool
	PrefixMaxLength int
	ColorManager    ColorFormatter
}

LoggerConfig holds configuration for consistent logging

type Nameable added in v0.0.30

type Nameable interface {
	GetName() string
}

Nameable represents anything that has a name (used for color generation)

type SimpleColorRule added in v0.0.30

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

SimpleColorRule is a basic implementation of ColorRule for simple cases

func (*SimpleColorRule) GetColor added in v0.0.30

func (r *SimpleColorRule) GetColor() string

func (*SimpleColorRule) GetName added in v0.0.30

func (r *SimpleColorRule) GetName() string

func (*SimpleColorRule) GetPrefix added in v0.0.30

func (r *SimpleColorRule) GetPrefix() string

Jump to

Keyboard shortcuts

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