Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 14 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ Thread-safe C++ logging library with real-time output and customizable formattin
logcoe is a lightweight, thread-safe C++ logging library designed for high-performance applications. It provides flexible output options and real-time logging with minimal overhead:

```
[2025-06-07_14:30:25] [INFO]: Application started successfully
[2025-06-07_14:30:25] [DEBUG] [NetworkManager]: Connecting to server 192.168.1.100
[2025-06-07_14:30:26] [WARNING] [Database]: Connection timeout, retrying...
[2025-06-07_14:30:27] [ERROR] [FileSystem]: Failed to open configuration file
[06/07/2025__14:30:25] [INFO]: Application started successfully
[06/07/2025__14:30:25] [DEBUG] [NetworkManager]: Connecting to server 192.168.1.100
[06/07/2025__14:30:26] [WARNING] [Database]: Connection timeout, retrying...
[06/07/2025__14:30:27] [ERROR] [FileSystem]: Failed to open configuration file
```

Perfect for applications requiring reliable logging across multiple threads with customizable output destinations.
Expand All @@ -32,7 +32,7 @@ include(FetchContent)
FetchContent_Declare(
logcoe
GIT_REPOSITORY https://github.com/nircoe/logcoe.git
GIT_TAG v0.1.0
GIT_TAG v0.1.1
)
FetchContent_MakeAvailable(logcoe)

