# armink/easylogger architecture

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

- Interactive diagram: https://gitdiagram.com/armink/easylogger
- Repository: https://github.com/armink/easylogger

## Overview

##### Project type and purpose
- This is an open-source, embeddable C/C++ logging library (EasyLogger) designed for resource-constrained systems (bare-metal, RTOS, Linux, Windows, Nuttx).
- It provides a minimal API, plugin-based extensibility (file, flash, etc.), and OS-abstraction ports for thread safety and asynchronous output.

##### File structure
- Top level:
- easylogger/         ← core library source & headers
- demo/               ← per-OS and bare-metal example applications
- os/                 ← porting layers & demo code for various OSes (RT-Thread, FreeRTOS, Linux, Windows, Nuttx)
- docs/               ← user API, porting guides, images
- README.md           ← overall project description
- Patterns:
- Layered: core library → plugin folder → port folder → demo/app
- Plugin architecture: easylogger/plugins/*
- Port abstraction: elog_port.c under each OS directory
- Singleton/config module in elog_cfg.h

##### Key README insights
- Core features: customizable output, filtering, async/buffered mode, multi-OS support, RAW/hexdump formats.
- Plugins: Flash (EasyFlash integration), File (cycle/split), future plugins.
- Demos show CLI control, flash storage, file logging.

- Application layer (demo apps, user code)
- EasyLogger API (public headers)
- Core engine modules:
– Configuration & filtering
– Formatter (timestamp, level, tag)
– Output manager (sync/async, buffer)
– Utilities (hexdump, utils)
- Plugin modules:
– File plugin
– Flash plugin
– (others via plugin interface)
- Port/Hardware Abstraction Layer:
– elog_port implementations per OS
– HAL libraries (CMSIS, STM32 StdPeriph, HAL driver)
- OS / Runtime environments:
– Bare-metal
– FreeRTOS
– RT-Thread
– Linux
– Windows
– Nuttx

- App → EasyLogger API calls (elog_init, elog_flush, elog_set_level)
- API → Core engine (dispatch, filter, format)
- Core engine → Plugin interface (register, invoke)
- Plugin → Port HAL (elog_port_write)
- Port HAL → OS/HAL drivers → hardware (UART, file system, flash)
- Core engine using async buffer may spawn RTOS tasks or IRQ callbacks

c. Architectural patterns & principles:
- Layered architecture (Separation of concerns)
- Plugin/Strategy pattern for extensibility
- Singleton for global config
- Adapter pattern in port layer to unify OS/hardware calls
- Thread-safe queue for async logging

d. Relevant technologies & libraries:
- C/C++ ANSI code (easylogger/src, inc)
- CMSIS, STM32 HAL or StdPeriph (for embedded targets)
- FreeRTOS, RT-Thread kernels (port demos)
- POSIX APIs (Linux demo)
- Win32 APIs (Windows demo)
- Nuttx build system/apps

##### Detailed elements
- Component names (e.g., elog.c, elog_async.c, elog_port.c) or logical names (Config, Formatter, Output Manager)
- Plugin entry points (e.g., elog_file_port.c, elog_flash_port.c)
- I/O endpoints (UART, file system, Flash memory)
- Build artifacts if relevant (Makefile, CMakeLists.txt, IDE projects)

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Application Layer
    subgraph "Application / Demos" 
        direction TB
        DemoApp["Demo Application (bare-metal)"]:::app
        LinuxDemo["Linux Demo Application"]:::app
        CubeFRTOSDemo["Cube-FreeRTOS Demo Application"]:::app
    end

    %% API Layer
    subgraph "EasyLogger API" 
        direction TB
        API["EasyLogger API\n(easylogger/inc/elog.h)"]:::api
    end

    %% Core Engine
    subgraph "Core Engine" 
        direction TB
        Config["Configuration Module\n(easylogger/inc/elog_cfg.h)"]:::core
        Dispatcher["Dispatcher & Filtering\n(easylogger/src/elog.c)"]:::core
        AsyncMgr["Async Output Manager\n(easylogger/src/elog_async.c)"]:::core
        Buffer["Buffer Management\n(easylogger/src/elog_buf.c)"]:::core
        Utils["Utilities (Hexdump, Helpers)\n(easylogger/src/elog_utils.c)"]:::core
    end

    %% Plugin Layer
    subgraph "Plugin Modules" 
        direction TB
        subgraph "File Plugin" 
            direction TB
            FileImpl["File Plugin Impl\n(easylogger/plugins/file/elog_file.c)"]:::plugin
            FileHdr["File Plugin Header\n(easylogger/plugins/file/elog_file.h)"]:::plugin
            FileCfg["File Plugin Config\n(easylogger/plugins/file/elog_file_cfg.h)"]:::plugin
            FilePort["File Plugin Port Adapter\n(easylogger/plugins/file/elog_file_port.c)"]:::plugin
        end
        subgraph "Flash Plugin" 
            direction TB
            FlashImpl["Flash Plugin Impl\n(easylogger/plugins/flash/elog_flash.c)"]:::plugin
            FlashHdr["Flash Plugin Header\n(easylogger/plugins/flash/elog_flash.h)"]:::plugin
            FlashCfg["Flash Plugin Config\n(easylogger/plugins/flash/elog_flash_cfg.h)"]:::plugin
            FlashPort["Flash Plugin Port Adapter\n(easylogger/plugins/flash/elog_flash_port.c)"]:::plugin
        end
    end

    %% Port HAL Layer
    subgraph "Port / HAL Abstraction" 
        direction TB
        DefaultPort["Default Port\n(easylogger/port/elog_port.c)"]:::port
    end

    %% OS Demo Ports
    subgraph "OS Demo Port Implementations" 
        direction TB
        LinuxCfg["Linux Port Config\n(demo/os/linux/easylogger/inc/elog_cfg.h)"]:::port
        LinuxFilePort["Linux File Port\n(demo/os/linux/easylogger/port/elog_file_port.c)"]:::port
        LinuxDefPort["Linux Default Port\n(demo/os/linux/easylogger/port/elog_port.c)"]:::port
        CubeCfg["Cube-FreeRTOS Port Config\n(demo/os/cube-freertos/.../elog_cfg.h)"]:::port
        CubePortImpl["Cube-FreeRTOS Port Impl\n(demo/os/cube-freertos/.../elog_port.c)"]:::port
    end

    %% Hardware / OS
    subgraph "OS / Hardware Environments" 
        direction TB
        BareMetal["Bare-metal"]:::os
        FreeRTOS["FreeRTOS"]:::os
        RTThread["RT-Thread"]:::os
        LinuxOS["Linux"]:::os
        WindowsOS["Windows"]:::os
        Nuttx["Nuttx"]:::os
        UART["UART Driver"]:::os
        FileSys["File System"]:::os
        FlashMem["Flash Memory"]:::os
    end

    %% Connections
    DemoApp -->|"elog_init/write"| API
    LinuxDemo -->|"elog_init/write"| API
    CubeFRTOSDemo -->|"elog_init/write"| API

    API -->|"dispatch()"| Dispatcher
    Dispatcher -->|"filter() / format()"| Config
    Dispatcher -->|"filter() / format()"| Utils
    Dispatcher -->|"enqueue()"| AsyncMgr
    AsyncMgr -->|"buffer mgmt"| Buffer

    Dispatcher -->|"invoke plugin"| FileImpl
    Dispatcher -->|"invoke plugin"| FlashImpl

    FileImpl -->|"elog_port_write()"| DefaultPort
    FlashImpl -->|"elog_port_write()"| DefaultPort

    DefaultPort -->|"HAL calls"| UART
    DefaultPort -->|"HAL calls"| FileSys
    DefaultPort -->|"HAL calls"| FlashMem

    %% OS Demo ports usage
    LinuxDemo -->|"uses port"| LinuxCfg
    LinuxDemo -->|"uses port"| LinuxFilePort
    LinuxDemo -->|"uses port"| LinuxDefPort

    CubeFRTOSDemo -->|"uses port"| CubeCfg
    CubeFRTOSDemo -->|"uses port"| CubePortImpl

    %% Click Events
    click API "https://github.com/armink/easylogger/blob/master/easylogger/inc/elog.h"
    click Config "https://github.com/armink/easylogger/blob/master/easylogger/inc/elog_cfg.h"
    click Dispatcher "https://github.com/armink/easylogger/blob/master/easylogger/src/elog.c"
    click AsyncMgr "https://github.com/armink/easylogger/blob/master/easylogger/src/elog_async.c"
    click Buffer "https://github.com/armink/easylogger/blob/master/easylogger/src/elog_buf.c"
    click Utils "https://github.com/armink/easylogger/blob/master/easylogger/src/elog_utils.c"
    click FileImpl "https://github.com/armink/easylogger/blob/master/easylogger/plugins/file/elog_file.c"
    click FileHdr "https://github.com/armink/easylogger/blob/master/easylogger/plugins/file/elog_file.h"
    click FileCfg "https://github.com/armink/easylogger/blob/master/easylogger/plugins/file/elog_file_cfg.h"
    click FilePort "https://github.com/armink/easylogger/blob/master/easylogger/plugins/file/elog_file_port.c"
    click FlashImpl "https://github.com/armink/easylogger/blob/master/easylogger/plugins/flash/elog_flash.c"
    click FlashHdr "https://github.com/armink/easylogger/blob/master/easylogger/plugins/flash/elog_flash.h"
    click FlashCfg "https://github.com/armink/easylogger/blob/master/easylogger/plugins/flash/elog_flash_cfg.h"
    click FlashPort "https://github.com/armink/easylogger/blob/master/easylogger/plugins/flash/elog_flash_port.c"
    click DefaultPort "https://github.com/armink/easylogger/blob/master/easylogger/port/elog_port.c"
    click DemoApp "https://github.com/armink/easylogger/blob/master/demo/non_os/stm32f10x/app/src/app.c"
    click LinuxCfg "https://github.com/armink/easylogger/blob/master/demo/os/linux/easylogger/inc/elog_cfg.h"
    click LinuxFilePort "https://github.com/armink/easylogger/blob/master/demo/os/linux/easylogger/port/elog_file_port.c"
    click LinuxDefPort "https://github.com/armink/easylogger/blob/master/demo/os/linux/easylogger/port/elog_port.c"
    click CubeCfg "https://github.com/armink/easylogger/blob/master/demo/os/cube-freertos/nucleo-g070rb/Components/EasyLogger_Port/elog_cfg.h"
    click CubePortImpl "https://github.com/armink/easylogger/blob/master/demo/os/cube-freertos/nucleo-g070rb/Components/EasyLogger_Port/elog_port.c"

    %% Styles
    classDef app fill:#D8BFD8,stroke:#8A2BE2,color:#000;
    classDef api fill:#AFEEEE,stroke:#20B2AA,color:#000;
    classDef core fill:#ADD8E6,stroke:#0000CD,color:#000;
    classDef plugin fill:#90EE90,stroke:#008000,color:#000;
    classDef port fill:#FFA500,stroke:#FF8C00,color:#000;
    classDef os fill:#D3D3D3,stroke:#696969,color:#000;
```
