@@ -11,6 +11,7 @@ mod libsdjournal;
1111mod libsdjournal_bindings;
1212mod query;
1313mod query_builder;
14+ mod unit;
1415
1516#[ macro_use]
1617extern crate log;
@@ -23,6 +24,7 @@ use journal_entries::JournalEntries;
2324use libsdjournal:: JournalError ;
2425use serde:: Deserialize ;
2526use tauri:: async_runtime:: Mutex ;
27+ use unit:: Unit ;
2628
2729fn main ( ) {
2830 let env = Env :: default ( )
@@ -41,7 +43,11 @@ fn main() {
4143 info ! ( "Starting journal logger" ) ;
4244 tauri:: Builder :: default ( )
4345 . manage ( Mutex :: new ( j) )
44- . invoke_handler ( tauri:: generate_handler![ get_logs, get_summary] )
46+ . invoke_handler ( tauri:: generate_handler![
47+ get_logs,
48+ get_summary,
49+ get_services
50+ ] )
4551 . run ( tauri:: generate_context!( ) )
4652 . expect ( "error while running tauri application" ) ;
4753}
@@ -54,6 +60,7 @@ pub struct JournalQuery {
5460 limit : u64 ,
5561 quick_search : String ,
5662 reset_position : bool ,
63+ service : String ,
5764}
5865
5966#[ tauri:: command]
@@ -70,6 +77,7 @@ async fn get_logs(
7077 . with_quick_search ( query. quick_search )
7178 . reset_position ( query. reset_position )
7279 . with_priority_above_or_equal_to ( query. priority )
80+ . with_unit ( query. service )
7381 . build ( ) ;
7482
7583 let lock = journal. lock ( ) . await ;
@@ -79,8 +87,14 @@ async fn get_logs(
7987 Ok ( logs)
8088}
8189
90+ #[ derive( Debug , Deserialize ) ]
91+ #[ serde( rename_all = "camelCase" ) ]
92+ pub struct SummaryQuery {
93+ priority : u32 ,
94+ }
95+
8296#[ tauri:: command]
83- async fn get_summary ( query : JournalQuery ) -> Result < JournalEntries , JournalError > {
97+ async fn get_summary ( query : SummaryQuery ) -> Result < JournalEntries , JournalError > {
8498 debug ! ( "Getting summary..." ) ;
8599 let j = Journal :: open (
86100 OpenFlags :: SD_JOURNAL_LOCAL_ONLY
@@ -92,7 +106,7 @@ async fn get_summary(query: JournalQuery) -> Result<JournalEntries, JournalError
92106 let from = Utc :: now ( ) - Duration :: days ( 1 ) ;
93107 let mut qb = QueryBuilder :: default ( ) ;
94108 let q = qb
95- . with_fields ( vec ! [ journal_fields :: SOURCE_REALTIME_TIMESTAMP . into( ) ] )
109+ . with_fields ( vec ! [ "__REALTIME" . into( ) ] )
96110 . with_limit ( 10_000 )
97111 . with_date_from ( from. timestamp_micros ( ) as u64 )
98112 . with_priority_above_or_equal_to ( query. priority )
@@ -103,3 +117,12 @@ async fn get_summary(query: JournalQuery) -> Result<JournalEntries, JournalError
103117
104118 Ok ( logs)
105119}
120+
121+ #[ tauri:: command]
122+ async fn get_services ( ) -> Result < Vec < Unit > , JournalError > {
123+ debug ! ( "Getting services..." ) ;
124+ let services = Journal :: list_services ( ) ;
125+ debug ! ( "found {} services" , services. len( ) ) ;
126+
127+ Ok ( Journal :: list_services ( ) )
128+ }
0 commit comments