# corvax/slogtfmt architecture

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

- Interactive diagram: https://gitdiagram.com/corvax/slogtfmt
- Repository: https://github.com/corvax/slogtfmt

## Overview

##### Main Components
- slogtfmt Package (Core logging handler)
– Contains the core functionality: NewHandler, NewHandlerWithOptions, and the Options struct.
– Defines default time formats (e.g., RFC3339Milli, RFC3339Micro) and handles configuration for log timestamps, source info, and time attribute formatting.
- loggerf Subpackage (Formatted logging wrapper)
– Wraps around the standard slog.Logger.
– Provides helper functions such as Debugf, Infof, Warnf, Errorf, and Logf.
- External Dependencies
– Standard Go libraries such as io.Writer, time, and potentially the external slog package.
– The main package (main.go) which uses the slogtfmt handler in a simple logging application.
- Testing and Supporting Files
– main_test.go, loggerf_test.go, and any examples in the README, which indicate usage patterns and integration tests.

##### Relationships and Interactions
- The core slogtfmt component is designed to be used by creating a new slog handler with a provided io.Writer and Options struct.
- The Options struct configures the behavior of the logging handler, with fields like Level, TimeFormat, and AddSource.
– Illustrate that “Options” configures “slogtfmt”.
- The loggerf package wraps a slog.Logger (which itself is built using the slogtfmt handler). It enhances logging with formatted output.
– Indicate that “loggerf” depends on “slogtfmt” (or more precisely, on the slog.Logger built with slogtfmt’s handler).
- External dependencies like the io.Writer (typically os.Stdout) and the slog library are used by both the handler and loggerf.

##### Architectural Patterns and Design Principles
- Layered design: There is a clear separation between the logging handler (slogtfmt) and the formatted logger (loggerf).
- Configuration-based: The use of an Options struct and “with” option functions demonstrates flexible configuration management.
- Wrapping/Decorator pattern: The loggerf package is an enhancement layer over the standard slog.Logger interface.

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Application Layer"
        App["Application (Main)"]:::app
    end

    subgraph "Core Logging Library"
        Options["Options & Time Format Constants"]:::core
        Handler["slogtfmt Handler: Custom Handler for slog"]:::core
        Options -->|"configures"| Handler
    end

    subgraph "Wrapper Layer"
        Loggerf["loggerf Logger Wrapper: Formatted Logger with Debugf/Infof"]:::wrapper
    end

    subgraph "External Libraries"
        Ext["External Packages & Libraries: slog,io,time"]:::external
    end

    subgraph "Testing & Support"
        TestMain["main_test.go"]:::test
        TestLoggerf["loggerf/loggerf_test.go"]:::test
    end

    App -->|"NewHandler"| Handler
    App -->|"instantiates"| Loggerf
    Handler -->|"uses"| Ext
    Loggerf -->|"wraps_logger_built_with"| Handler
    Loggerf -->|"uses"| Ext

    %% Click Events
    click App "https://github.com/corvax/slogtfmt/blob/main/main.go"
    click Handler "https://github.com/corvax/slogtfmt/blob/main/bufpool.go"
    click Options "https://github.com/corvax/slogtfmt/blob/main/bufpool.go"
    click Loggerf "https://github.com/corvax/slogtfmt/blob/main/loggerf/loggerf.go"
    click TestMain "https://github.com/corvax/slogtfmt/blob/main/main_test.go"
    click TestLoggerf "https://github.com/corvax/slogtfmt/blob/main/loggerf/loggerf_test.go"

    %% Styles
    classDef app fill:#FFF2CC,stroke:#BF9000,stroke-width:2px;
    classDef core fill:#CFE2F3,stroke:#2F5597,stroke-width:2px;
    classDef wrapper fill:#FCE5CD,stroke:#D79B00,stroke-width:2px;
    classDef external fill:#E2EFDA,stroke:#548235,stroke-width:2px;
    classDef test fill:#F4CCCC,stroke:#CC0000,stroke-width:2px;
```
