| name | timestamped-log-appender |
| description | Appends a timestamped sequenced line to a log file with idempotency protection. Reads the current log.txt file, determines the next sequence number, generates an ISO timestamp, and appends a formatted line in the pattern sequence | timestamp | OK. Uses sequence numbers as idempotency keys to prevent duplicate writes. Use this skill when you need to add sequential log entries with timestamps to log.txt, ensuring no duplicate entries are created even if the operation is run multiple times. |
Timestamped Log Appender
Append a timestamped, sequenced line to a log file with built-in idempotency protection.
Overview
This skill manages sequential log entries in a log.txt file. Each entry contains a sequence number, ISO timestamp, and status indicator. The skill prevents duplicate entries by checking existing sequence numbers before writing.
Output Format
Each log line follows this format:
{sequence} | {timestamp} | OK
Example:
1 | 2024-01-15T10:30:45.123Z | OK
2 | 2024-01-15T10:31:12.456Z | OK
3 | 2024-01-15T10:32:03.789Z | OK
Process
Step 1: Read Current Log File
Check if log.txt exists and read its contents to understand the current state.
Use the Read tool to access log.txt. If the file doesn't exist, treat it as an empty log with no existing entries.
Step 2: Determine Next Sequence Number
Count the existing lines in the log file to calculate the next sequence number.
Split the file contents by newlines and count non-empty lines. The next sequence number equals the line count plus one. For an empty or non-existent file, start with sequence number 1.
Step 3: Check for Existing Sequence
Verify that the target sequence number doesn't already exist in the log file.
Parse each existing line to extract the sequence number (the first part before the first pipe character). If the target sequence number already exists, skip the write operation to maintain idempotency.
Step 4: Generate ISO Timestamp
Create a current ISO 8601 timestamp for the log entry.
Generate the timestamp in the format YYYY-MM-DDTHH:mm:ss.sssZ using the current UTC time.
Step 5: Format Log Line
Construct the new log line using the determined sequence number, generated timestamp, and OK status.
Combine the components with the pipe separator format: {sequence} | {timestamp} | OK
Step 6: Append to Log File
Write the new line to log.txt if the sequence number doesn't already exist.
Use the Write tool to append the formatted line to log.txt. Add a newline character at the end. If this is the first entry and the file doesn't exist, create the file with the new entry.
Idempotency Behavior
The skill uses sequence numbers as idempotency keys. If a sequence number already exists in the log file, the operation completes without writing, preventing duplicate entries.
This protection allows the skill to be run multiple times safely without creating duplicate log entries, even in concurrent or retry scenarios.
Error Handling
- Handle missing log.txt files by treating them as empty logs
- Skip malformed lines when parsing existing sequence numbers
- Ensure proper newline formatting for cross-platform compatibility
- Validate timestamp generation before writing
Dependencies
Tools Required
- Read: Access log.txt file contents
- Write: Append new entries to log.txt
File Requirements
- log.txt: Target log file (created if it doesn't exist)
Usage Examples
First log entry:
1 | 2024-01-15T10:30:45.123Z | OK
Subsequent entries:
1 | 2024-01-15T10:30:45.123Z | OK
2 | 2024-01-15T10:31:12.456Z | OK
3 | 2024-01-15T10:32:03.789Z | OK
Idempotent behavior:
Running the skill multiple times in quick succession will only add one entry, as subsequent runs detect the existing sequence number and skip the write operation.