extractum-skills / rules
Cursor rule44 starsChanged 10 months agoMITView on GitHub
Logging configuration and usage standards
Where files are headingNew Cursor rule files have more rules about planning and tracking tasks, and fewer about code style.
Of the Cursor rule files we read, the 1,531 first seen in the last six months, against the older ones: the kind of rule that gained most share, and the kind that lost most. About files like this in general, not this one, and an estimate, since a kind is a pattern in the words.
In this repository7 other files it gives its agents.
- .cursor/rules/00-project-overview.mdcCursor rule
- .cursor/rules/05-solution-design.mdcCursor rule
- .cursor/rules/10-python-standards.mdcCursor rule
- .cursor/rules/20-type-annotations.mdcCursor rule
- .cursor/rules/40-docstrings.mdcCursor rule
- .cursor/rules/50-error-handling.mdcCursor rule
- .cursor/rules/60-async-patterns.mdcCursor rule
The file
We split this 30-logging-standards.mdc into the rules it gives an agent
4 rules. About 0 are common, 3 are distinctive, and 1 is very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈3
Distinctive · estimate
This author's own choices. Worth a look.
1
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 13
Use colorlog for colored console output to improve readability:
- Distinctive: line 35
Use a centralized logging setup with both file and console handlers:
- Distinctive: line 78
Use appropriate log levels:
- Distinctive: line 99
Use timestamped log files for traceability:
≈ “Common” is an estimate: at least 1 in 5 of the 3,030 Cursor rule files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
---
description: "Logging configuration and usage standards"
globs:
- "**/*.py"
alwaysApply: false
priority: 10
---
# Logging Standards
## Colored Console Output
Use `colorlog` for colored console output to improve readability:
```python
import colorlog
# Color configuration by log level
LOG_COLORS: dict[str, str] = {
"DEBUG": "cyan",
"INFO": "green",
"WARNING": "yellow",
"ERROR": "red",
"CRITICAL": "red,bg_white",
}
# Console format with color placeholders
LOG_FORMAT_CONSOLE: str = "%(log_color)s%(levelname)s%(reset)s: %(message)s"
```
---
## Logger Configuration
Use a centralized logging setup with both file and console handlers:
```python
LOGGER_NAME: str = "claude_agent"
LOG_ENCODING: str = "utf-8"
LOG_DATE_FORMAT: str = "%Y-%m-%d %H:%M:%S"
LOG_FORMAT_FILE: str = "%(asctime)s - %(levelname)s - %(message)s"
LOG_FORMAT_CONSOLE: str = "%(log_color)s%(levelname)s%(reset)s: %(message)s"
```
---
## Handler Factory Functions
Extract handler creation into reusable functions:
```python
def _create_file_handler(log_file: Path) -> logging.FileHandler:
"""Create and configure file handler for logging."""
handler: logging.FileHandler = logging.FileHandler(
log_file, encoding=LOG_ENCODING
)
handler.setLevel(logging.DEBUG)
handler.setFormatter(
logging.Formatter(LOG_FORMAT_FILE, datefmt=LOG_DATE_FORMAT)
)
return handler
def _create_console_handler() -> logging.StreamHandler:
"""Create and configure colored console handler for logging."""
handler: logging.StreamHandler = logging.StreamHandler(sys.stdout)
handler.setLevel(logging.INFO)
handler.setFormatter(
colorlog.ColoredFormatter(LOG_FORMAT_CONSOLE, log_colors=LOG_COLORS)
)
return handler
```
---
## Log Levels
Use appropriate log levels:
| Level | Use Case |
|-------|----------|
| `DEBUG` | Detailed diagnostic info, internal state |
| `INFO` | General operational messages, progress |
| `WARNING` | Unexpected but handled situations |
| `ERROR` | Errors that prevent normal operation |
| `CRITICAL` | System-wide failures |
```python
logger.debug(f"Working directory: {os.getcwd()}")
logger.info(f"Starting agent with prompt: {prompt[:100]}...")
logger.warning(f"Retrying after failure: {error}")
logger.error(f"Agent execution failed: {e}", exc_info=True)
```
---
## Log File Naming
Use timestamped log files for traceability:
```python
LOGS_DIR_NAME: str = "logs"
LOG_FILE_PREFIX: str = "agent_"
LOG_TIMESTAMP_FORMAT: str = "%Y%m%d_%H%M%S"
# Creates: logs/agent_20251223_213800.log
timestamp: str = datetime.now().strftime(LOG_TIMESTAMP_FORMAT)
log_file: Path = logs_dir / f"{LOG_FILE_PREFIX}{timestamp}.log"
```
---
## Preview Truncation
Truncate long content in logs with constants:
```python
LOG_PREVIEW_LENGTH: int = 200
PROMPT_PREVIEW_LENGTH: int = 100
# ✅ Good - Uses constants
logger.info(f"Assistant: {text_content[:LOG_PREVIEW_LENGTH]}...")
logger.info(f"Prompt: {prompt[:PROMPT_PREVIEW_LENGTH]}...")
# ❌ Bad - Magic numbers
logger.info(f"Assistant: {text_content[:200]}...")
```
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

