Skip to content

Commit 6bef101

Browse files
Copilotlmangani
andcommitted
Update Copilot instructions to recommend logging module over print
Co-authored-by: lmangani <1423657+lmangani@users.noreply.github.com>
1 parent 9f6aee6 commit 6bef101

1 file changed

Lines changed: 14 additions & 3 deletions

File tree

.github/copilot-instructions.md

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,18 @@
5454

5555
#### Error Handling
5656
- Use try-except blocks with specific exception types
57-
- Log errors with context using `print(..., flush=True)` for immediate console output
57+
- Use Python's `logging` module for error logging and diagnostics
58+
- For quick debugging, `print(..., flush=True)` is acceptable but prefer logging
5859
- Return structured error responses in API endpoints:
5960
```python
60-
return jsonify({"error": "Description", "details": str(e)}), 500
61+
import logging
62+
logger = logging.getLogger(__name__)
63+
64+
try:
65+
# ... operation
66+
except Exception as e:
67+
logger.error(f"Operation failed: {e}", exc_info=True)
68+
return jsonify({"error": "Description", "details": str(e)}), 500
6169
```
6270

6371
#### Documentation
@@ -300,8 +308,11 @@ When reviewing code:
300308
```python
301309
from __future__ import annotations
302310
from typing import Dict, Any
311+
import logging
303312
from flask import Blueprint, request, jsonify
304313

314+
logger = logging.getLogger(__name__)
315+
305316
def create_feature_blueprint() -> Blueprint:
306317
"""Create blueprint for new feature."""
307318
bp = Blueprint("feature_name", __name__)
@@ -321,7 +332,7 @@ def create_feature_blueprint() -> Blueprint:
321332
return jsonify({"status": "success", "result": result}), 200
322333

323334
except Exception as e:
324-
print(f"[Feature] Error: {e}", flush=True)
335+
logger.error(f"[Feature] Error: {e}", exc_info=True)
325336
return jsonify({"error": str(e)}), 500
326337

327338
return bp

0 commit comments

Comments
 (0)