Skip to content

Commit 8ec919c

Browse files
finish tracing logging integration
1 parent bdb562e commit 8ec919c

File tree

3 files changed

+40
-80
lines changed

3 files changed

+40
-80
lines changed

crates/djls-dev/src/bin/djls-tmux.rs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,19 +36,23 @@ fn main() -> Result<()> {
3636
)?;
3737

3838
// Split the right pane horizontally for server logs (50/50 split)
39+
// Updated to handle dated log files properly
3940
writeln!(
4041
stdin,
41-
"split-window -t djls-debug:0.1 -v -p 50 'tail -f /tmp/djls.log'"
42+
r#"split-window -t djls-debug:0.1 -v -p 50 'bash -c "log=\$(ls -t /tmp/djls.log.* 2>/dev/null | head -1); if [ -z \"\$log\" ]; then echo \"Waiting for server logs...\"; while [ -z \"\$log\" ]; do sleep 1; log=\$(ls -t /tmp/djls.log.* 2>/dev/null | head -1); done; fi; echo \"Tailing \$log\"; tail -F \"\$log\""'"#
4243
)?;
4344

4445
// Set pane titles
4546
writeln!(stdin, "select-pane -t djls-debug:0.0 -T 'Editor'")?;
46-
writeln!(stdin, "select-pane -t djls-debug:0.1 -T 'LSP DevTools'")?;
47+
writeln!(stdin, "select-pane -t djls-debug:0.1 -T 'LSP Messages'")?;
4748
writeln!(stdin, "select-pane -t djls-debug:0.2 -T 'Server Logs'")?;
4849

4950
// Enable pane borders with titles at the top
5051
writeln!(stdin, "set -t djls-debug pane-border-status top")?;
5152

53+
// Enable mouse support for scrolling and pane interaction
54+
writeln!(stdin, "set -t djls-debug mouse on")?;
55+
5256
// Add custom keybind to kill session (capital K)
5357
writeln!(stdin, "bind-key K kill-session")?;
5458

@@ -64,9 +68,9 @@ fn main() -> Result<()> {
6468
writeln!(stdin, "set -t djls-debug status-left '[#S] '")?;
6569
writeln!(stdin, "set -t djls-debug status-left-length 20")?;
6670

67-
// Right side: keybind hints
68-
writeln!(stdin, "set -t djls-debug status-right ' C-b d: detach | C-b K: kill session | C-b x: kill pane | C-b z: zoom | C-b ?: help '")?;
69-
writeln!(stdin, "set -t djls-debug status-right-length 90")?;
71+
// Right side: keybind hints - updated to include mouse info
72+
writeln!(stdin, "set -t djls-debug status-right ' Mouse: scroll/click | C-b d: detach | C-b K: kill | C-b x: kill pane | C-b z: zoom | C-b ?: help '")?;
73+
writeln!(stdin, "set -t djls-debug status-right-length 120")?;
7074

7175
// Center: window name
7276
writeln!(stdin, "set -t djls-debug status-justify centre")?;

crates/djls-server/src/logging.rs

Lines changed: 14 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
//! Logging infrastructure bridging tracing events to LSP client messages.
1+
//! Logging infrastructure for forwarding tracing events to LSP client messages.
22
//!
3-
//! This module provides both temporary dual-dispatch macros and the permanent
4-
//! `LspLayer` implementation for forwarding tracing events to the LSP client.
3+
//! This module provides the `LspLayer` implementation for forwarding tracing
4+
//! events to the LSP client through the tracing infrastructure.
55
//!
66
//! ## `LspLayer`
77
//!
@@ -10,34 +10,25 @@
1010
//! - ERROR, WARN, INFO, DEBUG → forwarded to LSP client
1111
//! - TRACE → kept server-side only (for performance)
1212
//!
13-
//! ## Temporary Macros
13+
//! ## Usage
1414
//!
15-
//! These macros bridge the gap during our migration from `client::log_message`
16-
//! to the tracing infrastructure. They ensure messages are sent to both systems
17-
//! so we maintain LSP client visibility while building out tracing support.
15+
//! Use standard tracing macros throughout the codebase:
1816
//!
19-
//! Each macro supports two invocation patterns to handle the different APIs:
20-
//!
21-
//! 1. String literal:
2217
//! ```rust,ignore
23-
//! log_info!("Server initialized");
24-
//! log_warn!("Configuration not found");
25-
//! log_error!("Failed to parse document");
18+
//! tracing::info!("Server initialized");
19+
//! tracing::warn!("Configuration not found");
20+
//! tracing::error!("Failed to parse document");
2621
//! ```
2722
//!
28-
//! 2. Format string with arguments:
23+
//! For formatted messages:
2924
//! ```rust,ignore
30-
//! log_info!("Processing {} documents", count);
31-
//! log_warn!("Timeout after {}ms for {}", ms, path);
32-
//! log_error!("Failed to open {}: {}", file, err);
25+
//! tracing::info!("Processing {} documents", count);
26+
//! tracing::warn!("Timeout after {}ms for {}", ms, path);
27+
//! tracing::error!("Failed to open {}: {}", file, err);
3328
//! ```
3429
//!
35-
//! The difference in the macro arms exists because of how each system works:
36-
//!
37-
//! - `client::log_message` expects a single string value
38-
//! - `tracing` macros can handle format strings natively for structured logging
39-
//! - For format strings, we format once for the client but pass the original
40-
//! format string and args to tracing to preserve structured data
30+
//! The `LspLayer` automatically handles forwarding appropriate log levels
31+
//! to the LSP client while preserving structured logging data for file output.
4132
4233
use std::sync::Arc;
4334

@@ -163,38 +154,4 @@ where
163154
guard
164155
}
165156

