add logging

This commit is contained in:
2025-09-24 11:04:16 +04:00
committed by nett00n
parent 7182c45351
commit 83cc433c2f
14 changed files with 515 additions and 42 deletions

106
tests/test_logging.gd Normal file
View File

@@ -0,0 +1,106 @@
extends Node
# Test script for the DebugManager logging system
# This script validates all log levels, filtering, and formatting functionality
# Usage: Add to scene or autoload temporarily to run tests
func _ready():
# Wait a frame for DebugManager to initialize
await get_tree().process_frame
test_logging_system()
func test_logging_system():
print("=== Starting Logging System Tests ===")
# Test 1: Basic log level functionality
test_basic_logging()
# Test 2: Log level filtering
test_log_level_filtering()
# Test 3: Category functionality
test_category_logging()
# Test 4: Debug mode integration
test_debug_mode_integration()
print("=== Logging System Tests Complete ===")
func test_basic_logging():
print("\n--- Test 1: Basic Log Level Functionality ---")
# Reset to INFO level for consistent testing
DebugManager.set_log_level(DebugManager.LogLevel.INFO)
DebugManager.log_trace("TRACE: This should not appear (below INFO level)")
DebugManager.log_debug("DEBUG: This should not appear (below INFO level)")
DebugManager.log_info("INFO: This message should appear")
DebugManager.log_warn("WARN: This warning should appear")
DebugManager.log_error("ERROR: This error should appear")
DebugManager.log_fatal("FATAL: This fatal error should appear")
func test_log_level_filtering():
print("\n--- Test 2: Log Level Filtering ---")
# Test DEBUG level
print("Setting log level to DEBUG...")
DebugManager.set_log_level(DebugManager.LogLevel.DEBUG)
DebugManager.log_trace("TRACE: Should not appear (below DEBUG)")
DebugManager.log_debug("DEBUG: Should appear with debug enabled")
DebugManager.log_info("INFO: Should appear")
# Test ERROR level (very restrictive)
print("Setting log level to ERROR...")
DebugManager.set_log_level(DebugManager.LogLevel.ERROR)
DebugManager.log_debug("DEBUG: Should not appear (below ERROR)")
DebugManager.log_warn("WARN: Should not appear (below ERROR)")
DebugManager.log_error("ERROR: Should appear")
DebugManager.log_fatal("FATAL: Should appear")
# Reset to INFO for remaining tests
DebugManager.set_log_level(DebugManager.LogLevel.INFO)
func test_category_logging():
print("\n--- Test 3: Category Functionality ---")
DebugManager.log_info("Message without category")
DebugManager.log_info("Message with TEST category", "TEST")
DebugManager.log_info("Message with LOGGING category", "LOGGING")
DebugManager.log_warn("Warning with VALIDATION category", "VALIDATION")
DebugManager.log_error("Error with SYSTEM category", "SYSTEM")
func test_debug_mode_integration():
print("\n--- Test 4: Debug Mode Integration ---")
# Set to TRACE level to test debug mode dependency
DebugManager.set_log_level(DebugManager.LogLevel.TRACE)
var original_debug_state = DebugManager.is_debug_enabled()
# Test with debug mode OFF
DebugManager.set_debug_enabled(false)
print("Debug mode OFF - TRACE and DEBUG should not appear:")
DebugManager.log_trace("TRACE: Should NOT appear (debug mode OFF)")
DebugManager.log_debug("DEBUG: Should NOT appear (debug mode OFF)")
DebugManager.log_info("INFO: Should appear regardless of debug mode")
# Test with debug mode ON
DebugManager.set_debug_enabled(true)
print("Debug mode ON - TRACE and DEBUG should appear:")
DebugManager.log_trace("TRACE: Should appear (debug mode ON)")
DebugManager.log_debug("DEBUG: Should appear (debug mode ON)")
DebugManager.log_info("INFO: Should still appear")
# Restore original debug state
DebugManager.set_debug_enabled(original_debug_state)
DebugManager.set_log_level(DebugManager.LogLevel.INFO)
# Helper function to validate log level enum values
func test_log_level_enum():
print("\n--- Log Level Enum Values ---")
print("TRACE: ", DebugManager.LogLevel.TRACE)
print("DEBUG: ", DebugManager.LogLevel.DEBUG)
print("INFO: ", DebugManager.LogLevel.INFO)
print("WARN: ", DebugManager.LogLevel.WARN)
print("ERROR: ", DebugManager.LogLevel.ERROR)
print("FATAL: ", DebugManager.LogLevel.FATAL)