Use tracing for configurable logging

This commit is contained in:
Matthias Schiffer 2023-09-19 23:29:05 +02:00
parent e57ec81d96
commit a8eb2da95d
Signed by: neocturne
GPG key ID: 16EF3F64CB201D9C
7 changed files with 164 additions and 11 deletions

View file

@ -35,6 +35,9 @@ pub struct Args {
/// use one thread per logical CPU core.
#[arg(short, long)]
pub jobs: Option<usize>,
/// Enable verbose messages
#[arg(short, long)]
pub verbose: bool,
/// Minecraft save directory
pub input_dir: PathBuf,
/// MinedMap data directory
@ -54,6 +57,15 @@ pub fn cli() -> Result<()> {
let args = Args::parse();
let config = Config::new(&args);
tracing_subscriber::fmt()
.with_max_level(if args.verbose {
tracing::Level::DEBUG
} else {
tracing::Level::INFO
})
.with_target(false)
.init();
setup_threads(config.num_threads)?;
let rt = tokio::runtime::Builder::new_current_thread()

View file

@ -5,6 +5,7 @@ use std::{ffi::OsStr, path::Path, time::SystemTime};
use anyhow::{Context, Result};
use indexmap::IndexSet;
use rayon::prelude::*;
use tracing::{debug, error};
use super::common::*;
use crate::{
@ -148,11 +149,11 @@ impl<'a> RegionProcessor<'a> {
if Some(input_timestamp) <= output_timestamp && Some(input_timestamp) <= lightmap_timestamp
{
println!("Skipping unchanged region r.{}.{}.mca", coords.x, coords.z);
debug!("Skipping unchanged region r.{}.{}.mca", coords.x, coords.z);
return Ok(());
}
println!("Processing region r.{}.{}.mca", coords.x, coords.z);
debug!("Processing region r.{}.{}.mca", coords.x, coords.z);
crate::nbt::region::from_file(path)?.foreach_chunk(
|chunk_coords, data: world::de::Chunk| {
@ -204,7 +205,7 @@ impl<'a> RegionProcessor<'a> {
regions.par_iter().for_each(|&coords| {
if let Err(err) = self.process_region(coords) {
eprintln!("Failed to process region {:?}: {:?}", coords, err);
error!("Failed to process region {:?}: {:?}", coords, err);
}
});

View file

@ -2,6 +2,7 @@
use anyhow::{Context, Result};
use rayon::prelude::*;
use tracing::{debug, warn};
use super::common::*;
use crate::{io::fs, types::*};
@ -83,7 +84,7 @@ impl<'a> TileMipmapper<'a> {
let timestamp = match fs::modified_timestamp(&source_path) {
Ok(timestamp) => timestamp,
Err(err) => {
eprintln!("{}", err);
warn!("{}", err);
return None;
}
};
@ -96,7 +97,7 @@ impl<'a> TileMipmapper<'a> {
};
if Some(input_timestamp) <= output_timestamp {
println!(
debug!(
"Skipping unchanged mipmap tile {}",
output_path
.strip_prefix(&self.config.output_dir)
@ -106,7 +107,7 @@ impl<'a> TileMipmapper<'a> {
return Ok(());
}
println!(
debug!(
"Rendering mipmap tile {}",
output_path
.strip_prefix(&self.config.output_dir)
@ -121,7 +122,7 @@ impl<'a> TileMipmapper<'a> {
let source = match image::open(&source_path) {
Ok(source) => source,
Err(err) => {
eprintln!(
warn!(
"Failed to read source image {}: {}",
source_path.display(),
err,

View file

@ -12,6 +12,7 @@ use glam::Vec3;
use lru::LruCache;
use rayon::prelude::*;
use tokio::sync::OnceCell;
use tracing::debug;
use super::{common::*, region_group::RegionGroup};
use crate::{
@ -272,7 +273,7 @@ impl<'a> TileRenderer<'a> {
let output_timestamp = fs::read_timestamp(&output_path, FILE_META_VERSION);
if Some(processed_timestamp) <= output_timestamp {
println!(
debug!(
"Skipping unchanged tile {}",
output_path
.strip_prefix(&self.config.output_dir)
@ -282,7 +283,7 @@ impl<'a> TileRenderer<'a> {
return Ok(());
}
println!(
debug!(
"Rendering tile {}",
output_path
.strip_prefix(&self.config.output_dir)