Expand Down Expand Up @@ -90,14 +90,14 @@ int main() {

## Features

- 🔒 **Thread-Safe** - Concurrent logging from multiple threads
- 📊 **Multiple Log Levels** - DEBUG, INFO, WARNING, ERROR with runtime filtering
- 🖥️ **Dual Output** - Console and file output simultaneously
- **High Performance** - Minimal overhead with optional flushing control
- 🎨 **Customizable** - Configurable time formats and output streams
- 🔄 **Dynamic Configuration** - Change settings during runtime
- 📦 **Zero Dependencies** - Header-only public API, pure C++17
- 🌐 **Cross-Platform** - Windows, Linux, macOS support
- **Thread-Safe** - Concurrent logging from multiple threads
- **Multiple Log Levels** - DEBUG, INFO, WARNING, ERROR with runtime filtering
- **Dual Output** - Console and file output simultaneously
- **High Performance** - Minimal overhead with optional flushing control
- **Customizable** - Configurable time formats and output streams
- **Dynamic Configuration** - Change settings during runtime
- **Zero Dependencies** - Header-only public API, pure C++17
- **Cross-Platform** - Windows, Linux, macOS support

## API Reference

Expand All @@ -115,7 +115,7 @@ logcoe::initialize(
"application.log" // Filename
);

// Clean shutdown
// shutdown
logcoe::shutdown();
```

Expand Down
95 changes: 35 additions & 60 deletions docs/ARCHITECTURE.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,30 +7,29 @@ logcoe is designed as a lightweight, thread-safe logging library that provides f
## Component Architecture

```
┌─────────────────────────────────────┐
│ User Application │
│ (Client Code) │
└───────────────┬─────────────────────┘
┌───────────────▼─────────────────────┐
│ logcoe API │
│ (Public Interface Functions) │
└───────────────┬─────────────────────┘
┌───────────────▼─────────────────────┐
│ LoggerImpl │
│ (Internal Implementation) │
│ │
│ ┌─────────────┬─────────────────┐ │
│ │ Mutex │ Output Streams │ │
│ │ Protection │ Management │ │
│ └─────────────┴─────────────────┘ │
│ │
│ ┌─────────────┬─────────────────┐ │
│ │ Log Level │ Timestamp │ │
│ │ Filtering │ Formatting │ │
│ └─────────────┴─────────────────┘ │
└─────────────────────────────────────┘
┌─────────────────────────────────────┐
│ User Application │
│ (Client Code) │
└──────────────────┬──────────────────┘
┌──────────────────▼──────────────────┐
│ logcoe API │
│ (Public Interface Functions) │
└──────────────────┬──────────────────┘
┌──────────────────▼──────────────────┐
│ LoggerImpl │
│ (Internal Implementation) │
│ │
│ ┌─────────────┬─────────────────┐ │
│ │ Mutex │ Output Streams │ │
│ │ Protection │ Management │ │
│ └─────────────┴─────────────────┘ │
│ ┌─────────────┬─────────────────┐ │
│ │ Log Level │ Timestamp │ │
│ │ Filtering │ Formatting │ │
│ └─────────────┴─────────────────┘ │
└─────────────────────────────────────┘
```

## Core Components
Expand All @@ -53,9 +52,7 @@ logcoe is designed as a lightweight, thread-safe logging library that provides f
```cpp
static std::mutex s_mutex;
```
- **Purpose**: Ensures thread-safe access to all shared state
- **Scope**: Protects all static members and operations
- **Granularity**: Single global mutex for simplicity and correctness
- Ensures thread-safe access to all static members and operations

#### State Management
```cpp
Expand All @@ -64,9 +61,7 @@ static bool s_useFile;
static bool s_useConsole;
static std::string s_timeFormat;
```
- **Purpose**: Maintains current logger configuration
- **Thread Safety**: All access protected by mutex
- **Dynamic Updates**: Can be changed at runtime
- Maintains current logger configuration, Can be changed at runtime

#### Output Stream Management
```cpp
Expand All @@ -76,7 +71,6 @@ static std::ostream* s_consoleStream;
```
- **File Output**: Direct file stream management with automatic opening/closing
- **Console Output**: Configurable output stream (default: std::cout)
- **Stream Safety**: All stream operations are mutex-protected

## Data Flow

Expand Down Expand Up @@ -139,18 +133,8 @@ Release mutex lock

## Thread Safety Implementation

### Mutex Strategy
- **Single Global Mutex**: `std::mutex s_mutex`
- **Lock Scope**: Every public API call acquires lock for entire duration
- **Benefits**:
- Simple design, no deadlock risk
- Guaranteed consistency across all operations
- Atomic configuration changes

### Performance Considerations
- **Lock Granularity**: Coarse-grained locking for simplicity
- **Lock Duration**: Minimal time holding locks
- **Flush Control**: Optional flushing to reduce I/O under lock

### Thread Safety Guarantees
1. **Configuration Consistency**: All threads see consistent logger state
Expand All @@ -172,12 +156,10 @@ std::tm tm_now;
```
- **Windows**: Uses `localtime_s` for thread safety
- **Unix/Linux/macOS**: Uses `localtime_r` for thread safety
- **Format**: Standard `strftime` formatting across platforms

### File System Operations
- **Path Handling**: Uses standard C++ filesystem operations
- **File Permissions**: Relies on OS default permissions
- **Directory Creation**: Not automatic, requires existing directories

### Build System Integration
- **CMake**: FetchContent compatible
Expand All @@ -188,7 +170,7 @@ std::tm tm_now;

### Static Storage
- **Lifetime**: All state stored in static variables
- **Initialization**: Lazy initialization through first API call
- **Initialization**: Lazy initialization through `initialize()`
- **Cleanup**: Explicit cleanup through `shutdown()`

### Resource Management
Expand All @@ -198,28 +180,26 @@ std::tm tm_now;

## Log Level Filtering

### Filtering Logic
### Level Hierarchy
```
DEBUG (0) < INFO (1) < WARNING (2) < ERROR (3) < NONE (4)
```

```cpp
if (static_cast<int>(level) < static_cast<int>(s_logLevel))
return;
```

- **Numeric Comparison**: Log levels assigned integer values
- **Early Return**: Filtered messages exit immediately
- **Performance**: O(1) filtering with minimal overhead

### Level Hierarchy
```
DEBUG (0) < INFO (1) < WARNING (2) < ERROR (3) < NONE (4)
```

## Message Formatting

### Format Structure
```
[timestamp] [LEVEL] [source]: message
[timestamp] [LEVEL] [source]: <message>
```

### Components
- **Timestamp**: Configurable format using strftime
- **Level**: String representation of LogLevel enum
- **Source**: Optional component identifier
Expand All @@ -229,11 +209,11 @@ DEBUG (0) < INFO (1) < WARNING (2) < ERROR (3) < NONE (4)

### Stream Failures
- **File Open Errors**: Logged to console, file output disabled
- **Write Failures**: Silent failure, no cascading errors
- **Write Failures**: Silent failure, no exceptions
- **Configuration Errors**: Invalid settings ignored with warnings

### Exception Safety
- **No Throws**: Public API designed to never throw
- **No Exceptions**: Public API designed to never throw exceptions
- **Resource Safety**: RAII ensures proper resource cleanup
- **State Consistency**: Mutex ensures consistent state even with errors

Expand All @@ -243,8 +223,3 @@ DEBUG (0) < INFO (1) < WARNING (2) < ERROR (3) < NONE (4)
- **Logging**: O(1) for level filtering, O(log_message_length) for formatting
- **Configuration**: O(1) for most operations
- **Thread Contention**: Minimal with short lock durations

### Space Complexity
- **Memory Usage**: Fixed overhead independent of message count
- **File Growth**: Linear with number of logged messages
- **Buffer Management**: No internal buffering beyond stream buffers
Loading
Loading