# alonza0314/logger-go architecture

> Architecture diagram of the GitHub repository alonza0314/logger-go, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-21). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/alonza0314/logger-go
- Repository: https://github.com/alonza0314/logger-go

## Overview

##### 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.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Subgraph CLI Layer
    subgraph "CLI Binary (cmd/)" 
        direction TB
        CLIRoot["root.go\n(subcommands: info, error, warn, test, debug)"]:::internal
        CLILogger["logger.go\n(parse args)"]:::internal
    end

    %% Core Logger Package
    subgraph "Logger Package" 
        direction TB
        CoreLogger["logger.go\n(Info(), Error(), etc.)"]:::internal
        ConstDefs["const.go\n(log levels)"]:::internal
    end

    %% Output Strategies
    subgraph "Output Strategies"
        direction TB
        StdOutLogger["StdOut Logger\n(os.Stdout, coloring)"]:::internal
        FileLogger["File Logger\n(flags, perms, color)"]:::internal
        FuncOptions["Functional Options\n(WithFlag, WithPerm, WithColor)"]:::options
    end

    %% External Systems
    Terminal["Terminal/Console"]:::external
    OSFS["OS Filesystem"]:::external

    %% Connections with labels and steps
    CLIRoot -->|"1: invoke command"| CLILogger
    CLILogger -->|"2: call Info()/Error()"| CoreLogger
    CoreLogger -->|"3a: StdOut strategy"| StdOutLogger
    CoreLogger -->|"3b: File strategy"| FileLogger
    FuncOptions -->|"options applied"| FileLogger
    StdOutLogger -->|"4: write()"| Terminal
    FileLogger -->|"4: write()"| OSFS

    %% Click Events
    click CLIRoot "https://github.com/alonza0314/logger-go/blob/main/cmd/root.go"
    click CLILogger "https://github.com/alonza0314/logger-go/blob/main/cmd/logger.go"
    click CoreLogger "https://github.com/alonza0314/logger-go/blob/main/logger.go"
    click ConstDefs "https://github.com/alonza0314/logger-go/blob/main/const.go"
    click FileLogger "https://github.com/alonza0314/logger-go/blob/main/fileLogger.go"
    click FuncOptions "https://github.com/alonza0314/logger-go/blob/main/fileLoggerOpt.go"

    %% Styles
    classDef internal fill:#D6EAF8,stroke:#3498DB,stroke-width:1px,color:#154360;
    classDef external fill:#F2F4F4,stroke:#7B7D7D,stroke-width:1px,color:#566573;
    classDef options fill:#FCF3CF,stroke:#F1C40F,stroke-width:1px,color:#7D6608;
```
