Skip to content

Commit a4fdb09

Browse files
committed
[update] logging for all crates.
1 parent 9965aba commit a4fdb09

File tree

16 files changed

+58
-41
lines changed

16 files changed

+58
-41
lines changed

Cargo.lock

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

crates/lambda-rs-logging/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22
name = "lambda-rs-logging"
33
description = "Logging support for lambda-rs"
4-
version = "2023.1.29"
4+
version = "2023.1.30"
55
edition = "2021"
66
license = "MIT"
77

crates/lambda-rs-logging/src/handler.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,12 @@ impl FileHandler {
4444
let log_message = format!("[{}]-[{:?}]: {}", timestamp, log_level, message);
4545

4646
let colored_message = match log_level {
47-
LogLevel::TRACE => format!("\x1B[34m{}\x1B[0m\n", log_message),
48-
LogLevel::DEBUG => format!("\x1B[33m{}\x1B[0m\n", log_message),
49-
LogLevel::INFO => format!("\x1B[32m{}\x1B[0m\n", log_message),
50-
LogLevel::WARN => format!("\x1B[31m{}\x1B[0m\n", log_message),
51-
LogLevel::ERROR => format!("\x1B[31;1m{}\x1B[0m\n", log_message),
52-
LogLevel::FATAL => format!("\x1B[31;1m{}\x1B[0m\n", log_message),
47+
LogLevel::TRACE => format!("\x1B[37m{}\x1B[0m", log_message),
48+
LogLevel::DEBUG => format!("\x1B[35m{}\x1B[0m", log_message),
49+
LogLevel::INFO => format!("\x1B[32m{}\x1B[0m", log_message),
50+
LogLevel::WARN => format!("\x1B[33m{}\x1B[0m", log_message),
51+
LogLevel::ERROR => format!("\x1B[31;1m{}\x1B[0m", log_message),
52+
LogLevel::FATAL => format!("\x1B[31;1m{}\x1B[0m", log_message),
5353
};
5454

5555
self.log_buffer.push(colored_message);

crates/lambda-rs-platform/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ rand = "=0.8.5"
1919
obj-rs = "=0.7.0"
2020
gfx-backend-empty = "=0.9.0"
2121

22+
lambda-rs-logging = { path = "../lambda-rs-logging", version = "2023.1.30" }
23+
2224
# GFX-RS backends
2325
gfx-backend-gl = { version="=0.9.0", optional = true }
2426
gfx-backend-metal = { version="=0.9.0", optional = true }

crates/lambda-rs-platform/src/gfx/assembler.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ impl PrimitiveAssemblerBuilder {
4747

4848
match (buffers, attributes) {
4949
(Some(buffers), Some(attributes)) => {
50-
println!(
51-
"[DEBUG] Building primitive assembler with buffers and attributes"
50+
logging::debug!(
51+
"Building primitive assembler with buffers and attributes"
5252
);
5353
self.buffer_descriptions = buffers
5454
.iter()

crates/lambda-rs-platform/src/gfx/buffer.rs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,10 @@ impl BufferBuilder {
110110

111111
// TODO(vmarcella): Add the ability for the user to specify the memory
112112
// properties (I.E. SparseFlags::SPARSE_MEMORY).
113-
println!("[DEBUG] Creating buffer of length: {}", self.buffer_length);
113+
logging::debug!(
114+
"[DEBUG] Creating buffer of length: {}",
115+
self.buffer_length
116+
);
114117
let buffer_result = unsafe {
115118
logical_device.create_buffer(
116119
self.buffer_length as u64,
@@ -120,6 +123,7 @@ impl BufferBuilder {
120123
};
121124

122125
if buffer_result.is_err() {
126+
logging::error!("Failed to create buffer for allocating memory.");
123127
return Err("Failed to create buffer for allocating memory.");
124128
}
125129

@@ -129,7 +133,7 @@ impl BufferBuilder {
129133
unsafe { logical_device.get_buffer_requirements(&buffer) };
130134
let memory_types = physical_device.memory_properties().memory_types;
131135

132-
println!("[DEBUG] Buffer requirements: {:?}", requirements);
136+
logging::debug!("Buffer requirements: {:?}", requirements);
133137
// Find a memory type that supports the requirements of the buffer.
134138
let memory_type = memory_types
135139
.iter()
@@ -141,12 +145,13 @@ impl BufferBuilder {
141145
.map(|(id, _)| MemoryTypeId(id))
142146
.unwrap();
143147

144-
println!("Allocating memory for buffer.");
148+
logging::debug!("Allocating memory for buffer.");
145149
// Allocates the memory on the GPU for the buffer.
146150
let buffer_memory_allocation =
147151
unsafe { logical_device.allocate_memory(memory_type, requirements.size) };
148152

149153
if buffer_memory_allocation.is_err() {
154+
logging::error!("Failed to allocate memory for buffer.");
150155
return Err("Failed to allocate memory for buffer.");
151156
}
152157

@@ -160,6 +165,7 @@ impl BufferBuilder {
160165
// Destroy the buffer if we failed to bind it to memory.
161166
if buffer_binding.is_err() {
162167
unsafe { logical_device.destroy_buffer(buffer) };
168+
logging::error!("Failed to bind buffer memory.");
163169
return Err("Failed to bind buffer memory.");
164170
}
165171

@@ -169,6 +175,7 @@ impl BufferBuilder {
169175

170176
if get_mapping_to_memory.is_err() {
171177
unsafe { logical_device.destroy_buffer(buffer) };
178+
logging::error!("Failed to map memory.");
172179
return Err("Failed to map memory.");
173180
}
174181
let mapped_memory = get_mapping_to_memory.unwrap();
@@ -194,6 +201,7 @@ impl BufferBuilder {
194201

195202
if memory_flush.is_err() {
196203
unsafe { logical_device.destroy_buffer(buffer) };
204+
logging::error!("Failed to flush memory.");
197205
return Err("No memory available on the GPU.");
198206
}
199207

crates/lambda-rs-platform/src/gfx/gpu.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ impl<RenderBackend: gfx_hal::Backend> Gpu<RenderBackend> {
163163
};
164164

165165
if result.is_err() {
166-
println!(
166+
logging::error!(
167167
"Failed to present to the surface: {:?}",
168168
result.err().unwrap()
169169
);

crates/lambda-rs-platform/src/gfx/pipeline.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ pub struct RenderPipeline<RenderBackend: Backend> {
167167
impl<RenderBackend: Backend> RenderPipeline<RenderBackend> {
168168
/// Destroys the pipeline layout and graphical pipeline
169169
pub fn destroy(self, gpu: &super::gpu::Gpu<RenderBackend>) {
170-
println!("Destroying render pipeline");
170+
logging::debug!("Destroying render pipeline");
171171
unsafe {
172172
for buffer in self.buffers {
173173
buffer.destroy(gpu);

crates/lambda-rs-platform/src/gfx/surface.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ impl<RenderBackend: gfx_hal::Backend> Surface<RenderBackend> {
128128
/// Remove the swapchain configuration that this surface used on this given
129129
/// GPU.
130130
pub fn remove_swapchain(&mut self, gpu: &Gpu<RenderBackend>) {
131-
println!("Removing the swapchain configuration from: {}", self.name);
131+
logging::debug!("Removing the swapchain configuration from: {}", self.name);
132132
unsafe {
133133
self
134134
.gfx_hal_surface
@@ -138,7 +138,7 @@ impl<RenderBackend: gfx_hal::Backend> Surface<RenderBackend> {
138138

139139
/// Destroy the current surface and it's underlying resources.
140140
pub fn destroy(self, instance: &Instance<RenderBackend>) {
141-
println!("Destroying the surface: {}", self.name);
141+
logging::debug!("Destroying the surface: {}", self.name);
142142

143143
instance.destroy_surface(self.gfx_hal_surface);
144144
}

crates/lambda-rs/examples/push_constants.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use lambda::{
22
component::Component,
33
events::WindowEvent,
4+
logging,
45
math::{
56
matrix,
67
matrix::Matrix,
@@ -186,7 +187,7 @@ impl Component<ComponentResult, String> for PushConstantsExample {
186187
])
187188
.build();
188189

189-
println!("mesh: {:?}", mesh);
190+
logging::trace!("mesh: {:?}", mesh);
190191

191192
let pipeline = RenderPipelineBuilder::new()
192193
.with_push_constant(PipelineStage::VERTEX, push_constant_size)
@@ -208,7 +209,7 @@ impl Component<ComponentResult, String> for PushConstantsExample {
208209
&mut self,
209210
render_context: &mut lambda::render::RenderContext,
210211
) -> Result<ComponentResult, String> {
211-
println!("Detaching component");
212+
logging::info!("Detaching component");
212213
return Ok(ComponentResult::Success);
213214
}
214215

@@ -222,7 +223,7 @@ impl Component<ComponentResult, String> for PushConstantsExample {
222223
WindowEvent::Resize { width, height } => {
223224
self.width = width;
224225
self.height = height;
225-
println!("Window resized to {}x{}", width, height);
226+
logging::info!("Window resized to {}x{}", width, height);
226227
}
227228
_ => {}
228229
},

0 commit comments

Comments
 (0)