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

View File

@@ -123,8 +123,8 @@ func some_deep_function():
### Debug System Integration
- Always connect to DebugManager signals for debug UI
- Use debug prints with clear prefixes
- Remove debug prints before committing (unless permanently useful)
- Use structured logging instead of plain print statements
- Remove temporary debug logs before committing (unless permanently useful)
```gdscript
# ✅ Correct debug integration
@@ -132,27 +132,47 @@ func _connect_to_global_debug() -> void:
DebugManager.debug_ui_toggled.connect(_on_debug_ui_toggled)
debug_ui.visible = DebugManager.is_debug_ui_visible()
# ✅ Good debug prints
print("Match3: Debug UI toggled to: ", visible)
print("TileSystem: Initialized ", tiles.size(), " tiles")
# ✅ Good structured logging
DebugManager.log_debug("Debug UI toggled to: " + str(visible), "Match3")
DebugManager.log_info("Initialized " + str(tiles.size()) + " tiles", "TileSystem")
# ❌ Bad debug prints
print("test") # Not descriptive
print(some_variable) # No context
# ❌ Bad logging practices
print("test") # Not descriptive, use structured logging
print(some_variable) # No context, use proper log level
```
### Logging Standards
- **ALWAYS** use `DebugManager.log_*()` functions instead of `print()` or `push_error()`
- Choose appropriate log levels based on message importance and audience
- Include meaningful categories to organize log output by system/component
- Format messages with clear, descriptive text and relevant context
```gdscript
# ✅ Correct logging usage
DebugManager.log_info("Game scene loaded successfully", "SceneManager")
DebugManager.log_warn("Audio file not found, using default", "AudioManager")
DebugManager.log_error("Failed to save settings: " + error_message, "Settings")
# ❌ Wrong approaches
print("loaded") # Use DebugManager.log_info() with category
push_error("error") # Use DebugManager.log_error() with context
if debug_mode: print("debug info") # Use DebugManager.log_debug()
```
### Error Handling
- Always check if resources loaded successfully
- Use `push_error()` for critical failures
- Use `DebugManager.log_error()` for critical failures
- Provide fallback behavior when possible
- Include meaningful context in error messages
```gdscript
# ✅ Correct error handling
# ✅ Correct error handling with structured logging
func load_scene(path: String) -> void:
var packed_scene := load(path)
if not packed_scene or not packed_scene is PackedScene:
push_error("Failed to load scene at: %s" % path)
DebugManager.log_error("Failed to load scene at: %s" % path, "SceneLoader")
return
DebugManager.log_info("Successfully loaded scene: %s" % path, "SceneLoader")
get_tree().change_scene_to_packed(packed_scene)
```
@@ -253,10 +273,12 @@ func _process(delta):
```gdscript
# ❌ Don't create separate debug systems
var my_debug_enabled = false
print("debug: " + some_info) # Don't use plain print()
# ✅ Use the global debug system
# ✅ Use the global debug and logging systems
if DebugManager.is_debug_enabled():
show_debug_info()
DebugManager.log_debug("Debug information: " + some_info, "MyComponent")
```
## Learning Resources
@@ -294,4 +316,4 @@ This code of conduct emphasizes:
- **Integration**: Use the project's systems properly
- **Learning**: Continuously improve your skills
Remember: It's better to ask questions and write clear, simple code than to guess and create complex, hard-to-maintain solutions. The goal is to contribute effectively to a codebase that will grow and evolve over time.
Remember: It's better to ask questions and write clear, simple code than to guess and create complex, hard-to-maintain solutions. The goal is to contribute effectively to a codebase that will grow and evolve over time.