Otter
Snippets
Otter
Upstream Otter 1.0.1 Tested
Safe Append Line to Log File
Atomically append a text log entry to a file with fallback creation.
Architecture & Runtime Preview
Otter 1.0.1Zero-dependency Otter 1.0.1 snippet (Files & Storage). Copy the parameterized template or run the self-contained example.
- 1Category: Files & Storage
- 2Attribution: Otter Reusable Library (Official)
- 3Zero external pack dependencies — paste directly into any .ot file
Source Code (2 files)
to appendLogEntry path msg
line is msg plus "\n"
try
read path into existing
updated is existing plus line
write updated to path
otherwise into reason
write line to path
.
.
logFilePath is "snippet_audit.log"
to appendLogEntry path msg
line is msg plus "\n"
try
read path into existing
updated is existing plus line
write updated to path
otherwise into reason
write line to path
.
.
appendLogEntry logFilePath "Server starting"
appendLogEntry logFilePath "Ready to receive"
read logFilePath into auditContents
say "Audit log:" auditContents
if not auditContents contains "Server starting"
fail with "append log missing first entry"
.
if not auditContents contains "Ready to receive"
fail with "append log missing second entry"
.
delete file logFilePath
Installation & Usage
otter snippet inspect file-append-log
Copy template.ot directly into your .ot source file, or run example.ot with 'otter run example.ot'.