-
Notifications
You must be signed in to change notification settings - Fork 124
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
To make it possible to understand that something got discarded, print a message saying so inside when `WAYLAND_DEBUG` is enabled. This also changes how timestamps are computed for `WAYLAND_DEBUG` log so they align with `libwayland-client` to look into logs using both at the same time more accessible. The `[rs]` particle was added to the log to give a hint which library was used, which could be helpful when looking into random logs.
- Loading branch information
Showing
7 changed files
with
55 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,11 @@ use std::{ | |
|
||
use crate::protocol::Argument; | ||
|
||
/// The `WAYLAND_DEBUG` env variable is set to debug client. | ||
pub fn has_debug_client_env() -> bool { | ||
matches!(std::env::var_os("WAYLAND_DEBUG"), Some(str) if str == "1" || str == "client") | ||
} | ||
|
||
/// Print the dispatched message to stderr in a following format: | ||
/// | ||
/// [timestamp] <- [email protected]_name(args) | ||
|
@@ -36,11 +41,16 @@ pub fn print_send_message<Id: Display, Fd: AsRawFd>( | |
id: u32, | ||
msg_name: &str, | ||
args: &[Argument<Id, Fd>], | ||
discarded: bool, | ||
) { | ||
// Add timestamp to output. | ||
print_timestamp(); | ||
|
||
eprint!(" -> {}@{}.{} ({})", interface, id, msg_name, DisplaySlice(args)); | ||
if discarded { | ||
eprint!("[discarded]"); | ||
} | ||
|
||
eprint!(" -> {}@{}.{}({})", interface, id, msg_name, DisplaySlice(args)); | ||
|
||
// Add a new line. | ||
eprintln!(); | ||
|
@@ -66,8 +76,10 @@ impl<'a, D: Display> Display for DisplaySlice<'a, D> { | |
#[cfg_attr(coverage, coverage(off))] | ||
fn print_timestamp() { | ||
if let Ok(timestamp) = SystemTime::now().duration_since(UNIX_EPOCH) { | ||
let sc = timestamp.as_secs(); | ||
let ms = timestamp.subsec_micros(); | ||
eprint!("[{}.{:06}]", sc, ms); | ||
// NOTE this is all to make timestamps the same with libwayland, so the log doesn't look | ||
// out of place when sys tries to log on their own. | ||
let time = (timestamp.as_secs() * 1000000 + timestamp.subsec_nanos() as u64 / 1000) as u32; | ||
// NOTE annotate timestamp so we know which library emmited the log entry. | ||
eprint!("[{:7}.{:03}][rs]", time / 1000, time % 1000); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -91,6 +91,7 @@ pub use sys::server; | |
mod test; | ||
|
||
mod core_interfaces; | ||
mod debug; | ||
pub mod protocol; | ||
mod types; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,6 @@ | |
mod client_impl; | ||
mod server_impl; | ||
|
||
mod debug; | ||
mod map; | ||
pub(crate) mod socket; | ||
mod wire; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters