@@ -174,6 +174,16 @@ pub struct JournaldConfig {
174
174
#[ serde( default ) ]
175
175
pub journal_directory : Option < PathBuf > ,
176
176
177
+ /// The [journal namespace][journal-namespace].
178
+ ///
179
+ /// This value is passed to `journalctl` through the [`--namespace` option][journalctl-namespace-option].
180
+ /// If not set, `journalctl` uses the default namespace.
181
+ ///
182
+ /// [journal-namespace]: https://www.freedesktop.org/software/systemd/man/systemd-journald.service.html#Journal%20Namespaces
183
+ /// [journalctl-namespace-option]: https://www.freedesktop.org/software/systemd/man/journalctl.html#--namespace=NAMESPACE
184
+ #[ serde( default ) ]
185
+ pub journal_namespace : Option < String > ,
186
+
177
187
#[ configurable( derived) ]
178
188
#[ serde( default , deserialize_with = "bool_or_struct" ) ]
179
189
acknowledgements : SourceAcknowledgementsConfig ,
@@ -290,6 +300,7 @@ impl Default for JournaldConfig {
290
300
batch_size : default_batch_size ( ) ,
291
301
journalctl_path : None ,
292
302
journal_directory : None ,
303
+ journal_namespace : None ,
293
304
acknowledgements : Default :: default ( ) ,
294
305
remap_priority : false ,
295
306
log_namespace : None ,
@@ -341,6 +352,7 @@ impl SourceConfig for JournaldConfig {
341
352
let starter = StartJournalctl :: new (
342
353
journalctl_path,
343
354
self . journal_directory . clone ( ) ,
355
+ self . journal_namespace . clone ( ) ,
344
356
self . current_boot_only ,
345
357
self . since_now ,
346
358
) ;
@@ -610,6 +622,7 @@ type JournalStream = BoxStream<'static, Result<Bytes, BoxedFramingError>>;
610
622
struct StartJournalctl {
611
623
path : PathBuf ,
612
624
journal_dir : Option < PathBuf > ,
625
+ journal_namespace : Option < String > ,
613
626
current_boot_only : bool ,
614
627
since_now : bool ,
615
628
}
@@ -618,12 +631,14 @@ impl StartJournalctl {
618
631
const fn new (
619
632
path : PathBuf ,
620
633
journal_dir : Option < PathBuf > ,
634
+ journal_namespace : Option < String > ,
621
635
current_boot_only : bool ,
622
636
since_now : bool ,
623
637
) -> Self {
624
638
Self {
625
639
path,
626
640
journal_dir,
641
+ journal_namespace,
627
642
current_boot_only,
628
643
since_now,
629
644
}
@@ -641,6 +656,10 @@ impl StartJournalctl {
641
656
command. arg ( format ! ( "--directory={}" , dir. display( ) ) ) ;
642
657
}
643
658
659
+ if let Some ( namespace) = & self . journal_namespace {
660
+ command. arg ( format ! ( "--namespace={}" , namespace) ) ;
661
+ }
662
+
644
663
if self . current_boot_only {
645
664
command. arg ( "--boot" ) ;
646
665
}
@@ -1400,43 +1419,76 @@ mod tests {
1400
1419
let path = PathBuf :: from ( "journalctl" ) ;
1401
1420
1402
1421
let journal_dir = None ;
1422
+ let journal_namespace = None ;
1403
1423
let current_boot_only = false ;
1404
1424
let cursor = None ;
1405
1425
let since_now = false ;
1406
1426
1407
- let command = create_command ( & path, journal_dir, current_boot_only, since_now, cursor) ;
1427
+ let command = create_command (
1428
+ & path,
1429
+ journal_dir,
1430
+ journal_namespace,
1431
+ current_boot_only,
1432
+ since_now,
1433
+ cursor,
1434
+ ) ;
1408
1435
let cmd_line = format ! ( "{:?}" , command) ;
1409
1436
assert ! ( !cmd_line. contains( "--directory=" ) ) ;
1437
+ assert ! ( !cmd_line. contains( "--namespace=" ) ) ;
1410
1438
assert ! ( !cmd_line. contains( "--boot" ) ) ;
1411
1439
assert ! ( cmd_line. contains( "--since=2000-01-01" ) ) ;
1412
1440
1413
- let since_now = true ;
1414
1441
let journal_dir = None ;
1442
+ let journal_namespace = None ;
1443
+ let since_now = true ;
1415
1444
1416
- let command = create_command ( & path, journal_dir, current_boot_only, since_now, cursor) ;
1445
+ let command = create_command (
1446
+ & path,
1447
+ journal_dir,
1448
+ journal_namespace,
1449
+ current_boot_only,
1450
+ since_now,
1451
+ cursor,
1452
+ ) ;
1417
1453
let cmd_line = format ! ( "{:?}" , command) ;
1418
1454
assert ! ( cmd_line. contains( "--since=now" ) ) ;
1419
1455
1420
1456
let journal_dir = Some ( PathBuf :: from ( "/tmp/journal-dir" ) ) ;
1457
+ let journal_namespace = Some ( String :: from ( "my_namespace" ) ) ;
1421
1458
let current_boot_only = true ;
1422
1459
let cursor = Some ( "2021-01-01" ) ;
1423
1460
1424
- let command = create_command ( & path, journal_dir, current_boot_only, since_now, cursor) ;
1461
+ let command = create_command (
1462
+ & path,
1463
+ journal_dir,
1464
+ journal_namespace,
1465
+ current_boot_only,
1466
+ since_now,
1467
+ cursor,
1468
+ ) ;
1425
1469
let cmd_line = format ! ( "{:?}" , command) ;
1426
1470
assert ! ( cmd_line. contains( "--directory=/tmp/journal-dir" ) ) ;
1471
+ assert ! ( cmd_line. contains( "--namespace=my_namespace" ) ) ;
1427
1472
assert ! ( cmd_line. contains( "--boot" ) ) ;
1428
1473
assert ! ( cmd_line. contains( "--after-cursor=" ) ) ;
1429
1474
}
1430
1475
1431
1476
fn create_command (
1432
1477
path : & Path ,
1433
1478
journal_dir : Option < PathBuf > ,
1479
+ journal_namespace : Option < String > ,
1434
1480
current_boot_only : bool ,
1435
1481
since_now : bool ,
1436
1482
cursor : Option < & str > ,
1437
1483
) -> Command {
1438
- StartJournalctl :: new ( path. into ( ) , journal_dir, current_boot_only, since_now)
1439
- . make_command ( cursor)
1484
+ StartJournalctl :: new (
1485
+ path. into ( ) ,
1486
+ journal_dir,
1487
+ journal_namespace,
1488
+ current_boot_only,
1489
+ since_now,
1490
+ )
1491
+ . make_command ( cursor)
1440
1492
}
1441
1493
1442
1494
fn message ( event : & Event ) -> Value {
0 commit comments