Write input to a file with size or line limits.
Project description
logfu
Write streams or files to a bounded file (by size or line count).
logfu provides the log CLI, a small Unix-style utility that acts as a bounded sink: it consumes
data (from stdin or a file), writes it to a file, and guarantees that the file never exceeds a
given size or number of lines, always keeping the most recent content.
Installation
Using pip
logfu can be installed as a regular Python package:
pip install logfu
Single-file installation
It can also be installed as a standalone executable by copying the entry point
to a standard location such as /usr/local/bin:
sudo cp ./log/__main__.py /usr/local/bin/log
sudo chmod +x /usr/local/bin/log
Usage
$ log --help
usage: log [-h] -o OUTPUT [-f] [-s SIZE | -l LINES] [input]
Write streams or files with size or line limits.
positional arguments:
input Input file (defaults to stdin)
options:
-h, --help show this help message and exit
-o, --output OUTPUT Output file path
-f, --follow Read stdin incrementally and keep output bounded
-s, --size SIZE Maximum size (bytes, supports K/M/G/T)
-l, --lines LINES Maximum number of lines
Examples
Keep the last 10MB of a command’s output
some_command | log --size 10M --output app.log
Keep the last 1000 lines of a live stream
journalctl -f | log --follow --lines 1000 --output journal.log
Truncate an existing file in place
log --size 5M --output app.log app.log
Line-based truncation of a text file
log -l 200 -o notes.txt notes.txt
Follow mode (--follow)
When --follow is enabled, log reads from stdin incrementally and updates the output file as new data arrives.
some_long_running_command | log --follow --size 20M --output output.log
Properties:
- streaming (no full buffering)
- bounded memory usage
- atomic file updates
- suitable for long-running pipelines
Note: --follow keeps running until stdin closes or the process is terminated.
Size format
--size accepts human-readable units:
| Suffix | Meaning |
|---|---|
K |
1024 bytes |
M |
1024² bytes |
G |
1024³ bytes |
T |
1024⁴ bytes |
Examples
log --size 512 # Limit to 512 bytes
log --size 10K # Limit to 10 kilobytes
log --size 2M # Limit to 2 megabytes
Atomicity and safety
All writes are performed via a temporary file followed by an atomic rename.
This guarantees that:
- readers never observe partial writes
- in-place truncation is safe
- crashes do not corrupt the output file
Why creating logfu
Unix has excellent tools for reading, selecting, and duplicating data:
tailselects the end of a stream or fileteeduplicates a stream to filestruncatechanges file sizelogrotaterotates files offline
What Unix lacks is a tool that can continuously write data to a file while enforcing bounds on that file.
That gap is exactly what log fills.
What log does that coreutils don’t
tail is a reader, not a writer
tail can select the last N lines or bytes, but it only writes to stdout.
tail -n 100 file.log
It cannot do this:
tail -n 100 file.log > file.log
And it cannot act as a sink in a pipeline.
tee writes, but never limits
some_command | tee app.log
This file grows forever. There is no way to tell tee:
Keep only the last 10MB of what you write.
truncate is blind to content
truncate -s 10M app.log
- works only on files
- truncates from the end
- has no notion of most recent data
- cannot be used on streams
What log provides
log combines the missing pieces into a single, composable primitive:
- consumes
stdinor a file - writes to a file atomically
- enforces limits by:
- raw size (
--size) - number of lines (
--lines)
- raw size (
- always keeps the most recent content
- can run continuously (
--follow)
In other words, log is a bounded sink.
Non-goals
log intentionally does not:
- rotate files
- compress logs
- multiplex outputs
- act as a logging framework
It is a small, sharp Unix tool designed to compose with others.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file logfu-0.1.0.tar.gz.
File metadata
- Download URL: logfu-0.1.0.tar.gz
- Upload date:
- Size: 7.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fdf91b7639b42eae72d15c81d5bc5defb7413adc34035f5b8c0ccdb386e4559d
|
|
| MD5 |
c2213836a50a38035ec25203a5a11a38
|
|
| BLAKE2b-256 |
6da6d95b30141790b1a464a3019a7fd76bbd042ed373c21438865378554839a2
|
Provenance
The following attestation bundles were made for logfu-0.1.0.tar.gz:
Publisher:
ci.yml on sagittarius-a/logfu
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
logfu-0.1.0.tar.gz -
Subject digest:
fdf91b7639b42eae72d15c81d5bc5defb7413adc34035f5b8c0ccdb386e4559d - Sigstore transparency entry: 868921936
- Sigstore integration time:
-
Permalink:
sagittarius-a/logfu@e2562319a31a9f686f629231c6498eb4524b136c -
Branch / Tag:
refs/heads/main - Owner: https://github.com/sagittarius-a
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
ci.yml@e2562319a31a9f686f629231c6498eb4524b136c -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file logfu-0.1.0-py3-none-any.whl.
File metadata
- Download URL: logfu-0.1.0-py3-none-any.whl
- Upload date:
- Size: 7.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fc111f82a0285cf655a50fa737151395e3eb5f0a7c61d762dc50cad2226d4c73
|
|
| MD5 |
125a452eb8529dffe12a3b36acce7f70
|
|
| BLAKE2b-256 |
4530b163ba9cb7165b2bfb8c6081d30468f01c639538656381c9defb4c5b6f65
|
Provenance
The following attestation bundles were made for logfu-0.1.0-py3-none-any.whl:
Publisher:
ci.yml on sagittarius-a/logfu
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
logfu-0.1.0-py3-none-any.whl -
Subject digest:
fc111f82a0285cf655a50fa737151395e3eb5f0a7c61d762dc50cad2226d4c73 - Sigstore transparency entry: 868921938
- Sigstore integration time:
-
Permalink:
sagittarius-a/logfu@e2562319a31a9f686f629231c6498eb4524b136c -
Branch / Tag:
refs/heads/main - Owner: https://github.com/sagittarius-a
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
ci.yml@e2562319a31a9f686f629231c6498eb4524b136c -
Trigger Event:
workflow_dispatch
-
Statement type: