feat: add main entry point and stdout sink for Docker build
- Create cmd/logcorrelator/main.go as the application entry point - Loads configuration from YAML file - Initializes Unix socket sources, file/ClickHouse/stdout sinks - Sets up correlation service and orchestrator - Handles graceful shutdown on SIGINT/SIGTERM - Supports -version flag to print version - Add internal/adapters/outbound/stdout/sink.go - Implements CorrelatedLogSink interface for stdout output - Writes JSON lines to standard output - Fix .gitignore to use /logcorrelator instead of logcorrelator - Prevents cmd/logcorrelator directory from being ignored Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>
This commit is contained in:
58
internal/adapters/outbound/stdout/sink.go
Normal file
58
internal/adapters/outbound/stdout/sink.go
Normal file
@ -0,0 +1,58 @@
|
||||
package stdout
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"os"
|
||||
"sync"
|
||||
|
||||
"github.com/logcorrelator/logcorrelator/internal/domain"
|
||||
)
|
||||
|
||||
// Config holds the stdout sink configuration.
|
||||
type Config struct {
|
||||
Enabled bool
|
||||
}
|
||||
|
||||
// StdoutSink writes correlated logs to stdout as JSON lines.
|
||||
type StdoutSink struct {
|
||||
config Config
|
||||
mu sync.Mutex
|
||||
enc *json.Encoder
|
||||
}
|
||||
|
||||
// NewStdoutSink creates a new stdout sink.
|
||||
func NewStdoutSink(config Config) *StdoutSink {
|
||||
return &StdoutSink{
|
||||
config: config,
|
||||
enc: json.NewEncoder(os.Stdout),
|
||||
}
|
||||
}
|
||||
|
||||
// Name returns the sink name.
|
||||
func (s *StdoutSink) Name() string {
|
||||
return "stdout"
|
||||
}
|
||||
|
||||
// Write writes a correlated log to stdout.
|
||||
func (s *StdoutSink) Write(ctx context.Context, log domain.CorrelatedLog) error {
|
||||
s.mu.Lock()
|
||||
defer s.mu.Unlock()
|
||||
|
||||
if err := s.enc.Encode(log); err != nil {
|
||||
return fmt.Errorf("failed to write to stdout: %w", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// Flush flushes any buffered data (no-op for stdout).
|
||||
func (s *StdoutSink) Flush(ctx context.Context) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Close closes the sink (no-op for stdout).
|
||||
func (s *StdoutSink) Close() error {
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user