Skip to content

Commit f54685d

Browse files
author
Pat Hickey
authored
Merge pull request #2139 from bytecodealliance/pch/wasi_common_tracing
wasi-common: switch all logs from `log` to `tracing`
2 parents 237a3ac + 5e0ca3c commit f54685d

40 files changed

+207
-184
lines changed

Cargo.lock

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/wasi-common/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@ thiserror = "1.0"
2222
libc = "0.2"
2323
getrandom = "0.1"
2424
cfg-if = "0.1.9"
25-
log = "0.4"
2625
filetime = "0.2.7"
2726
lazy_static = "1.4.0"
2827
wig = { path = "wig", version = "0.19.0" }
2928
wiggle = { path = "../wiggle", default-features = false, version = "0.19.0" }
29+
tracing = "0.1.15"
3030

3131
[target.'cfg(unix)'.dependencies]
3232
yanix = { path = "yanix", version = "0.19.0" }
@@ -44,7 +44,7 @@ default = ["trace_log"]
4444
# This feature enables the `tracing` logs in the calls to target the `log`
4545
# ecosystem of backends (e.g. `env_logger`. Disable this if you want to use
4646
# `tracing-subscriber`.
47-
trace_log = [ "wiggle/tracing_log" ]
47+
trace_log = [ "wiggle/tracing_log", "tracing/log" ]
4848
# Need to make the wiggle_metadata feature available to consumers of this
4949
# crate if they want the snapshots to have metadata available.
5050
wiggle_metadata = ["wiggle/wiggle_metadata"]

