# changkongfeiyun/c-log architecture

> Architecture diagram of the GitHub repository changkongfeiyun/c-log, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-08-17). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/changkongfeiyun/c-log
- Repository: https://github.com/changkongfeiyun/c-log

## Overview

#### Purpose and Entry Points
C-LOG is a C/C++ logging library intended for fast, stable, thread-safe file logging. Consumers initialize logging and emit records through level-specific macros such as `LOG_NOTICE`, `LOG_DEBUG`, `LOG_WARN`, and `LOG_ERROR`. The public-facing implementation and declarations are concentrated in `src/log.c` and `src/log.h`.

#### Logging API and Macro Layer
`src/log.h` defines the logger-facing API, including initialization and level-based logging interfaces. `src/macro_define.h` supplies convenience/error-handling macros and likely compile-time logging/output-file controls. This macro layer is the main integration boundary for application code: callers should not need to manage logger internals directly.

#### Log Lifecycle and Configuration
The primary control flow starts with `log_init(level, name, directory)`, which establishes the minimum log level, logical logger name, and output directory. The README indicates shutdown is normally automatic at process exit; explicit close behavior is exposed through level-associated writer objects. Runtime behavior is therefore configured primarily by initialization arguments and compile-time macros in `src/macro_define.h`.

#### Record Routing and Persistence
Log calls flow from level macros into the core implementation in `src/log.c`. Severity determines whether a message passes filtering and where it is written; notably, warning messages are described as being routed to error files. File-system throughput is a material performance boundary: benchmark claims are explicitly disk-dependent, with sustained writes constrained by SATA disk speed.

#### Thread-Safety Boundary
The library is designed for concurrent use. `src/log.c` is the central synchronization and file-write boundary, while callers can invoke logging macros from application threads. Concurrency behavior is exercised by the pthread-oriented test executable sources `test/thread_test.c` and `test/ultimate_test.c`.

#### Validation and Performance Executables
The repository ships standalone native test/benchmark programs rather than an application service. `test/build.sh` builds these executables; `test/bench_test.c` measures single-thread logging throughput, and `test/test.c` provides general functional coverage. No network service, database, web runtime, or external managed infrastructure is indicated.

#### Runtime and External Dependencies
The project targets native C/C++ environments and depends materially on OS file I/O, process-exit cleanup behavior, and pthread-style multithreading. Output is local log files under the directory passed to `log_init`; no external logging backend is described.

