chore: Improve debug logs

This commit is contained in:
Lucas Schwiderski 2023-02-22 15:39:08 +01:00
parent f90247710e
commit aa05c5bd4a
Signed by: lucas
GPG key ID: AA12679AAA6DF4D8
3 changed files with 20 additions and 9 deletions

View file

@ -392,15 +392,21 @@ pub(crate) async fn import_mod(state: State, info: FileInfo) -> Result<ModInfo>
let mut archive = ZipArchive::new(data).wrap_err("failed to open ZIP archive")?;
for f in archive.file_names() {
tracing::debug!("{}", f);
if tracing::enabled!(tracing::Level::DEBUG) {
let names = archive.file_names().fold(String::new(), |mut s, name| {
s.push('\n');
s.push_str(name);
s
});
tracing::debug!("Archive contents:{}", names);
}
let dir_name = {
let f = archive.by_index(0).wrap_err("archive is empty")?;
if !f.is_dir() {
eyre::bail!("archive does not have a top-level directory");
let err = eyre::eyre!("archive does not have a top-level directory");
return Err(err).with_suggestion(|| "Use 'dtmt build' to create the mod archive.");
}
let name = f.name();
@ -408,6 +414,8 @@ pub(crate) async fn import_mod(state: State, info: FileInfo) -> Result<ModInfo>
name[..(name.len().saturating_sub(1))].to_string()
};
tracing::info!("Importing mod {}", dir_name);
let mod_cfg: ModConfig = {
let mut f = archive
.by_name(&format!("{}/{}", dir_name, "dtmt.cfg"))
@ -421,6 +429,8 @@ pub(crate) async fn import_mod(state: State, info: FileInfo) -> Result<ModInfo>
serde_sjson::from_str(&data).wrap_err("failed to deserialize mod config")?
};
tracing::debug!(?mod_cfg);
let files: HashMap<String, Vec<String>> = {
let mut f = archive
.by_name(&format!("{}/{}", dir_name, "files.sjson"))

View file

@ -544,22 +544,23 @@ impl BundleFile {
r.skip_u32(0)?;
for i in 0..header_count {
let span = tracing::info_span!("Read file header", i);
let span = tracing::debug_span!("Read file header", i);
let _enter = span.enter();
let header = BundleFileVariant::read_header(r)
.wrap_err_with(|| format!("failed to read header {i}"))?;
if props.contains(Properties::DATA) {
tracing::debug!("props: {props:?} | unknown_1: {}", header.unknown_1)
}
// TODO: Figure out how `header.unknown_1` correlates to `properties::DATA`
// if props.contains(Properties::DATA) {
// tracing::debug!("props: {props:?} | unknown_1: {}", header.unknown_1)
// }
headers.push(header);
}
let mut variants = Vec::with_capacity(header_count);
for (i, header) in headers.into_iter().enumerate() {
let span = tracing::info_span!(
let span = tracing::debug_span!(
"Read file data {}",
i,
size = header.size,

View file

@ -192,7 +192,7 @@ impl Bundle {
let mut files = Vec::with_capacity(num_entries);
tracing::trace!(num_files = num_entries);
for (i, props) in file_props.iter().enumerate() {
let span = tracing::trace_span!("Read file {}", i);
let span = tracing::debug_span!("Read file {}", i);
let _enter = span.enter();
let file = BundleFile::from_reader(ctx, &mut r, *props)