166-
#[macro_export]
167-
macro_rules! log_info {
168-
($msg:literal) => {
169-
$crate::client::log_message(tower_lsp_server::lsp_types::MessageType::INFO, $msg);
170-
tracing::info!($msg);
171-
};
172-
($fmt:literal, $($arg:tt)*) => {
173-
$crate::client::log_message(tower_lsp_server::lsp_types::MessageType::INFO, format!($fmt, $($arg)*));
174-
tracing::info!($fmt, $($arg)*);
175-
};
176-
}
177-
178-
#[macro_export]
179-
macro_rules! log_warn {
180-
($msg:literal) => {
181-
$crate::client::log_message(tower_lsp_server::lsp_types::MessageType::WARNING, $msg);
182-
tracing::warn!($msg);
183-
};
184-
($fmt:literal, $($arg:tt)*) => {
185-
$crate::client::log_message(tower_lsp_server::lsp_types::MessageType::WARNING, format!($fmt, $($arg)*));
186-
tracing::warn!($fmt, $($arg)*);
187-
};
188-
}
189157

190-
#[macro_export]
191-
macro_rules! log_error {
192-
($msg:literal) => {
193-
$crate::client::log_message(tower_lsp_server::lsp_types::MessageType::ERROR, $msg);
194-
tracing::error!($msg);
195-
};
196-
($fmt:literal, $($arg:tt)*) => {
197-
$crate::client::log_message(tower_lsp_server::lsp_types::MessageType::ERROR, format!($fmt, $($arg)*));
198-
tracing::error!($fmt, $($arg)*);
199-
};
200-
}

crates/djls-server/src/server.rs

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@ use tower_lsp_server::lsp_types::WorkspaceServerCapabilities;
2525
use tower_lsp_server::LanguageServer;
2626
use tracing_appender::non_blocking::WorkerGuard;
2727

28-
use crate::log_error;
29-
use crate::log_info;
28+
3029
use crate::queue::Queue;
3130
use crate::session::Session;
3231

@@ -58,7 +57,7 @@ impl DjangoLanguageServer {
5857
if let Some(s) = &*session {
5958
f(s)
6059
} else {
61-
log_error!("Attempted to access session before initialization");
60+
tracing::error!("Attempted to access session before initialization");
6261
R::default()
6362
}
6463
}
@@ -72,7 +71,7 @@ impl DjangoLanguageServer {
7271
if let Some(s) = &mut *session {
7372
f(s)
7473
} else {
75-
log_error!("Attempted to access session before initialization");
74+
tracing::error!("Attempted to access session before initialization");
7675
R::default()
7776
}
7877
}
@@ -85,16 +84,16 @@ impl DjangoLanguageServer {
8584
let session_arc = Arc::clone(&self.session);
8685

8786
if let Err(e) = self.queue.submit(async move { f(session_arc).await }).await {
88-
log_error!("Failed to submit task: {}", e);
87+
tracing::error!("Failed to submit task: {}", e);
8988
} else {
90-
log_info!("Task submitted successfully");
89+
tracing::info!("Task submitted successfully");
9190
}
9291
}
9392
}
9493

