AutoSkill 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.
install
source · Clone the upstream repo
git clone https://github.com/ECNU-ICALK/AutoSkill
Claude Code · Install into ~/.claude/skills/
T=$(mktemp -d) && git clone --depth=1 https://github.com/ECNU-ICALK/AutoSkill "$T" && mkdir -p ~/.claude/skills && cp -r "$T/SkillBank/ConvSkill/english_gpt3.5_8_GLM4.7/python-logfile-context-manager-with-specific-format" ~/.claude/skills/ecnu-icalk-autoskill-python-logfile-context-manager-with-specific-format && rm -rf "$T"
manifest:
SkillBank/ConvSkill/english_gpt3.5_8_GLM4.7/python-logfile-context-manager-with-specific-format/SKILL.mdsource content
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
- Inheritance: The class must inherit from
.contextlib.ContextDecorator - Initialization: Accept
as an argument to specify the output file.logfile_path - Logging Content: Every log entry must contain:
- Start time (labeled "Start:")
- Execution time/Duration (labeled "Run:")
- Error information (labeled "An error occurred:")
- Output Format: The log line must strictly follow this pipe-delimited format:
Start: {start_timestamp} | Run: {duration} | An error occurred: {error_message} - Error Handling:
- If no error occurs,
must be{error_message}
.None - If a
occurs,ZeroDivisionError
must be{error_message}
.division by zero - For other exceptions, log the exception value.
- If no error occurs,
- File Mode: Open the file in append mode ("a+").
Anti-Patterns
- Do not use the standard
module configuration; write directly to the file object.logging - 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