@@ -3,6 +3,7 @@ use log::{self, Log, LogRecord, LogLocation, LogLevelFilter, SetLoggerError};
3
3
use std:: { fmt, io, ptr, result} ;
4
4
use std:: collections:: BTreeMap ;
5
5
use std:: io:: ErrorKind :: InvalidData ;
6
+ use std:: os:: raw:: c_void;
6
7
use ffi:: array_to_iovecs;
7
8
use ffi:: id128:: sd_id128_t;
8
9
use ffi:: journal as ffi;
@@ -152,7 +153,7 @@ impl Journal {
152
153
153
154
/// Read the next record from the journal. Returns `Ok(None)` if there
154
155
/// are no more records to read.
155
- pub fn next_record ( & self ) -> Result < Option < JournalRecord > > {
156
+ pub fn next_record ( & mut self ) -> Result < Option < JournalRecord > > {
156
157
if sd_try ! ( ffi:: sd_journal_next( self . j) ) == 0 {
157
158
return Ok ( None ) ;
158
159
}
@@ -178,7 +179,7 @@ impl Journal {
178
179
179
180
/// Seek to a specific position in journal. On success, returns a cursor
180
181
/// to the current entry.
181
- pub fn seek ( & self , seek : JournalSeek ) -> Result < String > {
182
+ pub fn seek ( & mut self , seek : JournalSeek ) -> Result < String > {
182
183
match seek {
183
184
JournalSeek :: Head => sd_try ! ( ffi:: sd_journal_seek_head( self . j) ) ,
184
185
JournalSeek :: Current => 0 ,
@@ -225,6 +226,38 @@ impl Journal {
225
226
sd_try ! ( ffi:: sd_journal_get_realtime_usec( self . j, & mut timestamp_us) ) ;
226
227
Ok ( system_time_from_realtime_usec ( timestamp_us) )
227
228
}
229
+
230
+ /// Adds a match by which to filter the entries of the journal.
231
+ /// If a match is applied, only entries with this field set will be iterated.
232
+ pub fn match_add < T : Into < Vec < u8 > > > ( & mut self , key : & str , val : T ) -> Result < & mut Journal > {
233
+ let mut filter = Vec :: < u8 > :: from ( key) ;
234
+ filter. push ( '=' as u8 ) ;
235
+ filter. extend ( val. into ( ) ) ;
236
+ let data = filter. as_ptr ( ) as * const c_void ;
237
+ let datalen = filter. len ( ) as size_t ;
238
+ sd_try ! ( ffi:: sd_journal_add_match( self . j, data, datalen) ) ;
239
+ Ok ( self )
240
+ }
241
+
242
+ /// Inserts a disjunction (i.e. logical OR) in the match list.
243
+ pub fn match_or ( & mut self ) -> Result < & mut Journal > {
244
+ sd_try ! ( ffi:: sd_journal_add_disjunction( self . j) ) ;
245
+ Ok ( self )
246
+ }
247
+
248
+ /// Inserts a conjunction (i.e. logical AND) in the match list.
249
+ pub fn match_and ( & mut self ) -> Result < & mut Journal > {
250
+ sd_try ! ( ffi:: sd_journal_add_conjunction( self . j) ) ;
251
+ Ok ( self )
252
+ }
253
+
254
+ /// Flushes all matches, disjunction and conjunction terms.
255
+ /// After this call all filtering is removed and all entries in
256
+ /// the journal will be iterated again.
257
+ pub fn match_flush ( & mut self ) -> Result < & mut Journal > {
258
+ unsafe { ffi:: sd_journal_flush_matches ( self . j ) } ;
259
+ Ok ( self )
260
+ }
228
261
}
229
262
230
263
impl Drop for Journal {
0 commit comments