Skip to content

Commit 24ea53b

Browse files
authored
feat: replace log with tracing (#1460)
* feat: replace log with tracing * chore: clippy * fix: revert replacing println!-calls * fix: await async construct * fix: lints + incorrect await * fix: each plugin spawns their own tracing-subscriber * fix: replace info! with println for commands * chore: remove env_logger * fix: added TODO about structured logging
1 parent bb75b78 commit 24ea53b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

66 files changed

+569
-457
lines changed

Cargo.lock

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

Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,6 @@ debug = true
8787
strip = false
8888

8989
[workspace.dependencies]
90-
log = "0.4"
9190
tokio = { version = "1.49", default-features = false }
9291
syn = { version = "2.0", default-features = false, features = ["printing"] }
9392

pumpkin-config/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ rust-version.workspace = true
77
[dependencies]
88
pumpkin-util.workspace = true
99
serde.workspace = true
10-
log.workspace = true
10+
tracing.workspace = true
1111
uuid.workspace = true
1212

1313
toml.workspace = true

pumpkin-config/src/lib.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use serde::{Deserialize, Serialize, de::DeserializeOwned};
77
use std::net::SocketAddr;
88
use std::path::PathBuf;
99
use std::{fs, num::NonZeroU8, path::Path};
10+
use tracing::{debug, warn};
1011
pub mod fun;
1112
pub mod logging;
1213
pub mod networking;
@@ -189,7 +190,7 @@ pub trait LoadConfiguration {
189190
Self: Sized + Default + Serialize + DeserializeOwned,
190191
{
191192
if !config_dir.exists() {
192-
log::debug!("creating new config root folder");
193+
debug!("creating new config root folder");
193194
fs::create_dir(config_dir).expect("Failed to create config root folder");
194195
}
195196
let path = config_dir.join(Self::get_path());
@@ -215,7 +216,7 @@ pub trait LoadConfiguration {
215216
path.file_name().unwrap().display()
216217
);
217218
if let Err(err) = fs::write(&path, toml::to_string(&merged_config).unwrap()) {
218-
log::warn!(
219+
warn!(
219220
"Couldn't write merged config to {}. Reason: {}",
220221
path.display(),
221222
err
@@ -227,7 +228,7 @@ pub trait LoadConfiguration {
227228
} else {
228229
let content = Self::default();
229230
if let Err(err) = fs::write(&path, toml::to_string(&content).unwrap()) {
230-
log::warn!(
231+
warn!(
231232
"Couldn't write default config to {:?}. Reason: {}",
232233
path.display(),
233234
err

pumpkin-inventory/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ pumpkin-data.workspace = true
1111
pumpkin-world.workspace = true
1212
pumpkin-util.workspace = true
1313

14-
log.workspace = true
14+
tracing.workspace = true
1515
tokio.workspace = true
1616
thiserror.workspace = true
1717
crossbeam-utils.workspace = true

pumpkin-inventory/src/furnace_like/furnace_like_screen_handler.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ use crate::{
1414
ScreenHandlerFuture, ScreenHandlerListener, ScreenProperty,
1515
},
1616
};
17+
use tracing::debug;
1718

1819
use super::furnace_like_slot::{FurnaceLikeSlot, FurnaceLikeSlotType, FurnaceOutputSlot};
1920

@@ -119,7 +120,7 @@ impl ScreenHandler for FurnaceLikeScreenHandler {
119120
const FUEL_SLOT: i32 = 1; // Note: Slots 0, 1, 2 are Furnace slots.
120121
const OUTPUT_SLOT: i32 = 2;
121122

122-
log::debug!("FurnaceLikeScreenHandler::quick_move slot_index={slot_index}");
123+
debug!("FurnaceLikeScreenHandler::quick_move slot_index={slot_index}");
123124

124125
let mut stack_left = ItemStack::EMPTY.clone();
125126

@@ -163,7 +164,7 @@ impl ScreenHandler for FurnaceLikeScreenHandler {
163164

164165
// Award XP when taking from output slot (slot 2)
165166
if slot_index == OUTPUT_SLOT {
166-
log::debug!("quick_move: taking from output slot, calling on_take_item");
167+
debug!("quick_move: taking from output slot, calling on_take_item");
167168
slot.on_take_item(player, &stack_left).await;
168169
}
169170

pumpkin-inventory/src/furnace_like/furnace_like_slot.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ use pumpkin_world::{
55
block::entities::furnace_like_block_entity::ExperienceContainer, inventory::Inventory,
66
};
77

8+
use tracing::debug;
9+
810
use crate::{
911
screen_handler::InventoryPlayer,
1012
slot::{BoxFuture, Slot},
@@ -118,12 +120,12 @@ impl Slot for FurnaceOutputSlot {
118120
_stack: &'a pumpkin_world::item::ItemStack,
119121
) -> BoxFuture<'a, ()> {
120122
Box::pin(async move {
121-
log::debug!("FurnaceOutputSlot: on_take_item called");
123+
debug!("FurnaceOutputSlot: on_take_item called");
122124
// Extract accumulated experience and award to player
123125
let experience = self.experience_container.extract_experience();
124-
log::debug!("FurnaceOutputSlot: extracted experience = {experience}");
126+
debug!("FurnaceOutputSlot: extracted experience = {experience}");
125127
if experience > 0 {
126-
log::debug!("FurnaceOutputSlot: awarding {experience} xp to player");
128+
debug!("FurnaceOutputSlot: awarding {experience} xp to player");
127129
player.award_experience(experience).await;
128130
}
129131
self.mark_dirty().await;

pumpkin-inventory/src/player/player_inventory.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ use std::pin::Pin;
1414
use std::sync::Arc;
1515
use std::sync::atomic::{AtomicU8, Ordering};
1616
use tokio::sync::Mutex;
17+
use tracing::warn;
1718

1819
pub struct PlayerInventory {
1920
pub main_inventory: [Arc<Mutex<ItemStack>>; Self::MAIN_SIZE],
@@ -401,13 +402,10 @@ impl Inventory for PlayerInventory {
401402
Box::pin(async move {
402403
if slot < self.main_inventory.len() {
403404
*self.main_inventory[slot].lock().await = stack;
405+
} else if let Some(slot) = self.equipment_slots.get(&slot) {
406+
self.entity_equipment.lock().await.put(slot, stack).await;
404407
} else {
405-
match self.equipment_slots.get(&slot) {
406-
Some(slot) => {
407-
self.entity_equipment.lock().await.put(slot, stack).await;
408-
}
409-
None => log::warn!("Failed to get Equipment Slot at {slot}"),
410-
}
408+
warn!("Failed to get Equipment Slot at {slot}");
411409
}
412410
})
413411
}

pumpkin-inventory/src/screen_handler.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ use crate::{
44
slot::{NormalSlot, Slot},
55
sync_handler::{SyncHandler, TrackedStack},
66
};
7-
use log::warn;
87
use pumpkin_data::{
98
data_component_impl::{EquipmentSlot, EquipmentType, EquippableImpl},
109
screen::WindowType,
@@ -29,6 +28,7 @@ use std::sync::atomic::{AtomicU32, Ordering};
2928
use std::{any::Any, collections::HashMap, sync::Arc};
3029
use std::{cmp::max, pin::Pin};
3130
use tokio::sync::Mutex;
31+
use tracing::warn;
3232

3333
const SLOT_INDEX_OUTSIDE: i32 = -999;
3434

pumpkin-world/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ uuid.workspace = true
2929
thiserror.workspace = true
3030
serde.workspace = true
3131
serde_json.workspace = true
32-
log.workspace = true
32+
tracing.workspace = true
3333
crossbeam.workspace = true
3434

3535
sha2.workspace = true

0 commit comments

Comments
 (0)