feat: Add file-based trade logging system and preview command#607
Open
hudsonandres wants to merge 1 commit intoerikzimmermann:developfrom
Open
feat: Add file-based trade logging system and preview command#607hudsonandres wants to merge 1 commit intoerikzimmermann:developfrom
hudsonandres wants to merge 1 commit intoerikzimmermann:developfrom
Conversation
- 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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
➜ 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:
logs/yyyy-MM-dd.txtformatBlockingQueue(100 entry buffer)Log Entry Format:
Configuration
Added to
Config.yml:Integration Points
FileTradeLogger.log()for all trade events🆕 Feat 2: Preview Command
Implementation
Extends the
Tradeclass to create a single-player preview mode for testing GUI layouts.How it works:
Command Usage:
/trade previewPermission:
TradeSystem.Trade.PreviewTechnical Details 📊
Performance
Error Handling
File Management