@@ -11,45 +11,19 @@ pub struct NetworkLogsView {
1111
1212impl NetworkLogsView {
1313 pub fn new ( _window : & mut Window , _cx : & mut Context < Self > ) -> Self {
14- // Add some sample logs for demonstration
15- let mut logs = VecDeque :: new ( ) ;
16-
17- logs. push_back ( LogEntry {
18- timestamp : "2025-11-10 15:00:01" . to_string ( ) ,
19- level : "INFO" . to_string ( ) ,
20- target : "wsrx::daemon" . to_string ( ) ,
21- message : "Daemon started successfully" . to_string ( ) ,
22- } ) ;
23-
24- logs. push_back ( LogEntry {
25- timestamp : "2025-11-10 15:00:05" . to_string ( ) ,
26- level : "DEBUG" . to_string ( ) ,
27- target : "wsrx::tunnel" . to_string ( ) ,
28- message : "Initializing WebSocket connection to ws://example.com" . to_string ( ) ,
29- } ) ;
30-
31- logs. push_back ( LogEntry {
32- timestamp : "2025-11-10 15:00:10" . to_string ( ) ,
33- level : "INFO" . to_string ( ) ,
34- target : "wsrx::tunnel" . to_string ( ) ,
35- message : "Connection established: 127.0.0.1:8080 → ws://example.com" . to_string ( ) ,
36- } ) ;
37-
38- logs. push_back ( LogEntry {
39- timestamp : "2025-11-10 15:00:15" . to_string ( ) ,
40- level : "WARN" . to_string ( ) ,
41- target : "wsrx::proxy" . to_string ( ) ,
42- message : "High latency detected: 250ms" . to_string ( ) ,
43- } ) ;
44-
45- logs. push_back ( LogEntry {
46- timestamp : "2025-11-10 15:00:20" . to_string ( ) ,
47- level : "ERROR" . to_string ( ) ,
48- target : "wsrx::tunnel" . to_string ( ) ,
49- message : "Connection failed: Connection refused" . to_string ( ) ,
50- } ) ;
14+ // Start with empty logs - will be populated from tracing
15+ Self {
16+ logs : VecDeque :: new ( ) ,
17+ }
18+ }
5119
52- Self { logs }
20+ /// Add a log entry (called from RootView when logs are received)
21+ pub fn add_log ( & mut self , entry : LogEntry ) {
22+ // Keep max 1000 logs to prevent memory issues
23+ if self . logs . len ( ) >= 1000 {
24+ self . logs . pop_front ( ) ;
25+ }
26+ self . logs . push_back ( entry) ;
5327 }
5428
5529 fn render_log_entry ( & self , entry : & LogEntry , index : usize ) -> impl IntoElement {
@@ -146,28 +120,6 @@ impl Render for NetworkLogsView {
146120 )
147121 . child (
148122 div ( ) . flex ( ) . gap_2 ( )
149- . child (
150- div ( )
151- . id ( "add-sample-log-button" )
152- . px_3 ( )
153- . py_1 ( )
154- . text_sm ( )
155- . bg ( colors:: accent ( ) )
156- . rounded_md ( )
157- . cursor_pointer ( )
158- . hover ( |div| div. bg ( gpui:: rgba ( 0x0088DDFF ) ) )
159- . on_click ( cx. listener ( |this, _event, _window, cx| {
160- use chrono:: Local ;
161- this. logs . push_back ( LogEntry {
162- timestamp : Local :: now ( ) . format ( "%Y-%m-%d %H:%M:%S" ) . to_string ( ) ,
163- level : "INFO" . to_string ( ) ,
164- target : "wsrx::test" . to_string ( ) ,
165- message : format ! ( "Sample log entry #{}" , this. logs. len( ) + 1 ) ,
166- } ) ;
167- cx. notify ( ) ;
168- } ) )
169- . child ( "Add Sample" ) ,
170- )
171123 . child (
172124 div ( )
173125 . id ( "clear-logs-button" )
@@ -182,7 +134,7 @@ impl Render for NetworkLogsView {
182134 this. logs . clear ( ) ;
183135 cx. notify ( ) ;
184136 } ) )
185- . child ( "Clear" ) ,
137+ . child ( "Clear Logs " ) ,
186138 ) ,
187139 ) ,
188140 )
0 commit comments