# mishankov/logman architecture

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

- Interactive diagram: https://gitdiagram.com/mishankov/logman
- Repository: https://github.com/mishankov/logman

## Overview

##### Main Components
- Logger Core (logman.go): This is the central API that instantiates loggers using provided components.
- Loggers (in the “loggers” directory): Implements default logger behavior (e.g., NewDefaultLogger) that wraps the core functionality.
- Formatters (in the “formatters” directory): Contains multiple implementations for formatting log messages. This includes:
- DefaultFormatter – converts messages to a human-readable string.
- JSONFormatter – outputs logs in JSON format.
- Context-Aware Formatters – such as DefaultContextFormatter and JSONContextFormatter (which extract values from context).
- Filters (in the “filters” directory): Currently provides at least a LevelFilter that filters out messages based on log level.
- Writers (in the “writers” directory): Responsible for sending output to different destinations (e.g., a file writer that outputs logs to a file).
- Supporting files: The example_test.go and logman_test.go files ensure that TDD practices are followed, and CI/CD setups (in the .github folder) are maintained for quality.

##### Relationships and Interactions
- User Code/Application: It uses the Logman API to perform logging. When a log request is made (e.g., logger.Info or logger.Debug), the logger:
- Passes the log message (along with context, if applicable) to a Formatter.
- The Formatter processes the message into a final string (or JSON) representation.
- Before output, a Filter (like the LevelFilter) might check if the message should be logged.
- Finally, the processed message is forwarded to a Writer which delivers the log to its destination (stdout or file).
- Composition: The “custom logger” example in the README shows how different components (writer, formatter, and filter) are injected into the logger instance via the core API.

##### Architectural Patterns and Design Principles
- Component-Based Design: Each module (logger, formatter, filter, writer) performs a specific, isolated function, and the logger composes them together.
- Dependency Injection: The logger accepts a formatter, writer, and optionally a filter, allowing flexibility for different use cases.
- Extensibility: The design allows developers to create custom implementations to replace any of the built-in ones.
- Test-Driven Development (TDD): Evident from the test files, ensuring each component is well-tested.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Application layer
    A["User Code (Application)"]:::app

    %% Core logging API
    B["Logger (Core API)"]:::core

    %% Default Logger implementation
    C["Default Logger"]:::logger

    %% Formatters subgraph
    subgraph "Formatters"
        D1["DefaultFormatter"]:::formatter
        D2["JSONFormatter"]:::formatter
        D3["DefaultContextFormatter"]:::formatter
        D4["JSONContextFormatter"]:::formatter
    end

    %% Filters subgraph
    subgraph "Filters"
        E["LevelFilter"]:::filter
    end

    %% Writers subgraph
    subgraph "Writers"
        F["File Writer"]:::writer
    end

    %% Testing & CI/CD subgraph
    subgraph "Testing & CI/CD"
        T1["example_test.go"]:::test
        T2["logman_test.go"]:::test
        CI[".github"]:::test
    end

    %% Relationships
    A -->|"calls"| B
    C -->|"wraps"| B
    B -->|"formats"| D1
    B -->|"formats"| D2
    B -->|"formats"| D3
    B -->|"formats"| D4
    B -->|"filters"| E
    B -->|"writes"| F

    T1 -->|"verifies"| B
    T2 -->|"verifies"| B
    CI -->|"supports"| B

    %% Click Events
    click B "https://github.com/mishankov/logman/blob/main/logman.go"
    click C "https://github.com/mishankov/logman/blob/main/loggers/default.go"
    click D1 "https://github.com/mishankov/logman/blob/main/formatters/default.go"
    click D2 "https://github.com/mishankov/logman/blob/main/formatters/json.go"
    click D3 "https://github.com/mishankov/logman/blob/main/formatters/defaultcontext.go"
    click D4 "https://github.com/mishankov/logman/blob/main/formatters/jsoncontext.go"
    click E "https://github.com/mishankov/logman/blob/main/filters/level.go"
    click F "https://github.com/mishankov/logman/blob/main/writers/file.go"
    click T1 "https://github.com/mishankov/logman/blob/main/example_test.go"
    click T2 "https://github.com/mishankov/logman/blob/main/logman_test.go"
    click CI "https://github.com/mishankov/logman/blob/main/.github"

    %% Styles
    classDef core fill:#FFE4B5,stroke:#DAA520,stroke-width:2px;
    classDef logger fill:#E6E6FA,stroke:#9370DB,stroke-width:2px;
    classDef formatter fill:#B0E0E6,stroke:#4682B4,stroke-width:2px;
    classDef filter fill:#FFDAB9,stroke:#FF8C00,stroke-width:2px;
    classDef writer fill:#98FB98,stroke:#2E8B57,stroke-width:2px;
    classDef app fill:#FFFACD,stroke:#CCCC00,stroke-width:2px;
    classDef test fill:#F5DEB3,stroke:#DEB887,stroke-width:2px;
```
