From 152138fe8934edc79d2bce1536edc31003ef7457 Mon Sep 17 00:00:00 2001 From: filedesless Date: Sat, 30 May 2020 23:07:26 -0400 Subject: [PATCH 1/2] replace print statements by logging --- Cargo.lock | 10 ++++++++++ src/game.rs | 3 ++- src/main.rs | 3 ++- 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 9914df2..1b7c355 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -65,6 +65,7 @@ checksum = "0dbbb57365263e881e805dc77d94697c9118fd94d8da011240555aa7b23445bd" name = "core" version = "0.1.0" dependencies = [ + "log", "math", "serde", ] @@ -291,6 +292,15 @@ version = "0.2.70" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3baa92041a6fec78c687fa0cc2b3fae8884f743d672cf551bed1d6dac6988d0f" +[[package]] +name = "log" +version = "0.4.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "14b6052be84e6b71ab17edffc2eeabf5c2c3ae1fdb464aae35ac50c67a44e1f7" +dependencies = [ + "cfg-if", +] + [[package]] name = "lzw" version = "0.10.0" diff --git a/src/game.rs b/src/game.rs index 4cf0c2b..8665a01 100644 --- a/src/game.rs +++ b/src/game.rs @@ -2,6 +2,7 @@ use crate::network::NetworkHandler; use crate::player::{Player, PlayerId}; use core::events::{ClientEvent, ServerEvent}; +use core::utils::logging; use core::utils::sleep; use core::world::World; use std::collections::HashMap; @@ -55,7 +56,7 @@ impl Game { let tps = 1.0 / start.elapsed().as_secs_f64(); // TODO: make a struct for ServerStats - println!( + logging::info!( "mspt: {:.3}, tps: {:.1}, players: {}", mspt, tps, diff --git a/src/main.rs b/src/main.rs index 8336da6..ecc721a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -4,6 +4,7 @@ mod player; use crate::game::Game; +use core::utils::logging; use std::io; gflags::define! { @@ -25,7 +26,7 @@ fn main() -> io::Result<()> { gflags::parse(); if HELP.flag { - println!("{} {}", env!("CARGO_PKG_NAME"), env!("CARGO_PKG_VERSION")); + logging::info!("{} {}", env!("CARGO_PKG_NAME"), env!("CARGO_PKG_VERSION")); gflags::print_help_and_exit(0); } From 986fac83b35a9d15c4ba0707e9e58bb3255532dd Mon Sep 17 00:00:00 2001 From: filedesless Date: Sun, 31 May 2020 00:13:50 -0400 Subject: [PATCH 2/2] use defs --- src/game.rs | 4 ++-- src/main.rs | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/game.rs b/src/game.rs index 8665a01..e9ab5a0 100644 --- a/src/game.rs +++ b/src/game.rs @@ -2,7 +2,7 @@ use crate::network::NetworkHandler; use crate::player::{Player, PlayerId}; use core::events::{ClientEvent, ServerEvent}; -use core::utils::logging; +use core::utils::logging::info; use core::utils::sleep; use core::world::World; use std::collections::HashMap; @@ -56,7 +56,7 @@ impl Game { let tps = 1.0 / start.elapsed().as_secs_f64(); // TODO: make a struct for ServerStats - logging::info!( + info!( "mspt: {:.3}, tps: {:.1}, players: {}", mspt, tps, diff --git a/src/main.rs b/src/main.rs index ecc721a..4033bce 100644 --- a/src/main.rs +++ b/src/main.rs @@ -4,7 +4,7 @@ mod player; use crate::game::Game; -use core::utils::logging; +use core::utils::logging::info; use std::io; gflags::define! { @@ -26,7 +26,7 @@ fn main() -> io::Result<()> { gflags::parse(); if HELP.flag { - logging::info!("{} {}", env!("CARGO_PKG_NAME"), env!("CARGO_PKG_VERSION")); + info!("{} {}", env!("CARGO_PKG_NAME"), env!("CARGO_PKG_VERSION")); gflags::print_help_and_exit(0); }