How alonza0314/logger-go works
Project Type and Purpose
• This is a Go library and CLI tool (“logger-go”) for producing leveled logs (info, error, warn, test, debug).
• It can be integrated into other Go projects (as a package) or used standalone via its CLI binary.
Main Architectural Components
a. CLI Layer
• cmd/root.go and cmd/logger.go define the command-line interface.
• Parses command and arguments (level, tag, message).
• Delegates to the core logger package.
b. Core Logger Package
• logger.go: defines global functions Info(), Error(), etc. that call an underlying Logger instance.
• const.go: defines log levels and defaults.
c. File Logger Module
• fileLogger.go: implements Logger interface for writing to files.
• fileLoggerOpt.go: implements the functional-options pattern (WithFlag, WithPerm, WithColor).
d. Output Providers
• StdOut provider (default) writes to os.Stdout with optional coloring.
• File provider writes to an *os.File handle.
e. External Dependencies
• Operating system file system (for file logger).
• Terminal/console (for STDOUT logger).
f. Testing
• logger_test.go and fileLogger_test.go verify behavior of both outputs.
Relationships and Data Flow
• The CLI parses user input → invokes loggergo.<Level>(...) functions →
based on build-time or runtime setup, routes to either StdOutLogger or FileLogger →
• Functional options are applied at NewFileLogger() time to configure file open flags, permissions, coloring.
Key Architectural Patterns
• Functional Options pattern in fileLoggerOpt.go to configure file logger behavior.
• Strategy pattern: interchangeable output strategies (StdOut vs File).
• Separation of concerns between CLI parsing, logging interface, and output mechanisms.