# sergiusthebest/plog architecture

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

- Interactive diagram: https://gitdiagram.com/sergiusthebest/plog
- Repository: https://github.com/sergiusthebest/plog

## Overview

##### Main Components
- Logger: Central singleton component (with variant “instanceId” support) that collects log records from macro calls.
- Record: Represents the data structure that encapsulates log message details (time, severity, thread id, file name, function name, message, etc.).
- Appender Interface (IAppender) and its concrete implementations:
– File-based appenders (RollingFileAppender)
– Console display (ConsoleAppender and ColorConsoleAppender)
– Platform-specific appenders (AndroidAppender, EventLogAppender, DebugOutputAppender)
– A dynamic container for add/remove operations (DynamicAppender)
- Formatter: Set of classes (TxtFormatter, CsvFormatter, FuncMessageFormatter, MessageOnlyFormatter) that take a Record and produce a formatted output.
- Converter: For example, the UTF8Converter and NativeEOLConverter, responsible for converting a formatted string into a native (binary) output (suitable for file encoding, for instance).

##### Relationships and Data Flow
- The logging process springs from the logging macros (PLOG, PLOGD, etc.) which construct a Record.
- The Record is passed to the Logger. The Logger (possibly a singleton) holds a list of IAppender pointers.
- Each Appender calls its Formatter’s static “format()” and “header()” functions to transform Record content.
- Then the Appender uses its Converter (if applicable) to convert the text into the appropriate output format (binary or native string encoding).
- Appender outputs the result to their destination (file system, console, platform-specific logs).

##### Architectural Patterns and Design Principles
- Component separation: There is a clear separation between record construction (Record), message routing (Logger), output formatting (Formatter) and the final output (Appenders and Converters).
- Extensibility: Custom formatters, appenders, and converters can be built easily and plugged in (as shown in the “Extending” section of the README).
- Lazy evaluation: Log streams are evaluated only if the current log level is active, minimizing performance overhead.

##### Relevant Technologies and Libraries
- This library appears to use templates extensively in its design (e.g., appender classes), so you might indicate parameterized components (like Logger<instanceId>, RollingFileAppender<Formatter, Converter>).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Logging Entry Layer
    subgraph "Logging Entry"
        LM("Log Macros/Entry Point"):::entry
        REC("Record"):::core
        LOGGER("Logger"):::core
    end
    LM -->|"creates"| REC
    REC -->|"sends_to"| LOGGER

    %% Appender Layer
    subgraph "Appender Layer"
        IA("IAppender (interface)"):::interface
        LOGGER --> IA
        subgraph "Concrete Appenders"
            RFA("RollingFileAppender"):::component
            CA("ConsoleAppender"):::component
            CCA("ColorConsoleAppender"):::component
            AA("AndroidAppender"):::component
            DOA("DebugOutputAppender"):::component
            EVA("EventLogAppender"):::component
            DA("DynamicAppender"):::component
        end
        IA --> RFA
        IA --> CA
        IA --> CCA
        IA --> AA
        IA --> DOA
        IA --> EVA
        IA --> DA
    end

    %% Formatting Layer
    subgraph "Formatting Layer"
        FMT("Formatter"):::pipeline
        FSEL("Select_Formatter"):::pipeline
        FMT --> FSEL
        subgraph "Formatter Variants"
            TFM("TxtFormatter"):::component
            CFM("CsvFormatter"):::component
            FMFM("FuncMessageFormatter"):::component
            MOM("MessageOnlyFormatter"):::component
        end
        FSEL --> TFM
        FSEL --> CFM
        FSEL --> FMFM
        FSEL --> MOM
    end

    %% Conversion Layer
    subgraph "Conversion Layer"
        CNV("Converter"):::pipeline
        CSEL("Select_Converter"):::pipeline
        CNV --> CSEL
        subgraph "Converter Variants"
            NEC("NativeEOLConverter"):::component
            U8C("UTF8Converter"):::component
        end
        CSEL --> NEC
        CSEL --> U8C
    end

    %% Output Layer
    subgraph "Output Layer"
        OUT("Destination"):::output
    end

    %% Connections from Appenders to Pipeline
    RFA -->|"formats"| FMT
    CA  -->|"formats"| FMT
    CCA -->|"formats"| FMT
    AA  -->|"formats"| FMT
    DOA -->|"formats"| FMT
    EVA -->|"formats"| FMT
    DA  -->|"formats"| FMT

    FMT -->|"converts"| CNV
    CNV -->|"outputs"| OUT

    %% Click Events for Logging Entry
    click LM "https://github.com/sergiusthebest/plog/blob/master/include/plog/Log.h"
    click REC "https://github.com/sergiusthebest/plog/blob/master/include/plog/Record.h"
    click LOGGER "https://github.com/sergiusthebest/plog/blob/master/include/plog/Logger.h"

    %% Click Events for Appender Layer
    click IA "https://github.com/sergiusthebest/plog/blob/master/include/plog/Appenders/IAppender.h"
    click RFA "https://github.com/sergiusthebest/plog/blob/master/include/plog/Appenders/RollingFileAppender.h"
    click CA "https://github.com/sergiusthebest/plog/blob/master/include/plog/Appenders/ConsoleAppender.h"
    click CCA "https://github.com/sergiusthebest/plog/blob/master/include/plog/Appenders/ColorConsoleAppender.h"
    click AA "https://github.com/sergiusthebest/plog/blob/master/include/plog/Appenders/AndroidAppender.h"
    click DOA "https://github.com/sergiusthebest/plog/blob/master/include/plog/Appenders/DebugOutputAppender.h"
    click EVA "https://github.com/sergiusthebest/plog/blob/master/include/plog/Appenders/EventLogAppender.h"
    click DA "https://github.com/sergiusthebest/plog/blob/master/include/plog/Appenders/DynamicAppender.h"

    %% Click Events for Formatters
    click TFM "https://github.com/sergiusthebest/plog/blob/master/include/plog/Formatters/TxtFormatter.h"
    click CFM "https://github.com/sergiusthebest/plog/blob/master/include/plog/Formatters/CsvFormatter.h"
    click FMFM "https://github.com/sergiusthebest/plog/blob/master/include/plog/Formatters/FuncMessageFormatter.h"
    click MOM "https://github.com/sergiusthebest/plog/blob/master/include/plog/Formatters/MessageOnlyFormatter.h"

    %% Click Events for Converters
    click NEC "https://github.com/sergiusthebest/plog/blob/master/include/plog/Converters/NativeEOLConverter.h"
    click U8C "https://github.com/sergiusthebest/plog/blob/master/include/plog/Converters/UTF8Converter.h"

    %% Styling
    classDef entry fill:#FFD700,stroke:#333,stroke-width:2px;
    classDef core fill:#C0FFC0,stroke:#333,stroke-width:2px;
    classDef interface fill:#CCE5FF,stroke:#333,stroke-width:2px,stroke-dasharray:5,5;
    classDef component fill:#FFFFCC,stroke:#333,stroke-width:2px;
    classDef pipeline fill:#D9EAD3,stroke:#333,stroke-width:2px;
    classDef output fill:#FCE5CD,stroke:#333,stroke-width:2px;
```
