CI / test (macos-latest) (push) Canceled after 0s
CI / test (ubuntu-latest) (push) Canceled after 0s
CI / test (windows-latest) (push) Canceled after 0s
CI / release (macos-latest, aarch64-apple-darwin) (push) Canceled after 0s
CI / release (ubuntu-latest, x86_64-unknown-linux-gnu) (push) Canceled after 0s
CI / release (windows-latest, x86_64-pc-windows-msvc) (push) Canceled after 0s
171 lines
4.8 KiB
Rust
171 lines
4.8 KiB
Rust
//! Entry-start detection across common real-world log formats.
|
|
//! Each sample must be detected and must split into the expected entries.
|
|
|
|
use logreadlite::index::{SharedIndex, build};
|
|
use logreadlite::job::{Token, no_notify};
|
|
use logreadlite::pattern::detect;
|
|
use logreadlite::source::{ByteSource, VecSource};
|
|
|
|
fn check(name: &str, text: &str, expect_pattern: &str, expect_entries: usize) {
|
|
let det = detect(text.as_bytes(), &[]);
|
|
assert_eq!(det.chosen.name, expect_pattern, "{name}: chose {:?}", det.chosen);
|
|
let src = VecSource(text.as_bytes().to_vec());
|
|
let shared = SharedIndex::new(src.len());
|
|
build(&src, &det.chosen.compile().unwrap(), &shared, &Token::detached(), &no_notify());
|
|
let n = shared.index.read().unwrap().len();
|
|
assert_eq!(n, expect_entries, "{name}: {n} entries");
|
|
}
|
|
|
|
#[test]
|
|
fn java_logback_with_stack_traces() {
|
|
check(
|
|
"logback",
|
|
"2026-10-21 05:06:48,123 INFO [main] c.e.App - Starting\n\
|
|
2026-10-21 05:06:49,001 ERROR [http-1] c.e.Api - Request failed\n\
|
|
java.lang.NullPointerException: null\n\
|
|
\tat com.example.Api.handle(Api.java:42)\n\
|
|
\tat com.example.Server.run(Server.java:7)\n\
|
|
Caused by: java.io.IOException: reset\n\
|
|
\t... 3 more\n\
|
|
2026-10-21 05:06:50,000 INFO [main] c.e.App - Done\n",
|
|
"ISO 8601 timestamp",
|
|
3,
|
|
);
|
|
}
|
|
|
|
#[test]
|
|
fn bracketed_iso() {
|
|
check(
|
|
"bracketed",
|
|
"[2026-10-21T05:06:48.123Z] info: a\n[2026-10-21T05:06:49.000Z] warn: b\n detail\n",
|
|
"ISO 8601 timestamp",
|
|
2,
|
|
);
|
|
}
|
|
|
|
#[test]
|
|
fn syslog() {
|
|
check(
|
|
"syslog",
|
|
"Oct 21 05:06:48 host sshd[42]: Accepted key\nOct 21 05:06:49 host CRON[7]: job\nOct 1 05:06:50 host kernel: x\n",
|
|
"Syslog",
|
|
3,
|
|
);
|
|
}
|
|
|
|
#[test]
|
|
fn nginx_access() {
|
|
check(
|
|
"nginx",
|
|
"10.0.0.1 - - [21/Oct/2026:05:06:48 +0000] \"GET / HTTP/1.1\" 200 612 \"-\" \"curl\"\n\
|
|
10.0.0.2 - alice [21/Oct/2026:05:06:49 +0000] \"POST /api HTTP/1.1\" 201 12 \"-\" \"x\"\n",
|
|
"Apache / nginx access",
|
|
2,
|
|
);
|
|
}
|
|
|
|
#[test]
|
|
fn dotnet_slash_date_with_exception() {
|
|
check(
|
|
".NET",
|
|
"10/21/2026 5:06:48 AM Information: Service started\n\
|
|
10/21/2026 5:06:49 AM Error: Unhandled exception\n\
|
|
System.InvalidOperationException: Sequence contains no elements\n \
|
|
at System.Linq.Enumerable.First[TSource](IEnumerable`1 source)\n \
|
|
at App.Program.Main(String[] args) in C:\\src\\Program.cs:line 12\n\
|
|
10/21/2026 5:06:50 AM Information: Recovered\n",
|
|
"Slash date",
|
|
3,
|
|
);
|
|
}
|
|
|
|
#[test]
|
|
fn time_only() {
|
|
check(
|
|
"time only",
|
|
"05:06:48.123 [main] INFO start\n05:06:49.001 [main] WARN slow\n at x\n05:06:50.000 [main] INFO ok\n",
|
|
"Time only",
|
|
3,
|
|
);
|
|
}
|
|
|
|
#[test]
|
|
fn level_first() {
|
|
check(
|
|
"level first",
|
|
"INFO [db] connected\nERROR [db] connection lost\n retrying\nWARN [db] slow query\n",
|
|
"Level first",
|
|
3,
|
|
);
|
|
}
|
|
|
|
#[test]
|
|
fn epoch_seconds() {
|
|
check(
|
|
"epoch",
|
|
"1792472808.123 worker started\n1792472809.456 job 1 done\n1792472810 job 2 done\n",
|
|
"Epoch seconds",
|
|
3,
|
|
);
|
|
}
|
|
|
|
#[test]
|
|
fn json_lines() {
|
|
check(
|
|
"json",
|
|
"{\"ts\":\"2026-10-21T05:06:48Z\",\"level\":\"info\",\"msg\":\"a\"}\n\
|
|
{\"ts\":\"2026-10-21T05:06:49Z\",\"level\":\"error\",\"msg\":\"b\"}\n",
|
|
"JSON lines",
|
|
2,
|
|
);
|
|
}
|
|
|
|
#[test]
|
|
fn go_log_package_by_shape() {
|
|
check(
|
|
"go",
|
|
"2026/10/21 05:06:48 server listening on :8080\n\
|
|
2026/10/21 05:06:49 http: panic serving 1.2.3.4: boom\n\
|
|
goroutine 7 [running]:\n\
|
|
main.handler()\n\
|
|
\t/src/main.go:12 +0x1d\n\
|
|
2026/10/21 05:06:50 shutting down\n",
|
|
"Inferred from line shapes",
|
|
3,
|
|
);
|
|
}
|
|
|
|
#[test]
|
|
fn rails_logger_by_shape() {
|
|
check(
|
|
"rails",
|
|
"I, [2026-10-21T05:06:48.123456 #4242] INFO -- : Started GET \"/\"\n\
|
|
E, [2026-10-21T05:06:49.000001 #4242] ERROR -- : boom\n\
|
|
app/models/user.rb:12:in `save'\n\
|
|
I, [2026-10-21T05:06:50.000002 #4242] INFO -- : Completed 200\n",
|
|
"Inferred from line shapes",
|
|
3,
|
|
);
|
|
}
|
|
|
|
#[test]
|
|
fn python_traceback() {
|
|
check(
|
|
"python",
|
|
"2026-10-21 05:06:48,123 - app - INFO - start\n\
|
|
2026-10-21 05:06:49,000 - app - ERROR - failed\n\
|
|
Traceback (most recent call last):\n \
|
|
File \"app.py\", line 3, in <module>\n \
|
|
main()\n\
|
|
ValueError: bad\n\
|
|
2026-10-21 05:06:50,000 - app - INFO - end\n",
|
|
"ISO 8601 timestamp",
|
|
3,
|
|
);
|
|
}
|
|
|
|
#[test]
|
|
fn plain_text_falls_back_to_non_indented() {
|
|
check("plain", "first thing\n indented detail\nsecond thing\n", "Every line not starting with whitespace", 2);
|
|
}
|