Main entry points: [`src/log.c`](https://github.com/changkongfeiyun/c-log/blob/master/src/log.c) (Log Core), [`test/build.sh`](https://github.com/changkongfeiyun/c-log/blob/master/test/build.sh) (Test Build Script), [`src/macro_define.h`](https://github.com/changkongfeiyun/c-log/blob/master/src/macro_define.h) (Level Macros), [`src/log.h`](https://github.com/changkongfeiyun/c-log/blob/master/src/log.h) (Logger API)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["Public Integration"]
  node_caller(("Application Threads<br/>consumer"))
  node_log_header["Logger API<br/>C header<br/>[log.h]"]
  node_macros["Level Macros<br/>macro header<br/>[macro_define.h]"]
end

subgraph group_runtime["Logging Runtime"]
  node_init["log_init<br/>lifecycle API<br/>[log.c]"]
  node_core["Log Core<br/>C implementation<br/>[log.c]"]
  node_filter["Severity Filter<br/>runtime stage<br/>[log.c]"]
  node_routing["Level File Routing<br/>runtime stage<br/>[log.c]"]
  node_exit_cleanup["Process-Exit Cleanup<br/>lifecycle behavior<br/>[log.c]"]
  node_local_files[("Local Log Files<br/>filesystem output")]
  node_os_io{{"OS File I/O<br/>native dependency"}}
end

subgraph group_validation["Native Validation"]
  node_build["Test Build Script<br/>shell build<br/>[build.sh]"]
  node_functional_test["Functional Test<br/>native executable source<br/>[test.c]"]
  node_benchmark["Single-Thread Benchmark<br/>native executable source<br/>[bench_test.c]"]
  node_thread_test["Thread Test<br/>pthread executable source<br/>[thread_test.c]"]
  node_ultimate_test["Ultimate Thread Test<br/>pthread executable source<br/>[ultimate_test.c]"]
end

node_caller -->|"uses"| node_macros
node_macros -->|"exposes API"| node_log_header
node_log_header -->|"declares"| node_init
node_macros -->|"emits records"| node_core
node_init -->|"configures"| node_core
node_core -->|"filters"| node_filter
node_filter -->|"accepted records"| node_routing
node_routing -->|"writes"| node_local_files
node_core -->|"synchronized file writes"| node_os_io
node_os_io -->|"persists"| node_local_files
node_core -.->|"registers cleanup"| node_exit_cleanup
node_build -->|"builds"| node_functional_test
node_build -->|"builds"| node_benchmark
node_build -->|"builds"| node_thread_test
node_build -->|"builds"| node_ultimate_test
node_functional_test -.->|"validates"| node_macros
node_benchmark -.->|"measures"| node_core
node_thread_test -.->|"exercises concurrency"| node_core
node_ultimate_test -.->|"exercises concurrency"| node_core

click node_log_header "https://github.com/changkongfeiyun/c-log/blob/master/src/log.h"
click node_macros "https://github.com/changkongfeiyun/c-log/blob/master/src/macro_define.h"
click node_init "https://github.com/changkongfeiyun/c-log/blob/master/src/log.c"
click node_core "https://github.com/changkongfeiyun/c-log/blob/master/src/log.c"
click node_filter "https://github.com/changkongfeiyun/c-log/blob/master/src/log.c"
click node_routing "https://github.com/changkongfeiyun/c-log/blob/master/src/log.c"
click node_exit_cleanup "https://github.com/changkongfeiyun/c-log/blob/master/src/log.c"
click node_build "https://github.com/changkongfeiyun/c-log/blob/master/test/build.sh"
click node_functional_test "https://github.com/changkongfeiyun/c-log/blob/master/test/test.c"
click node_benchmark "https://github.com/changkongfeiyun/c-log/blob/master/test/bench_test.c"
click node_thread_test "https://github.com/changkongfeiyun/c-log/blob/master/test/thread_test.c"
click node_ultimate_test "https://github.com/changkongfeiyun/c-log/blob/master/test/ultimate_test.c"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_caller,node_log_header,node_macros toneBlue
class node_init,node_core,node_filter,node_routing,node_exit_cleanup,node_local_files,node_os_io toneAmber
class node_build,node_functional_test,node_benchmark,node_thread_test,node_ultimate_test toneMint
```

## Components

### Public Integration

- **Application Threads**: consumer · Concurrent callers emit level-specific log records.
- [Logger API](https://github.com/changkongfeiyun/c-log/blob/master/src/log.h): C header · `src/log.h`
- [Level Macros](https://github.com/changkongfeiyun/c-log/blob/master/src/macro_define.h): macro header · Provides logging convenience and compile-time controls. · `src/macro_define.h`

### Logging Runtime

- [log_init](https://github.com/changkongfeiyun/c-log/blob/master/src/log.c): lifecycle API · Sets minimum level, logger name, and output directory. · `src/log.c`
- [Log Core](https://github.com/changkongfeiyun/c-log/blob/master/src/log.c): C implementation · Central filtering, synchronization, routing, and file-write boundary. · `src/log.c`
- [Severity Filter](https://github.com/changkongfeiyun/c-log/blob/master/src/log.c): runtime stage · Suppresses records below the configured minimum level. · `src/log.c`
- [Level File Routing](https://github.com/changkongfeiyun/c-log/blob/master/src/log.c): runtime stage · Routes warnings to error files as documented. · `src/log.c`
- [Process-Exit Cleanup](https://github.com/changkongfeiyun/c-log/blob/master/src/log.c): lifecycle behavior · Logger shutdown is normally automatic at process exit. · `src/log.c`
- **Local Log Files**: filesystem output · Files are written beneath the directory passed to initialization.
- **OS File I/O**: native dependency · Disk throughput constrains sustained logging performance.

### Native Validation

- [Test Build Script](https://github.com/changkongfeiyun/c-log/blob/master/test/build.sh): shell build · Builds the standalone native validation executables. · `test/build.sh`
- [Functional Test](https://github.com/changkongfeiyun/c-log/blob/master/test/test.c): native executable source · `test/test.c`
- [Single-Thread Benchmark](https://github.com/changkongfeiyun/c-log/blob/master/test/bench_test.c): native executable source · Measures logging throughput. · `test/bench_test.c`
- [Thread Test](https://github.com/changkongfeiyun/c-log/blob/master/test/thread_test.c): pthread executable source · Exercises concurrent logging behavior. · `test/thread_test.c`
- [Ultimate Thread Test](https://github.com/changkongfeiyun/c-log/blob/master/test/ultimate_test.c): pthread executable source · Exercises concurrent logging behavior. · `test/ultimate_test.c`

## Connections

- Application Threads → Level Macros: uses
- Level Macros → Logger API: exposes API
- Logger API → log_init: declares
- Level Macros → Log Core: emits records
- log_init → Log Core: configures
- Log Core → Severity Filter: filters
- Severity Filter → Level File Routing: accepted records
- Level File Routing → Local Log Files: writes
- Log Core → OS File I/O: synchronized file writes
- OS File I/O → Local Log Files: persists
- Log Core → Process-Exit Cleanup: registers cleanup
- Test Build Script → Functional Test: builds
- Test Build Script → Single-Thread Benchmark: builds
- Test Build Script → Thread Test: builds
- Test Build Script → Ultimate Thread Test: builds
- Functional Test → Level Macros: validates
- Single-Thread Benchmark → Log Core: measures
- Thread Test → Log Core: exercises concurrency
- Ultimate Thread Test → Log Core: exercises concurrency
