Crates.io | alog |
lib.rs | alog |
version | 0.10.0 |
created_at | 2020-01-05 12:04:10.317803+00 |
updated_at | 2025-09-25 08:42:04.408244+00 |
description | Anonymize 'Combined Log Format' data |
homepage | https://crates.io/crates/alog |
repository | https://codeberg.org/thyrc/alog.git |
max_upload_size | |
id | 195397 |
size | 41,873 |
alog
is a simple log file anonymizer.
In fact by default alog
just replaces the first word on every line of any input stream
with a customizable string.
So "log file anonymizer" might be a bit of an overstatement, but alog
can be used to (very
efficiently) replace the $remote_addr
part in many access log formats, e.g. Nginx' default
combined log format:
log_format combined '$remote_addr - $remote_user [$time_local] '
'"$request" $status $body_bytes_sent '
'"$http_referer" "$http_user_agent"';
By default any parseable $remote_addr
is replaced by it's localhost representation,
Lines without a $remote_addr
part will remain unchanged (but can be skipped).
With version 0.10
With version 0.9
Config:thorough
option was added to replace every occurrence of $remote_addr
in each line.With version 0.7
ASCII whitespace character
s are removed from the beginning of each line by default.With version 0.6
$remote_user
with '-' as well and$remote_addr
.With version 0.3 [features]
where added, so that the library crate won't pull unneeded
dependencies anymore.
To build the alog
command line tool you now have to explicitly add --features
.
cargo build --features alog-cli
or
cargo build --all-features
Run cli-tool with --help
.
./target/release/alog --help
Calling run()
fn main() {
let mut io_conf = alog::IOConfig::default();
let mut conf = alog::Config::default();
io_conf.push_input("/tmp/test.log");
conf.set_ipv4_value("0.0.0.0");
if let Err(e) = alog::run(&conf, &io_conf) {
eprintln!("{}", e);
}
}
or run_raw()
use std::io::Cursor;
fn main() {
let mut buffer = vec![];
if let Err(e) = alog::run_raw(
&alog::Config {
ipv4: "XXX",
..Default::default()
},
Cursor::new(b"8.8.8.8 test line"),
&mut buffer,
) {
eprintln!("{}", e);
}
assert_eq!(buffer, b"XXX test line");
}
Config::authuser
Starting with version 0.6, alog
can replace the $remote_user
field with a hyphen (-
).
This feature works with normal Common/Combined log files, but there are a few quirks to be aware of.
If you set Config::trim
to false
and process malformed logs, the parser slows down
considerably, and the $remote_user
field won’t be removed at all unless a $time_local
field is present.
The $time_local
field must begin with [
followed by a decimal timestamp,
e.g. [10/Oct/2000:13:55:36 -0700]
.
An optimization is applied to improve performance on real‑world logs. Because of this,
any $remote_user
that starts with - [
is left unchanged. For example, in
8.8.8.8 - - [frank] [10/Oct/2000:13:55:36 -0700] GET /apache_pb.gif HTTP/1.0 200 2326
the string “frank” remains “frank”. You can disable this optimization.
alog
began as a simple replacement for a sub‑10‑line Perl script that ran on an old backup
server—nothing fancy, but it gave me a chance to learn the basics of Rust and crates.io.
As of version 0.6, alog
is feature‑complete. It doesn’t have a lot of functionality, but it
performs what it does reliably. In the future I may reuse this crate to implement proper data
anonymization, but for now that’s where it stands.
I’ll continue to fix bugs when (and if) I encounter them, so the project is now passively maintained.