How changkongfeiyun/c-log works
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: log.c Log Core · build.sh Test Build Script · macro_define.h Level Macros · log.h Logger API
Components 15
Public Integration
- Application Threads · Concurrent callers emit level-specific log records.
- Logger API
src/log.h - Level Macros · Provides logging convenience and compile-time controls.
src/macro_define.h
Logging Runtime
- log_init · Sets minimum level, logger name, and output directory.
src/log.c - Log Core · Central filtering, synchronization, routing, and file-write boundary.
src/log.c - Severity Filter · Suppresses records below the configured minimum level.
src/log.c - Level File Routing · Routes warnings to error files as documented.
src/log.c - Process-Exit Cleanup · Logger shutdown is normally automatic at process exit.
src/log.c - Local Log Files · Files are written beneath the directory passed to initialization.
- OS File I/O · Disk throughput constrains sustained logging performance.
Native Validation
- Test Build Script · Builds the standalone native validation executables.
test/build.sh - Functional Test
test/test.c - Single-Thread Benchmark · Measures logging throughput.
test/bench_test.c - Thread Test · Exercises concurrent logging behavior.
test/thread_test.c - Ultimate Thread Test · Exercises concurrent logging behavior.
test/ultimate_test.c
Connections 19
- 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