crates/wasi-common/src/ctx.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,10 @@ impl WasiCtxBuilder {
359359
self.stdout.take().unwrap(),
360360
self.stderr.take().unwrap(),
361361
] {
362-
log::debug!("WasiCtx inserting entry {:?}", pending);
362+
tracing::debug!(
363+
pending = tracing::field::debug(&pending),
364+
"WasiCtx inserting entry"
365+
);
363366
let fd = match pending {
364367
PendingEntry::Thunk(f) => {
365368
let handle = EntryHandle::from(f()?);
@@ -376,7 +379,7 @@ impl WasiCtxBuilder {
376379
.ok_or(WasiCtxBuilderError::TooManyFilesOpen)?
377380
}
378381
};
379-
log::debug!("WasiCtx inserted at {:?}", fd);
382+
tracing::debug!(fd = tracing::field::debug(fd), "WasiCtx inserted");
380383
}
381384
// Then add the preopen entries.
382385
for (guest_path, preopen) in self.preopens.take().unwrap() {
@@ -386,7 +389,7 @@ impl WasiCtxBuilder {
386389
let fd = entries
387390
.insert(entry)
388391
.ok_or(WasiCtxBuilderError::TooManyFilesOpen)?;
389-
log::debug!("WasiCtx inserted at {:?}", fd);
392+
tracing::debug!(fd = tracing::field::debug(fd), "WasiCtx inserted",);
390393
}
391394

392395
Ok(WasiCtx {

crates/wasi-common/src/entry.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,12 @@ impl EntryHandle {
1818
}
1919
}
2020

21+
impl std::fmt::Debug for EntryHandle {
22+
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
23+
f.debug_struct("EntryHandle").field("opaque", &()).finish()
24+
}
25+
}
26+
2127
impl From<Box<dyn Handle>> for EntryHandle {
2228
fn from(handle: Box<dyn Handle>) -> Self {
2329
Self(handle.into())
@@ -87,10 +93,10 @@ impl Entry {
8793
if this_rights.contains(rights) {
8894
Ok(())
8995
} else {
90-
log::trace!(
91-
" | validate_rights failed: required rights = {}; actual rights = {}",
92-
rights,
93-
this_rights,
96+
tracing::trace!(
97+
required = tracing::field::display(rights),
98+
actual = tracing::field::display(this_rights),
99+
"validate_rights failed",
94100
);
95101
Err(Errno::Notcapable)
96102
}

crates/wasi-common/src/old/snapshot_0/ctx.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ impl WasiCtxBuilder {
287287
let fd = fd_pool
288288
.allocate()
289289
.ok_or(WasiCtxBuilderError::TooManyFilesOpen)?;
290-
log::debug!("WasiCtx inserting ({:?}, {:?})", fd, pending);
290+
tracing::debug!("WasiCtx inserting ({:?}, {:?})", fd, pending);
291291
match pending.take().unwrap() {
292292
PendingEntry::Thunk(f) => {
293293
entries.insert(fd, f()?);
@@ -311,9 +311,9 @@ impl WasiCtxBuilder {
311311

312312
let mut fe = Entry::from(dir)?;
313313
fe.preopen_path = Some(guest_path);
314-
log::debug!("WasiCtx inserting ({:?}, {:?})", preopen_fd, fe);
314+
tracing::debug!("WasiCtx inserting ({:?}, {:?})", preopen_fd, fe);
315315
entries.insert(preopen_fd, fe);
316-
log::debug!("WasiCtx entries = {:?}", entries);
316+
tracing::debug!("WasiCtx entries = {:?}", entries);
317317
}
318318

319319
Ok(WasiCtx {

crates/wasi-common/src/old/snapshot_0/hostcalls_impl/fs.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ use crate::old::snapshot_0::wasi::{self, WasiError, WasiResult};
1111
use crate::old::snapshot_0::{helpers, host, wasi32};
1212
use crate::sandboxed_tty_writer::SandboxedTTYWriter;
1313
use filetime::{set_file_handle_times, FileTime};
14-
use log::trace;
1514
use std::fs::File;
1615
use std::io::{self, Read, Seek, SeekFrom, Write};
1716
use std::ops::DerefMut;
1817
use std::time::{Duration, SystemTime, UNIX_EPOCH};
18+
use tracing::trace;
1919

2020
pub(crate) unsafe fn fd_close(
2121
wasi_ctx: &mut WasiCtx,
@@ -686,8 +686,8 @@ pub(crate) unsafe fn path_rename(
686686
true,
687687
)?;
688688

689-
log::debug!("path_rename resolved_old={:?}", resolved_old);
690-
log::debug!("path_rename resolved_new={:?}", resolved_new);
689+
tracing::debug!("path_rename resolved_old={:?}", resolved_old);
690+
tracing::debug!("path_rename resolved_new={:?}", resolved_new);
691691

692692
hostcalls_impl::path_rename(resolved_old, resolved_new)
693693
}
@@ -950,7 +950,7 @@ pub(crate) unsafe fn path_remove_directory(
950950
true,
951951
)?;
952952

953-
log::debug!("path_remove_directory resolved={:?}", resolved);
953+
tracing::debug!("path_remove_directory resolved={:?}", resolved);
954954

955955
hostcalls_impl::path_remove_directory(resolved)
956956
}

crates/wasi-common/src/old/snapshot_0/hostcalls_impl/fs_helpers.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ pub(crate) fn path_get(
6868
loop {
6969
match path_stack.pop() {
7070
Some(cur_path) => {
71-
log::debug!("path_get cur_path = {:?}", cur_path);
71+
tracing::debug!("path_get cur_path = {:?}", cur_path);
7272

7373
let ends_with_slash = cur_path.ends_with('/');
7474
let mut components = Path::new(&cur_path).components();
@@ -86,7 +86,7 @@ pub(crate) fn path_get(
8686
path_stack.push(tail);
8787
}
8888

89-
log::debug!("path_get path_stack = {:?}", path_stack);
89+
tracing::debug!("path_get path_stack = {:?}", path_stack);
9090

9191
match head {
9292
Component::Prefix(_) | Component::RootDir => {
@@ -140,7 +140,7 @@ pub(crate) fn path_get(
140140
link_path.push('/');
141141
}
142142

143-
log::debug!(
143+
tracing::debug!(
144144
"attempted symlink expansion link_path={:?}",
145145
link_path
146146
);
@@ -172,7 +172,7 @@ pub(crate) fn path_get(
172172
link_path.push('/');
173173
}
174174

175-
log::debug!(
175+
tracing::debug!(
176176
"attempted symlink expansion link_path={:?}",
177177
link_path
178178
);

crates/wasi-common/src/old/snapshot_0/hostcalls_impl/misc.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ use crate::old::snapshot_0::memory::*;
55
use crate::old::snapshot_0::sys::hostcalls_impl;
66
use crate::old::snapshot_0::wasi::{self, WasiError, WasiResult};
77
use crate::old::snapshot_0::wasi32;
8-
use log::{error, trace};
98
use std::convert::TryFrom;
9+
use tracing::{error, trace};
1010

1111
pub(crate) fn args_get(
1212
wasi_ctx: &WasiCtx,
@@ -227,8 +227,8 @@ pub(crate) fn poll_oneoff(
227227
let clock = unsafe { subscription.u.u.clock };
228228
let delay = wasi_clock_to_relative_ns_delay(clock)?;
229229

230-
log::debug!("poll_oneoff event.u.clock = {:?}", clock);
231-
log::debug!("poll_oneoff delay = {:?}ns", delay);
230+
tracing::debug!("poll_oneoff event.u.clock = {:?}", clock);
231+
tracing::debug!("poll_oneoff delay = {:?}ns", delay);
232232

233233
let current = ClockEventData {
234234
delay,
@@ -299,8 +299,8 @@ pub(crate) fn poll_oneoff(
299299
}
300300
}
301301

302-
log::debug!("poll_oneoff timeout = {:?}", timeout);
303-
log::debug!("poll_oneoff fd_events = {:?}", fd_events);
302+
tracing::debug!("poll_oneoff timeout = {:?}", timeout);
303+
tracing::debug!("poll_oneoff fd_events = {:?}", fd_events);
304304

305305
hostcalls_impl::poll_oneoff(timeout, fd_events, &mut events)?;
306306

crates/wasi-common/src/old/snapshot_0/sys/unix/bsd/hostcalls_impl.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ pub(crate) fn path_unlink_file(resolved: PathGet) -> WasiResult<()> {
3636
}
3737
}
3838
Err(err) => {
39-
log::debug!("path_unlink_file fstatat error: {:?}", err);
39+
tracing::debug!("path_unlink_file fstatat error: {:?}", err);
4040
}
4141
}
4242
}
@@ -50,8 +50,8 @@ pub(crate) fn path_unlink_file(resolved: PathGet) -> WasiResult<()> {
5050
pub(crate) fn path_symlink(old_path: &str, resolved: PathGet) -> WasiResult<()> {
5151
use yanix::file::{fstatat, symlinkat, AtFlags};
5252

53-
log::debug!("path_symlink old_path = {:?}", old_path);
54-
log::debug!("path_symlink resolved = {:?}", resolved);
53+
tracing::debug!("path_symlink old_path = {:?}", old_path);
54+
tracing::debug!("path_symlink resolved = {:?}", resolved);
5555

5656
match unsafe { symlinkat(old_path, resolved.dirfd().as_raw_fd(), resolved.path()) } {
5757
Err(err) => {
@@ -71,7 +71,7 @@ pub(crate) fn path_symlink(old_path: &str, resolved: PathGet) -> WasiResult<()>
7171
} {
7272
Ok(_) => return Err(WasiError::EEXIST),
7373
Err(err) => {
74-
log::debug!("path_symlink fstatat error: {:?}", err);
74+
tracing::debug!("path_symlink fstatat error: {:?}", err);
7575
}
7676
}
7777
}
@@ -119,7 +119,7 @@ pub(crate) fn path_rename(resolved_old: PathGet, resolved_new: PathGet) -> WasiR
119119
}
120120
}
121121
Err(err) => {
122-
log::debug!("path_rename fstatat error: {:?}", err);
122+
tracing::debug!("path_rename fstatat error: {:?}", err);
123123
}
124124
}
125125
}

crates/wasi-common/src/old/snapshot_0/sys/unix/entry_impl.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -61,14 +61,14 @@ pub(crate) unsafe fn determine_type_rights<Fd: AsRawFd>(
6161
let file = std::mem::ManuallyDrop::new(std::fs::File::from_raw_fd(fd.as_raw_fd()));
6262
let ft = file.metadata()?.file_type();
6363
if ft.is_block_device() {
64-
log::debug!("Host fd {:?} is a block device", fd.as_raw_fd());
64+
tracing::debug!("Host fd {:?} is a block device", fd.as_raw_fd());
6565
(
6666
wasi::__WASI_FILETYPE_BLOCK_DEVICE,
6767
wasi::RIGHTS_BLOCK_DEVICE_BASE,
6868
wasi::RIGHTS_BLOCK_DEVICE_INHERITING,
6969
)
7070
} else if ft.is_char_device() {
71-
log::debug!("Host fd {:?} is a char device", fd.as_raw_fd());
71+
tracing::debug!("Host fd {:?} is a char device", fd.as_raw_fd());
7272
use yanix::file::isatty;
7373
if isatty(fd.as_raw_fd())? {
7474
(
@@ -84,21 +84,21 @@ pub(crate) unsafe fn determine_type_rights<Fd: AsRawFd>(
8484
)
8585
}
8686
} else if ft.is_dir() {
87-
log::debug!("Host fd {:?} is a directory", fd.as_raw_fd());
87+
tracing::debug!("Host fd {:?} is a directory", fd.as_raw_fd());
8888
(
8989
wasi::__WASI_FILETYPE_DIRECTORY,
9090
wasi::RIGHTS_DIRECTORY_BASE,
9191
wasi::RIGHTS_DIRECTORY_INHERITING,
9292
)
9393
} else if ft.is_file() {
94-
log::debug!("Host fd {:?} is a file", fd.as_raw_fd());
94+
tracing::debug!("Host fd {:?} is a file", fd.as_raw_fd());
9595
(
9696
wasi::__WASI_FILETYPE_REGULAR_FILE,
9797
wasi::RIGHTS_REGULAR_FILE_BASE,
9898
wasi::RIGHTS_REGULAR_FILE_INHERITING,
9999
)
100100
} else if ft.is_socket() {
101-
log::debug!("Host fd {:?} is a socket", fd.as_raw_fd());
101+
tracing::debug!("Host fd {:?} is a socket", fd.as_raw_fd());
102102
use yanix::socket::{get_socket_type, SockType};
103103
match get_socket_type(fd.as_raw_fd())? {
104104
SockType::Datagram => (
@@ -114,14 +114,14 @@ pub(crate) unsafe fn determine_type_rights<Fd: AsRawFd>(
114114
_ => return Err(io::Error::from_raw_os_error(libc::EINVAL)),
115115
}
116116
} else if ft.is_fifo() {
117-
log::debug!("Host fd {:?} is a fifo", fd.as_raw_fd());
117+
tracing::debug!("Host fd {:?} is a fifo", fd.as_raw_fd());
118118
(
119119
wasi::__WASI_FILETYPE_UNKNOWN,
120120
wasi::RIGHTS_REGULAR_FILE_BASE,
121121
wasi::RIGHTS_REGULAR_FILE_INHERITING,
122122
)
123123
} else {
124-
log::debug!("Host fd {:?} is unknown", fd.as_raw_fd());
124+
tracing::debug!("Host fd {:?} is unknown", fd.as_raw_fd());
125125
return Err(io::Error::from_raw_os_error(libc::EINVAL));
126126
}
127127
};

crates/wasi-common/src/old/snapshot_0/sys/unix/host_impl.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,12 +92,12 @@ impl From<io::Error> for WasiError {
9292
libc::ENOTRECOVERABLE => Self::ENOTRECOVERABLE,
9393
libc::ENOTSUP => Self::ENOTSUP,
9494
x => {
95-
log::debug!("Unknown errno value: {}", x);
95+
tracing::debug!("Unknown errno value: {}", x);
9696
Self::EIO
9797
}
9898
},
9999
None => {
100-
log::debug!("Other I/O error: {}", err);
100+
tracing::debug!("Other I/O error: {}", err);
101101
Self::EIO
102102
}
103103
}

crates/wasi-common/src/old/snapshot_0/sys/unix/hostcalls_impl/fs.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,8 @@ pub(crate) fn path_open(
115115
// umask is, but don't set the executable flag, because it isn't yet
116116
// meaningful for WASI programs to create executable files.
117117

118-
log::debug!("path_open resolved = {:?}", resolved);
119-
log::debug!("path_open oflags = {:?}", nix_all_oflags);
118+
tracing::debug!("path_open resolved = {:?}", resolved);
119+
tracing::debug!("path_open oflags = {:?}", nix_all_oflags);
120120

121121
let new_fd = match unsafe {
122122
openat(
@@ -144,7 +144,7 @@ pub(crate) fn path_open(
144144
}
145145
}
146146
Err(err) => {
147-
log::debug!("path_open fstatat error: {:?}", err);
147+
tracing::debug!("path_open fstatat error: {:?}", err);
148148
}
149149
}
150150
}
@@ -166,7 +166,7 @@ pub(crate) fn path_open(
166166
}
167167
}
168168
Err(err) => {
169-
log::debug!("path_open fstatat error: {:?}", err);
169+
tracing::debug!("path_open fstatat error: {:?}", err);
170170
}
171171
}
172172
}
@@ -182,7 +182,7 @@ pub(crate) fn path_open(
182182
}
183183
};
184184

185-
log::debug!("path_open (host) new_fd = {:?}", new_fd);
185+
tracing::debug!("path_open (host) new_fd = {:?}", new_fd);
186186

187187
// Determine the type of the new file descriptor and which rights contradict with this type
188188
Ok(unsafe { File::from_raw_fd(new_fd) })
@@ -294,10 +294,10 @@ pub(crate) fn fd_readdir<'a>(
294294
// Seek if needed. Unless cookie is wasi::__WASI_DIRCOOKIE_START,
295295
// new items may not be returned to the caller.
296296
if cookie == wasi::__WASI_DIRCOOKIE_START {
297-
log::trace!(" | fd_readdir: doing rewinddir");
297+
tracing::trace!(" | fd_readdir: doing rewinddir");
298298
dir.rewind();
299299
} else {
300-
log::trace!(" | fd_readdir: doing seekdir to {}", cookie);
300+
tracing::trace!(" | fd_readdir: doing seekdir to {}", cookie);
301301
let loc = unsafe { SeekLoc::from_raw(cookie as i64)? };
302302
dir.seek(loc);
303303
}

0 commit comments

Comments
 (0)