agentleFS
extractumioextractumio/extractum-skills/.cursor/rules/30-logging-standards.mdc

extractum-skills / rules

Cursor rule44 starsChanged 10 months agoMITView on GitHub

Logging configuration and usage standards

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
  1. Very specific:

    Use colorlog for colored console output to improve readability:

    line 13
  2. Distinctive:

    Use a centralized logging setup with both file and console handlers:

    line 35
  3. Distinctive:

    Use appropriate log levels:

    line 78
  4. Distinctive:

    Use timestamped log files for traceability:

    line 99

≈ “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.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
30-logging-standards.mdc
---
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]}...")
```

Download now (ZIP)

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
What did you use it for? e.g. Reviewing pull requests in a Rails app

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.