9594
impl LanguageServer for DjangoLanguageServer {
9695
async fn initialize(&self, params: InitializeParams) -> LspResult<InitializeResult> {
97-
log_info!("Initializing server...");
96+
tracing::info!("Initializing server...");
9897

9998
let session = Session::new(&params);
10099

@@ -142,7 +141,7 @@ impl LanguageServer for DjangoLanguageServer {
142141

143142
#[allow(clippy::too_many_lines)]
144143
async fn initialized(&self, _params: InitializedParams) {
145-
log_info!("Server received initialized notification.");
144+
tracing::info!("Server received initialized notification.");
146145

147146
self.with_session_task(|session_arc| async move {
148147
let project_path_and_venv = {
@@ -162,13 +161,13 @@ impl LanguageServer for DjangoLanguageServer {
162161
};
163162

164163
if let Some((path_display, venv_path)) = project_path_and_venv {
165-
log_info!(
164+
tracing::info!(
166165
"Task: Starting initialization for project at: {}",
167166
path_display
168167
);
169168

170169
if let Some(ref path) = venv_path {
171-
log_info!("Using virtual environment from config: {}", path);
170+
tracing::info!("Using virtual environment from config: {}", path);
172171
}
173172

174173
let init_result = {
@@ -188,10 +187,10 @@ impl LanguageServer for DjangoLanguageServer {
188187

189188
match init_result {
190189
Ok(()) => {
191-
log_info!("Task: Successfully initialized project: {}", path_display);
190+
tracing::info!("Task: Successfully initialized project: {}", path_display);
192191
}
193192
Err(e) => {
194-
log_error!(
193+
tracing::error!(
195194
"Task: Failed to initialize Django project at {}: {}",
196195
path_display,
197196
e
@@ -205,7 +204,7 @@ impl LanguageServer for DjangoLanguageServer {
205204
}
206205
}
207206
} else {
208-
log_info!("Task: No project instance found to initialize.");
207+
tracing::info!("Task: No project instance found to initialize.");
209208
}
210209
Ok(())
211210
})
@@ -217,7 +216,7 @@ impl LanguageServer for DjangoLanguageServer {
217216
}
218217

219218
async fn did_open(&self, params: DidOpenTextDocumentParams) {
220-
log_info!("Opened document: {:?}", params.text_document.uri);
219+
tracing::info!("Opened document: {:?}", params.text_document.uri);
221220

222221
self.with_session_mut(|session| {
223222
let db = session.db();
@@ -227,7 +226,7 @@ impl LanguageServer for DjangoLanguageServer {
227226
}
228227

229228
async fn did_change(&self, params: DidChangeTextDocumentParams) {
230-
log_info!("Changed document: {:?}", params.text_document.uri);
229+
tracing::info!("Changed document: {:?}", params.text_document.uri);
231230

232231
self.with_session_mut(|session| {
233232
let db = session.db();
@@ -237,7 +236,7 @@ impl LanguageServer for DjangoLanguageServer {
237236
}
238237

239238
async fn did_close(&self, params: DidCloseTextDocumentParams) {
240-
log_info!("Closed document: {:?}", params.text_document.uri);
239+
tracing::info!("Closed document: {:?}", params.text_document.uri);
241240

242241
self.with_session_mut(|session| {
243242
session.documents_mut().handle_did_close(&params);
@@ -265,7 +264,7 @@ impl LanguageServer for DjangoLanguageServer {
265264
}
266265

267266
async fn did_change_configuration(&self, _params: DidChangeConfigurationParams) {
268-
log_info!("Configuration change detected. Reloading settings...");
267+
tracing::info!("Configuration change detected. Reloading settings...");
269268

270269
let project_path = self
271270
.with_session(|session| session.project().map(|p| p.path().to_path_buf()))
@@ -277,7 +276,7 @@ impl LanguageServer for DjangoLanguageServer {
277276
session.set_settings(new_settings);
278277
}
279278
Err(e) => {
280-
log_error!("Error loading settings: {}", e);
279+
tracing::error!("Error loading settings: {}", e);
281280
}
282281
})
283282
.await;

0 commit comments

Comments
 (0)