Skip to content
Back to skills

Python Logfile Context Manager With Specific Format

ASecurity

Generates a Python class `LogFile` inheriting from `ContextDecorator` to log execution start time, duration, and errors to a file using a strict pipe-delimited format.

  • 611 stars
  • 0 votes
  • 0 copies
  • 0 views
  • Added November 11, 2026
educationpython

Security analysis

A100/100

Scanned November 11, 2026

npx -y skills add ECNU-ICALK/AutoSkill --skill python-logfile-context-manager-with-specific-format --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Python Logfile Context Manager With Specific Format?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Python Logfile Context Manager With Specific Format
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/ecnu-icalk-python-logfile-context-manager-with-specific-forma/badge)](https://www.skillsdirectory.com/skills/ecnu-icalk-python-logfile-context-manager-with-specific-forma)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
id: "3b437934-a6a3-4e40-b9a5-5375b8486065"
name: "Python LogFile Context Manager with Specific Format"
description: "Generates a Python class `LogFile` inheriting from `ContextDecorator` to log execution start time, duration, and errors to a file using a strict pipe-delimited format."
version: "0.1.0"
tags:
  - "python"
  - "context-manager"
  - "logging"
  - "contextdecorator"
  - "code-generation"
triggers:
  - "create a logfile context manager"
  - "python logging context decorator"
  - "log start run error to file"
  - "contextdecorator logfile"
  - "create context manager log file specific format"
---

# Python LogFile Context Manager with Specific Format

Generates a Python class `LogFile` inheriting from `ContextDecorator` to log execution start time, duration, and errors to a file using a strict pipe-delimited format.

## Prompt

# Role & Objective
You are a Python developer. Your task is to implement a context manager class named `LogFile` that inherits from `ContextDecorator`. This class must log the execution details of a code block or function to a specified file.

# Operational Rules & Constraints
1. **Inheritance**: The class must inherit from `contextlib.ContextDecorator`.
2. **Initialization**: Accept `logfile_path` as an argument to specify the output file.
3. **Logging Content**: Every log entry must contain:
   - Start time (labeled "Start:")
   - Execution time/Duration (labeled "Run:")
   - Error information (labeled "An error occurred:")
4. **Output Format**: The log line must strictly follow this pipe-delimited format:
   `Start: {start_timestamp} | Run: {duration} | An error occurred: {error_message}`
5. **Error Handling**:
   - If no error occurs, `{error_message}` must be `None`.
   - If a `ZeroDivisionError` occurs, `{error_message}` must be `division by zero`.
   - For other exceptions, log the exception value.
6. **File Mode**: Open the file in append mode ("a+").

# Anti-Patterns
- Do not use the standard `logging` module configuration; write directly to the file object.
- Do not alter the specific labels ("Start:", "Run:", "An error occurred:") or the pipe separator structure.

## Triggers

- create a logfile context manager
- python logging context decorator
- log start run error to file
- contextdecorator logfile
- create context manager log file specific format

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

View all in education →

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.