Skip to content

Commit 492fed5

Browse files
authored
Merge pull request #1268 from kernelkit/syslog-matching
Syslog Enhancements
2 parents f88ebc9 + 79dd5d2 commit 492fed5

40 files changed

+1623
-123
lines changed

board/common/rootfs/etc/bash.bashrc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ bind "set completion-ignore-case on"
3131
# show all completions immediately instead of ringing bell
3232
bind "set show-all-if-ambiguous on"
3333

34+
export LANG=C.UTF-8
35+
3436
log()
3537
{
3638
local fn="/var/log/syslog"

board/common/rootfs/etc/finit.conf

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
set COLORTERM=yes
2-
rlimit soft core infinity
2+
set LANG=C.UTF-8
3+
rlimit soft core infinity

board/common/rootfs/etc/profile.d/convenience.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ alias la='ls -A'
33
alias ll='ls -alF'
44
alias ls='ls --color=auto'
55

6+
export LANG=C.UTF-8
67
export EDITOR=/usr/bin/edit
78
export VISUAL=/usr/bin/edit
89
export LESS="-P %f (press h for help or q to quit)"

doc/ChangeLog.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,17 @@ All notable changes to the project are documented in this file.
4848
- Add CLI commands for managing boot partition order: `show boot-order` and
4949
`set boot-order` allow viewing and changing the boot order from the CLI,
5050
complementing the existing YANG RPC support, issue #1032
51+
- Extended syslog filtering capabilities, issue #1091:
52+
- Add support for pattern matching using POSIX extended regular expressions
53+
on message content (IETF `select-match` feature)
54+
- Add support for advanced severity comparison: exact match (`equals`) and
55+
exclusion (`block`/`stop`) in addition to the default equals-or-higher
56+
(IETF `select-adv-compare` feature)
57+
- Add support for hostname-based filtering, useful when acting as a log
58+
server to route messages from different devices to separate log files
59+
- Add support for property-based filtering with operators (contains, isequal,
60+
startswith, regex, ereregex) on message properties (msg, msgid, programname,
61+
hostname, source, data), with optional case-insensitive and negate modifiers
5162

5263
### Fixes
5364

doc/syslog.md

Lines changed: 108 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -191,8 +191,114 @@ admin@example:/>
191191
```
192192

193193
See the above [Log to File](#log-to-file) section on how to set up
194-
filtering of received logs to local files. Please note, filtering based
195-
on property, e.g., hostname, is not supported yet.
194+
filtering of received logs to local files. Advanced filtering based
195+
on hostname and message properties is also available, see the next
196+
section for details.
197+
198+
## Advanced Filtering
199+
200+
The syslog subsystem supports several advanced filtering options that
201+
allow fine-grained control over which messages are logged. These can
202+
be combined with facility and severity filters to create sophisticated
203+
logging rules.
204+
205+
### Pattern Matching
206+
207+
Messages can be filtered using regular expressions (POSIX extended regex)
208+
on the message content. This is useful when you want to log only messages
209+
containing specific keywords or patterns:
210+
211+
```
212+
admin@example:/config/> edit syslog actions log-file file:errors
213+
admin@example:/config/syslog/…/file:errors/> set pattern-match "ERROR|CRITICAL|FATAL"
214+
admin@example:/config/syslog/…/file:errors/> set facility-list all severity info
215+
admin@example:/config/syslog/…/file:errors/> leave
216+
admin@example:/>
217+
```
218+
219+
This will log all messages containing ERROR, CRITICAL, or FATAL.
220+
221+
### Advanced Severity Comparison
222+
223+
By default, severity filtering uses "equals-or-higher" comparison,
224+
meaning a severity of `error` will match error, critical, alert, and
225+
emergency messages. You can change this behavior:
226+
227+
```
228+
admin@example:/config/> edit syslog actions log-file file:daemon-errors
229+
admin@example:/config/syslog/…/file:daemon-errors/> set facility-list daemon
230+
admin@example:/config/syslog/…/daemon/> set severity error
231+
admin@example:/config/syslog/…/daemon/> set advanced-compare compare equals
232+
admin@example:/config/syslog/…/daemon/> leave
233+
admin@example:/>
234+
```
235+
236+
This will log only `error` severity messages, not higher severities.
237+
238+
You can also block specific severities:
239+
240+
```
241+
admin@example:/config/syslog/…/daemon/> set advanced-compare action block
242+
```
243+
244+
This will exclude `error` messages from the log.
245+
246+
### Hostname Filtering
247+
248+
When acting as a log server, you can filter messages by hostname. This
249+
is useful for directing logs from different devices to separate files:
250+
251+
```
252+
admin@example:/config/> edit syslog actions log-file file:router1
253+
admin@example:/config/syslog/…/file:router1/> set hostname-filter router1
254+
admin@example:/config/syslog/…/file:router1/> set facility-list all severity info
255+
admin@example:/config/syslog/…/file:router1/> leave
256+
admin@example:/>
257+
```
258+
259+
Multiple hostnames can be added to the filter list.
260+
261+
### Property-Based Filtering
262+
263+
For more advanced filtering, you can match on specific message properties
264+
using various comparison operators:
265+
266+
```
267+
admin@example:/config/> edit syslog actions log-file file:myapp
268+
admin@example:/config/syslog/…/file:myapp/> edit property-filter
269+
admin@example:/config/syslog/…/property-filter/> set property programname
270+
admin@example:/config/syslog/…/property-filter/> set operator isequal
271+
admin@example:/config/syslog/…/property-filter/> set value myapp
272+
admin@example:/config/syslog/…/property-filter/> leave
273+
admin@example:/>
274+
```
275+
276+
Available properties:
277+
- `msg`: Message body
278+
- `msgid`: RFC5424 message identifier
279+
- `programname`: Program/tag name
280+
- `hostname`: Source hostname
281+
- `source`: Alias for hostname
282+
- `data`: RFC5424 structured data
283+
284+
Available operators:
285+
- `contains`: Substring match
286+
- `isequal`: Exact equality
287+
- `startswith`: Prefix match
288+
- `regex`: Basic regular expression
289+
- `ereregex`: Extended regular expression (POSIX ERE)
290+
291+
The comparison can be made case-insensitive:
292+
293+
```
294+
admin@example:/config/syslog/…/property-filter/> set case-insensitive true
295+
```
296+
297+
Or negated to exclude matching messages:
298+
299+
```
300+
admin@example:/config/syslog/…/property-filter/> set negate true
301+
```
196302

197303
### Facilities
198304

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
# -l :: Keep kernel looging to console
1+
# -H :: Log remote messages using hostname from the message
2+
# -l :: Keep kernel logging to console
23
# -m0 :: Disable periodic syslog MARK entries
4+
# -n :: Disable DNS query for every request, trust hostname in message
35
# -s :: Enable secure mode, don't listen to remote logs
46
# -r 1M:5 :: Log rotation every 1 MiB and keep 5 rotated ones
5-
SYSLOGD_ARGS="-l -m0"
7+
SYSLOGD_ARGS="-H -l -m0"

patches/sysklogd/2.7.2/0001-syslogd-fix-UTF-8-handling-with-8-flag-for-RFC5424-c.patch

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
From 31dfe0d16461d2852f3fc56cb82aed3a23db022f Mon Sep 17 00:00:00 2001
22
From: Joachim Wiberg <[email protected]>
33
Date: Thu, 25 Sep 2025 16:48:31 +0200
4-
Subject: [PATCH] syslogd: fix UTF-8 handling with -8 flag, for RFC5424
4+
Subject: [PATCH 1/4] syslogd: fix UTF-8 handling with -8 flag, for RFC5424
55
compliance
66
MIME-Version: 1.0
77
Content-Type: text/plain; charset=UTF-8
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
From f9b6531430c6485af4697a5868a6f43c93d20419 Mon Sep 17 00:00:00 2001
2+
From: Joachim Wiberg <[email protected]>
3+
Date: Fri, 26 Sep 2025 08:42:57 +0200
4+
Subject: [PATCH 2/4] syslogd: fix parentheses handling in RFC 3164 tag parsing
5+
MIME-Version: 1.0
6+
Content-Type: text/plain; charset=UTF-8
7+
Content-Transfer-Encoding: 8bit
8+
Organization: Wires
9+
10+
Some applications use tag names like "(polkit-agent)" which sysklogd do
11+
not handle well. This patch aims to address this and also add a bit of
12+
logic to normalize such tags:
13+
14+
- Allow parentheses in tag character set for broader compatibility
15+
- Smart parsing: strip surrounding parentheses from complete tags like
16+
"(polkit-agent):" → "polkit-agent", while preserving partial parentheses
17+
like "app(version):" unchanged
18+
- Maintain RFC compliance: both RFC3164 and RFC5424 allow parentheses
19+
- Preserve all existing functionality and edge case handling
20+
21+
Fixes #104
22+
23+
Signed-off-by: Joachim Wiberg <[email protected]>
24+
---
25+
src/syslogd.c | 35 ++++++++++++++++++++++++++++-------
26+
1 file changed, 28 insertions(+), 7 deletions(-)
27+
28+
diff --git a/src/syslogd.c b/src/syslogd.c
29+
index fa82d98..37e1920 100644
30+
--- a/src/syslogd.c
31+
+++ b/src/syslogd.c
32+
@@ -1309,15 +1309,36 @@ parsemsg_rfc3164_app_name_procid(char **msg, char **app_name, char **procid)
33+
m = *msg;
34+
35+
/* Application name. */
36+
- app_name_begin = m;
37+
- app_name_length = strspn(m,
38+
- "abcdefghijklmnopqrstuvwxyz"
39+
- "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
40+
- "0123456789"
41+
- "._-/");
42+
+ /* Check if tag is surrounded by parentheses like (polkit-agent) */
43+
+ if (*m == '(') {
44+
+ char *closing = strchr(m + 1, ')');
45+
+ if (closing && (closing[1] == ':' || closing[1] == '[' || isblank(closing[1]) || closing[1] == '\0')) {
46+
+ /* Found complete parenthetical tag, strip parentheses */
47+
+ app_name_begin = m + 1;
48+
+ app_name_length = closing - (m + 1);
49+
+ m = closing + 1;
50+
+ } else {
51+
+ /* Incomplete or malformed, treat normally */
52+
+ app_name_begin = m;
53+
+ app_name_length = strspn(m,
54+
+ "abcdefghijklmnopqrstuvwxyz"
55+
+ "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
56+
+ "0123456789"
57+
+ "._-/()");
58+
+ m += app_name_length;
59+
+ }
60+
+ } else {
61+
+ app_name_begin = m;
62+
+ app_name_length = strspn(m,
63+
+ "abcdefghijklmnopqrstuvwxyz"
64+
+ "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
65+
+ "0123456789"
66+
+ "._-/()");
67+
+ m += app_name_length;
68+
+ }
69+
+
70+
if (app_name_length == 0)
71+
goto bad;
72+
- m += app_name_length;
73+
74+
/* Process identifier (optional). */
75+
if (*m == '[') {
76+
--
77+
2.43.0
78+

0 commit comments

Comments
 (0)