Skip to content

feat: Add file-based trade logging system and preview command#607

Open
hudsonandres wants to merge 1 commit intoerikzimmermann:developfrom
hudsonandres:feature
Open

feat: Add file-based trade logging system and preview command#607
hudsonandres wants to merge 1 commit intoerikzimmermann:developfrom
hudsonandres:feature

Conversation

@hudsonandres
Copy link

➜ Added a comprehensive file-based logging system for trades and a preview command to test GUI layouts without requiring a second player account.

General explain:

🆕 Feat 1: File-Based Trade Logging

Implementation

A singleton logger that writes trade events to daily text files using an asynchronous queue system.

Key Features:

  • Daily log files: logs/yyyy-MM-dd.txt format
  • Async processing: Non-blocking writes using BlockingQueue (100 entry buffer)
  • Auto-flush: 1-second intervals to ensure data persistence
  • Graceful shutdown: Flushes remaining queue entries on server stop
  • Configurable filters: Control exactly what gets logged

Log Entry Format:

  • dd/MM/yyyy HH:mm:ss - EVENT_TYPE - Details

Configuration

Added to Config.yml:

TradeLog:
  log-trade-files: false           # Master switch for file logging
  log-filters:                     # Granular control
    log-trade-started: false       # When trade begins
    log-trade-finished: false      # Successful completion
    log-trade-cancelled: false     # Cancellation + reason
    log-items-offered: false       # Item placement events
    log-items-received: false      # Final item distribution

Integration Points

  • TradeLogService: Calls FileTradeLogger.log() for all trade events
  • TradeSystem: Shutdown hook ensures proper queue flushing
  • Works independently from existing database logging

🆕 Feat 2: Preview Command

Implementation

Extends the Trade class to create a single-player preview mode for testing GUI layouts.

How it works:

  • Opens trade GUI for one player only
  • Simulates trade environment without actual trading
  • Prevents normal trade completion
  • Isolated from regular trade flow

Command Usage:
/trade preview

Permission: TradeSystem.Trade.Preview

Technical Details 📊

Performance

  • Async logging: No impact on main server thread
  • Queue buffering: Prevents I/O bottlenecks
  • Scheduled flushing: Batches writes for efficiency

Error Handling

  • Silent failure mode (logged to console only)
  • Queue overflow protection
  • Thread-safe implementation

File Management

  • Automatic date rollover at midnight
  • Creates logs/ directory if missing
  • UTF-8 encoding for international characters

- Added a comprehensive file-based logging system for trades and a preview command to test GUI layouts without requiring a second player account.

## General explain:

🆕 Feat 1: File-Based Trade Logging

### Implementation
A singleton logger that writes trade events to daily text files using an asynchronous queue system.

**Key Features:**
- **Daily log files:** `logs/yyyy-MM-dd.txt` format
- **Async processing:** Non-blocking writes using `BlockingQueue` (100 entry buffer)
- **Auto-flush:** 1-second intervals to ensure data persistence
- **Graceful shutdown:** Flushes remaining queue entries on server stop
- **Configurable filters:** Control exactly what gets logged

**Log Entry Format:**
- dd/MM/yyyy HH:mm:ss - EVENT_TYPE - Details


### Configuration
Added to `Config.yml`:
```yaml
TradeLog:
  log-trade-files: false           # Master switch for file logging
  log-filters:                     # Granular control
    log-trade-started: false       # When trade begins
    log-trade-finished: false      # Successful completion
    log-trade-cancelled: false     # Cancellation + reason
    log-items-offered: false       # Item placement events
    log-items-received: false      # Final item distribution

Integration Points
TradeLogService: Calls FileTradeLogger.log() for all trade events
TradeSystem: Shutdown hook ensures proper queue flushing
Works independently from existing database logging

🆕 Feat 2: Preview Command

### Implementation
Extends the Trade class to create a single-player preview mode for testing GUI layouts.

How it works:

Opens trade GUI for one player only
Simulates trade environment without actual trading
Prevents normal trade completion
Isolated from regular trade flow

Command Usage:
```/trade preview```

Permission: TradeSystem.Trade.Preview

Technical Details 📊
Performance
Async logging: No impact on main server thread
Queue buffering: Prevents I/O bottlenecks
Scheduled flushing: Batches writes for efficiency
Error Handling
Silent failure mode (logged to console only)
Queue overflow protection
Thread-safe implementation
File Management
Automatic date rollover at midnight
Creates logs/ directory if missing
UTF-8 encoding for international characters
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant