From 16cf7689a86bc75984a57ff75671354977d69c9f Mon Sep 17 00:00:00 2001 From: Kevin Glasson Date: Sun, 21 Jun 2020 18:22:26 +0800 Subject: [PATCH] Convert voxygen to use tracing There are several noteable changes in this commit that mean that logging will behave differently to how it did previously. - There are now no separate filter levels for terminal and file output. This is a feature that is lacking in `tracing` but is set to be resolved by https://github.com/tokio-rs/tracing/pull/508. At which point we MAY include it. - The default log level was previously `WARN` - it is now `INFO`. --- Cargo.lock | 82 ++++++++++----- voxygen/Cargo.toml | 11 +- voxygen/src/anim/src/dyn_lib.rs | 10 +- voxygen/src/audio/mod.rs | 3 +- voxygen/src/audio/music.rs | 6 +- voxygen/src/audio/sfx/mod.rs | 5 +- voxygen/src/audio/soundcache.rs | 3 +- voxygen/src/ecs/sys/interpolation.rs | 2 +- voxygen/src/hud/item_imgs.rs | 2 +- voxygen/src/i18n.rs | 11 +- voxygen/src/logging.rs | 137 ++++++++++++------------- voxygen/src/main.rs | 33 +++--- voxygen/src/menu/char_selection/mod.rs | 2 +- voxygen/src/menu/main/mod.rs | 2 +- voxygen/src/meta.rs | 8 +- voxygen/src/profile.rs | 8 +- voxygen/src/render/renderer.rs | 2 +- voxygen/src/scene/figure/load.rs | 2 +- voxygen/src/scene/figure/mod.rs | 2 +- voxygen/src/scene/simple.rs | 2 +- voxygen/src/session.rs | 4 +- voxygen/src/settings.rs | 8 +- voxygen/src/singleplayer.rs | 2 +- voxygen/src/ui/graphic/mod.rs | 2 +- voxygen/src/ui/mod.rs | 2 +- voxygen/src/window.rs | 2 +- 26 files changed, 190 insertions(+), 163 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 7a15df740c..9b0b4535bf 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -571,17 +571,6 @@ dependencies = [ "objc", ] -[[package]] -name = "colored" -version = "1.9.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f4ffc801dacf156c5854b9df4f425a626539c3a6ef7893cc0c5084a23f0b6c59" -dependencies = [ - "atty", - "lazy_static", - "winapi 0.3.8", -] - [[package]] name = "conrod_core" version = "0.63.0" @@ -1210,17 +1199,6 @@ dependencies = [ "synstructure", ] -[[package]] -name = "fern" -version = "0.5.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e69ab0d5aca163e388c3a49d284fed6c3d0810700e77c5ae2756a50ec1a4daaa" -dependencies = [ - "chrono", - "colored", - "log", -] - [[package]] name = "filetime" version = "0.2.10" @@ -4251,9 +4229,32 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a41f40ed0e162c911ac6fcb53ecdc8134c46905fdbbae8c50add462a538b495f" dependencies = [ "cfg-if", + "tracing-attributes", "tracing-core", ] +[[package]] +name = "tracing-appender" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e86a61ff69b54f44ffdf02cf27f2da864639dde602d5f90d9f7ef2ea76629c0" +dependencies = [ + "chrono", + "crossbeam-channel 0.4.2", + "tracing-subscriber", +] + +[[package]] +name = "tracing-attributes" +version = "0.1.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "99bbad0de3fd923c9c3232ead88510b783e5a4d16a6154adffa3d53308de984c" +dependencies = [ + "proc-macro2 1.0.18", + "quote 1.0.7", + "syn 1.0.31", +] + [[package]] name = "tracing-core" version = "0.1.10" @@ -4274,19 +4275,44 @@ dependencies = [ ] [[package]] -name = "tracing-subscriber" -version = "0.2.5" +name = "tracing-log" +version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1d53c40489aa69c9aed21ff483f26886ca8403df33bdc2d2f87c60c1617826d2" +checksum = "5e0f8c7178e13481ff6765bd169b33e8d554c5d2bbede5e32c356194be02b9b9" +dependencies = [ + "lazy_static", + "log", + "tracing-core", +] + +[[package]] +name = "tracing-serde" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6ccba2f8f16e0ed268fc765d9b7ff22e965e7185d32f8f1ec8294fe17d86e79" +dependencies = [ + "serde", + "tracing-core", +] + +[[package]] +name = "tracing-subscriber" +version = "0.2.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "04a11b459109e38ff6e1b580bafef4142a11d44889f5d07424cbce2fd2a2a119" dependencies = [ "ansi_term", "chrono", "lazy_static", "matchers", "regex", + "serde", + "serde_json", "sharded-slab", "smallvec 1.4.0", "tracing-core", + "tracing-log", + "tracing-serde", ] [[package]] @@ -4567,7 +4593,6 @@ dependencies = [ "dot_vox", "euc", "failure", - "fern", "gfx", "gfx_device_gl", "gfx_window_glutin", @@ -4578,7 +4603,6 @@ dependencies = [ "guillotiere", "hashbrown", "image", - "log", "msgbox", "num 0.2.1", "rand 0.7.3", @@ -4588,6 +4612,10 @@ dependencies = [ "serde_derive", "specs", "specs-idvs", + "tracing", + "tracing-appender", + "tracing-log", + "tracing-subscriber", "treeculler", "uvth 3.1.1", "vek", diff --git a/voxygen/Cargo.toml b/voxygen/Cargo.toml index bd96e5c9f4..cdf93d4074 100644 --- a/voxygen/Cargo.toml +++ b/voxygen/Cargo.toml @@ -48,14 +48,12 @@ server = { package = "veloren-server", path = "../server", optional = true } # Utility glsl-include = "0.3.1" failure = "0.1.6" -log = "0.4.8" dot_vox = "4.0" image = { version = "0.22.5", default-features = false, features = ["ico", "png"] } serde = "1.0" serde_derive = "1.0" ron = { version = "0.6", default-features = false } guillotiere = { git = "https://github.com/Imberflur/guillotiere" } -fern = { version = "0.5.8", features = ["colored"] } msgbox = { git = "https://github.com/bekker/msgbox-rs.git", default-features = false, rev = "68fe39a", optional = true } directories = "2.0.2" num = "0.2.0" @@ -73,6 +71,15 @@ uvth = "3.1.1" authc = { git = "https://gitlab.com/veloren/auth.git", rev = "223a4097f7ebc8d451936dccb5e6517194bbf086" } const-tweaker = { version = "0.2.5", optional = true } +# # Logging +# log = "0.4.8" +# fern = { version = "0.5.8", features = ["colored"] } +# Logging (new) +tracing = { version = "0.1", default-features = false , features = ["attributes"] } +tracing-subscriber = { version = "0.2.3", default-features = false, features = ["env-filter", "fmt", "chrono", "ansi", "smallvec", "registry", "tracing-log"] } +tracing-log = "0.1.1" +tracing-appender = "0.1" + [target.'cfg(target_os = "macos")'.dependencies] dispatch = "0.1.4" diff --git a/voxygen/src/anim/src/dyn_lib.rs b/voxygen/src/anim/src/dyn_lib.rs index 9308c97e30..a0f4505bea 100644 --- a/voxygen/src/anim/src/dyn_lib.rs +++ b/voxygen/src/anim/src/dyn_lib.rs @@ -69,7 +69,7 @@ pub fn init() { info.push_str(&path); info.push('\"'); } - log::warn!("{}", info); + warn!("{}", info); // Reload reload(); @@ -96,7 +96,7 @@ fn event_fn(res: notify::Result, sender: &mpsc::Sender) { }, _ => {}, }, - Err(e) => log::error!("Animation hotreload watcher error: {:?}", e), + Err(e) => error!("Animation hotreload watcher error: {:?}", e), } } @@ -119,7 +119,7 @@ fn reload() { // Open new lib *lock = Some(LoadedLib::load()); - log::warn!("Updated animations"); + warn!("Updated animations"); } // Returns false if compile failed @@ -135,10 +135,10 @@ fn compile() -> bool { // If compile failed if !output.status.success() { - log::error!("Failed to compile anim crate"); + error!("Failed to compile anim crate"); false } else { - log::warn!("Animation recompile success!!"); + warn!("Animation recompile success!!"); true } } diff --git a/voxygen/src/audio/mod.rs b/voxygen/src/audio/mod.rs index 370c3ec45f..9c7b022dc4 100644 --- a/voxygen/src/audio/mod.rs +++ b/voxygen/src/audio/mod.rs @@ -9,6 +9,7 @@ pub mod soundcache; use channel::{MusicChannel, MusicChannelTag, SfxChannel}; use fader::Fader; use soundcache::SoundCache; +use tracing::warn; use common::assets; use cpal::traits::DeviceTrait; @@ -272,7 +273,7 @@ fn list_devices_raw() -> Vec { devices.filter(|d| d.name().is_ok()).collect() }, Err(_) => { - log::warn!("Failed to enumerate audio output devices, audio will not be available"); + warn!("Failed to enumerate audio output devices, audio will not be available"); Vec::new() }, } diff --git a/voxygen/src/audio/music.rs b/voxygen/src/audio/music.rs index 6d86908666..643b4826b5 100644 --- a/voxygen/src/audio/music.rs +++ b/voxygen/src/audio/music.rs @@ -37,12 +37,12 @@ //! tracks //! - If you are not the author of the track, ensure that the song's licensing //! permits usage of the track for non-commercial use - use crate::audio::AudioFrontend; use common::{assets, state::State}; use rand::{seq::IteratorRandom, thread_rng}; use serde::Deserialize; use std::time::Instant; +use tracing::warn; const DAY_START_SECONDS: u32 = 28800; // 8:00 const DAY_END_SECONDS: u32 = 70200; // 19:30 @@ -146,7 +146,7 @@ impl MusicMgr { Ok(file) => match ron::de::from_reader(file) { Ok(config) => config, Err(error) => { - log::warn!( + warn!( "Error parsing music config file, music will not be available: {}", format!("{:#?}", error) ); @@ -155,7 +155,7 @@ impl MusicMgr { }, }, Err(error) => { - log::warn!( + warn!( "Error reading music config file, music will not be available: {}", format!("{:#?}", error) ); diff --git a/voxygen/src/audio/sfx/mod.rs b/voxygen/src/audio/sfx/mod.rs index 38e50412db..63f5ef9619 100644 --- a/voxygen/src/audio/sfx/mod.rs +++ b/voxygen/src/audio/sfx/mod.rs @@ -94,6 +94,7 @@ use event_mapper::SfxEventMapper; use hashbrown::HashMap; use serde::Deserialize; use specs::WorldExt; +use tracing::warn; use vek::*; /// We watch the states of nearby entities in order to emit SFX at their @@ -193,7 +194,7 @@ impl SfxMgr { Ok(file) => match ron::de::from_reader(file) { Ok(config) => config, Err(error) => { - log::warn!( + warn!( "Error parsing sfx config file, sfx will not be available: {}", format!("{:#?}", error) ); @@ -202,7 +203,7 @@ impl SfxMgr { }, }, Err(error) => { - log::warn!( + warn!( "Error reading sfx config file, sfx will not be available: {}", format!("{:#?}", error) ); diff --git a/voxygen/src/audio/soundcache.rs b/voxygen/src/audio/soundcache.rs index f7672720dc..8add632140 100644 --- a/voxygen/src/audio/soundcache.rs +++ b/voxygen/src/audio/soundcache.rs @@ -3,6 +3,7 @@ use common::assets; use hashbrown::HashMap; use std::{convert::AsRef, io, io::Read, sync::Arc}; +use tracing::warn; // Implementation of sound taken from this github issue: // https://github.com/RustAudio/rodio/issues/141 @@ -52,7 +53,7 @@ impl SoundCache { .entry(name.to_string()) .or_insert_with(|| { Sound::load(name).unwrap_or_else(|_| { - log::warn!("SoundCache: Failed to load sound: {}", name); + warn!("SoundCache: Failed to load sound: {}", name); Sound::empty() }) diff --git a/voxygen/src/ecs/sys/interpolation.rs b/voxygen/src/ecs/sys/interpolation.rs index fa48e15504..9d7307e758 100644 --- a/voxygen/src/ecs/sys/interpolation.rs +++ b/voxygen/src/ecs/sys/interpolation.rs @@ -4,8 +4,8 @@ use common::{ state::DeltaTime, util::Dir, }; -use log::warn; use specs::{Entities, Join, Read, ReadStorage, System, WriteStorage}; +use tracing::warn; use vek::*; /// This system will allow NPCs to modify their controller diff --git a/voxygen/src/hud/item_imgs.rs b/voxygen/src/hud/item_imgs.rs index 3b6434d73a..40c9d98c36 100644 --- a/voxygen/src/hud/item_imgs.rs +++ b/voxygen/src/hud/item_imgs.rs @@ -12,9 +12,9 @@ use conrod_core::image::Id; use dot_vox::DotVoxData; use hashbrown::HashMap; use image::DynamicImage; -use log::{error, warn}; use serde_derive::{Deserialize, Serialize}; use std::{fs::File, io::BufReader, sync::Arc}; +use tracing::{error, warn}; use vek::*; #[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)] diff --git a/voxygen/src/i18n.rs b/voxygen/src/i18n.rs index 9e8a14573b..57b6a376e7 100644 --- a/voxygen/src/i18n.rs +++ b/voxygen/src/i18n.rs @@ -10,6 +10,7 @@ use std::{ fs::File, io::BufReader, }; +use tracing::warn; /// The reference language, aka the more up-to-date localization data. /// Also the default language at first startup. @@ -124,17 +125,15 @@ impl VoxygenLocalization { pub fn log_missing_entries(&self) { let (missing_strings, missing_vectors) = self.list_missing_entries(); for missing_key in missing_strings { - log::warn!( + warn!( "[{:?}] Missing string key {:?}", - self.metadata.language_identifier, - missing_key + self.metadata.language_identifier, missing_key ); } for missing_key in missing_vectors { - log::warn!( + warn!( "[{:?}] Missing vector key {:?}", - self.metadata.language_identifier, - missing_key + self.metadata.language_identifier, missing_key ); } } diff --git a/voxygen/src/logging.rs b/voxygen/src/logging.rs index fd292bbd74..f96dfdca7b 100644 --- a/voxygen/src/logging.rs +++ b/voxygen/src/logging.rs @@ -1,82 +1,79 @@ -use fern::colors::{Color, ColoredLevelConfig}; use std::fs; use crate::settings::Settings; -#[allow(clippy::or_fun_call)] // TODO: Pending review in #587 -pub fn init( - settings: &Settings, - term_log_level: log::LevelFilter, - file_log_level: log::LevelFilter, -) { - let colors = ColoredLevelConfig::new() - .error(Color::Red) - .warn(Color::Yellow) - .info(Color::Cyan) - .debug(Color::Green) - .trace(Color::BrightBlack); +use tracing::{error, info, instrument}; +use tracing_subscriber::{filter::LevelFilter, prelude::*, registry, EnvFilter}; - let mut base = fern::Dispatch::new() - .level_for("dot_vox::parser", log::LevelFilter::Warn) - .level_for("gfx_device_gl::factory", log::LevelFilter::Warn) - .level_for("uvth", log::LevelFilter::Warn) - .level_for("tiny_http", log::LevelFilter::Warn); +const VOXYGEN_LOG_ENV: &str = "VOXYGEN_LOG"; - let time = chrono::offset::Utc::now(); +/// Initialise tracing and logging fro the settings. +/// +/// This function will attempt to set up both a file and a terminal logger, +/// falling back to just a terminal logger if the file is unable to be created. +/// +/// The logging level is by deafult set to `INFO`, to change this for any +/// particular crate or module you must use the `VOXYGEN_LOG` environment +/// variable. +/// +/// For example to set this crate's debug level to `TRACE` you would need the +/// following in your environment. +/// +/// `VOXYGEN_LOG="veloren_voxygen=trace"` +#[instrument] +pub fn init(settings: &Settings) -> Vec { + // To hold the guards that we create, they will cause the logs to be + // flushed when they're dropped. + let mut _guards = vec![]; - let mut file_cfg = - fern::Dispatch::new() - .level(file_log_level) - .format(|out, message, record| { - out.finish(format_args!( - "{}[{}:{}][{}] {}", - chrono::Local::now().format("[%Y-%m-%d][%H:%M:%S]"), - record.target(), - record - .line() - .map(|x| x.to_string()) - .unwrap_or("X".to_string()), - record.level(), - message - )) - }); + // We will do lower logging than the default (INFO) by INCLUSION. This + // means that if you need lower level logging for a specific module, then + // put it in the environment in the correct format i.e. DEBUG logging for + // this crate with would be veloren_voxygen=debug. + let filter = EnvFilter::from_env(VOXYGEN_LOG_ENV) + .add_directive("dot_vox::parser=warn".parse().unwrap()) + .add_directive("gfx_device_gl::factory=warn".parse().unwrap()) + .add_directive("gfx_device_gl::shade=warn".parse().unwrap()) + .add_directive("uvth=warn".parse().unwrap()) + .add_directive("tiny_http=warn".parse().unwrap()) + .add_directive(LevelFilter::INFO.into()); - // Try to create the logs file parent directories. - let mut log_file_created = fs::create_dir_all(&settings.log.logs_path); + // Create the terminal writer layer. + let (non_blocking, _stdio_guard) = tracing_appender::non_blocking(std::io::stdout()); + _guards.push(_stdio_guard); - if log_file_created.is_ok() { - // Try to create the log file. - match fern::log_file( - settings - .log - .logs_path - .join(&format!("voxygen-{}.log", time.format("%Y-%m-%d-%H"))), - ) { - Ok(log_file) => file_cfg = file_cfg.chain(log_file), - Err(e) => log_file_created = Err(e), - } - } + // Try to create the log file's parent folders. + let log_folders_created = fs::create_dir_all(&settings.log.logs_path); - let stdout_cfg = fern::Dispatch::new() - .level(term_log_level) - .format(move |out, message, record| { - out.finish(format_args!( - "[{}] {}", - colors.color(record.level()), - message - )) - }) - .chain(std::io::stdout()); + match log_folders_created { + // If the parent folders were created then attach both a terminal and a + // file writer to the registry and init it. + Ok(_) => { + let file_appender = + tracing_appender::rolling::daily(&settings.log.logs_path, "voxygen.log"); + let (non_blocking_file, _file_guard) = tracing_appender::non_blocking(file_appender); + _guards.push(_file_guard); + registry() + .with(tracing_subscriber::fmt::layer().with_writer(non_blocking)) + .with(tracing_subscriber::fmt::layer().with_writer(non_blocking_file)) + .with(filter) + .init(); + info!("Setup terminal and file logging."); + }, + // Otherwise just add a terminal writer and init it. + Err(e) => { + error!( + "Failed to create log file! {}. Falling back to terminal logging only.", + e + ); + registry() + .with(tracing_subscriber::fmt::layer().with_writer(non_blocking)) + .with(filter) + .init(); + info!("Setup terminal logging."); + }, + }; - if settings.log.log_to_file { - base = base.chain(file_cfg); - } - base.chain(stdout_cfg) - .apply() - .expect("Failed to setup logging!"); - - // Incase that the log file creation failed simply print it to the console - if let Err(e) = log_file_created { - log::error!("Failed to create log file! {}", e); - } + // Return the guards + _guards } diff --git a/voxygen/src/main.rs b/voxygen/src/main.rs index 2f2b37ec20..eae9810bb4 100644 --- a/voxygen/src/main.rs +++ b/voxygen/src/main.rs @@ -15,34 +15,25 @@ use veloren_voxygen::{ }; use common::assets::{load, load_expect}; -use log::{debug, error}; -use std::{mem, panic, str::FromStr}; +use std::{mem, panic}; +use tracing::{debug, error, instrument, warn}; +#[instrument] fn main() { #[cfg(feature = "tweak")] const_tweaker::run().expect("Could not run server"); - // Initialize logging. - let term_log_level = std::env::var_os("VOXYGEN_LOG") - .and_then(|env| env.to_str().map(|s| s.to_owned())) - .and_then(|s| log::LevelFilter::from_str(&s).ok()) - .unwrap_or(log::LevelFilter::Warn); - - let file_log_level = std::env::var_os("VOXYGEN_FILE_LOG") - .and_then(|env| env.to_str().map(|s| s.to_owned())) - .and_then(|s| log::LevelFilter::from_str(&s).ok()) - .unwrap_or(log::LevelFilter::Debug); // Load the settings // Note: This won't log anything due to it being called before - // ``logging::init``. The issue is we need to read a setting to decide + // `logging::init`. The issue is we need to read a setting to decide // whether we create a log file or not. let settings = Settings::load(); - let profile = Profile::load(); + // Init logging and hold the guards. + let _guards = logging::init(&settings); - logging::init(&settings, term_log_level, file_log_level); - - // Save settings to add new fields or create the file if it is not already there + // Save settings to add new fields or create the file if it is not already + // there. if let Err(err) = settings.save_to_file() { panic!("Failed to save settings: {:?}", err); } @@ -58,6 +49,9 @@ fn main() { audio.set_music_volume(settings.audio.music_volume); audio.set_sfx_volume(settings.audio.sfx_volume); + // Load the profile. + let profile = Profile::load(); + let mut global_state = GlobalState { audio, profile, @@ -72,11 +66,10 @@ fn main() { &global_state.settings.language.selected_language, )) .unwrap_or_else(|error| { - log::warn!( + warn!( "Impossible to load {} language: change to the default language (English) instead. \ Source error: {:?}", - &global_state.settings.language.selected_language, - error + &global_state.settings.language.selected_language, error ); global_state.settings.language.selected_language = i18n::REFERENCE_LANG.to_owned(); load_expect::(&i18n_asset_key( diff --git a/voxygen/src/menu/char_selection/mod.rs b/voxygen/src/menu/char_selection/mod.rs index 8d82f7b4f7..722fa3d431 100644 --- a/voxygen/src/menu/char_selection/mod.rs +++ b/voxygen/src/menu/char_selection/mod.rs @@ -9,9 +9,9 @@ use crate::{ }; use client::{self, Client}; use common::{assets, clock::Clock, comp, msg::ClientState, state::DeltaTime}; -use log::error; use specs::WorldExt; use std::{cell::RefCell, rc::Rc, time::Duration}; +use tracing::error; use ui::CharSelectionUi; pub struct CharSelectionState { diff --git a/voxygen/src/menu/main/mod.rs b/voxygen/src/menu/main/mod.rs index 3d7b3d2c58..8ff712f37f 100644 --- a/voxygen/src/menu/main/mod.rs +++ b/voxygen/src/menu/main/mod.rs @@ -7,9 +7,9 @@ use crate::{ }; use client_init::{ClientInit, Error as InitError, Msg as InitMsg}; use common::{assets::load_expect, clock::Clock, comp}; -use log::{error, warn}; #[cfg(feature = "singleplayer")] use std::time::Duration; +use tracing::{error, warn}; use ui::{Event as MainMenuEvent, MainMenuUi}; pub struct MainMenuState { diff --git a/voxygen/src/meta.rs b/voxygen/src/meta.rs index 71d66087f9..d3e568b790 100644 --- a/voxygen/src/meta.rs +++ b/voxygen/src/meta.rs @@ -1,8 +1,8 @@ use common::comp; use directories::ProjectDirs; -use log::warn; use serde_derive::{Deserialize, Serialize}; use std::{fs, io::Write, path::PathBuf}; +use tracing::warn; const VALID_VERSION: u32 = 0; // Change this if you broke charsaves #[derive(Clone, Debug, Serialize, Deserialize)] @@ -47,13 +47,13 @@ impl Meta { } }, Err(e) => { - log::warn!("Failed to parse meta file! Fallback to default. {}", e); + warn!("Failed to parse meta file! Fallback to default. {}", e); // Rename the corrupted settings file let mut new_path = path.to_owned(); new_path.pop(); new_path.push("meta.invalid.ron"); if let Err(err) = std::fs::rename(path, new_path) { - log::warn!("Failed to rename meta file. {}", err); + warn!("Failed to rename meta file. {}", err); } }, } @@ -90,7 +90,7 @@ impl Meta { if meta.exists() || meta.parent().map(|x| x.exists()).unwrap_or(false) { return meta; } - log::warn!("VOXYGEN_CONFIG points to invalid path."); + warn!("VOXYGEN_CONFIG points to invalid path."); } let proj_dirs = ProjectDirs::from("net", "veloren", "voxygen") diff --git a/voxygen/src/profile.rs b/voxygen/src/profile.rs index b4193041dc..bdfd8c5386 100644 --- a/voxygen/src/profile.rs +++ b/voxygen/src/profile.rs @@ -1,9 +1,9 @@ use crate::hud; use directories::ProjectDirs; use hashbrown::HashMap; -use log::warn; use serde_derive::{Deserialize, Serialize}; use std::{fs, io::prelude::*, path::PathBuf}; +use tracing::warn; /// Represents a character in the profile. #[derive(Clone, Debug, Serialize, Deserialize)] @@ -65,14 +65,14 @@ impl Profile { match ron::de::from_reader(file) { Ok(profile) => return profile, Err(e) => { - log::warn!( + warn!( "Failed to parse profile file! Falling back to default. {}", e ); // Rename the corrupted profile file. let new_path = path.with_extension("invalid.ron"); if let Err(err) = std::fs::rename(path, new_path) { - log::warn!("Failed to rename profile file. {}", err); + warn!("Failed to rename profile file. {}", err); } }, } @@ -161,7 +161,7 @@ impl Profile { if profile.exists() || profile.parent().map(|x| x.exists()).unwrap_or(false) { return profile; } - log::warn!("VOXYGEN_CONFIG points to invalid path."); + warn!("VOXYGEN_CONFIG points to invalid path."); } let proj_dirs = ProjectDirs::from("net", "veloren", "voxygen") diff --git a/voxygen/src/render/renderer.rs b/voxygen/src/render/renderer.rs index 9dd874c083..4d471b2f58 100644 --- a/voxygen/src/render/renderer.rs +++ b/voxygen/src/render/renderer.rs @@ -16,7 +16,7 @@ use gfx::{ traits::{Device, Factory, FactoryExt}, }; use glsl_include::Context as IncludeContext; -use log::error; +use tracing::error; use vek::*; /// Represents the format of the pre-processed color target. diff --git a/voxygen/src/scene/figure/load.rs b/voxygen/src/scene/figure/load.rs index d4ea8ccc41..5ca885024a 100644 --- a/voxygen/src/scene/figure/load.rs +++ b/voxygen/src/scene/figure/load.rs @@ -24,9 +24,9 @@ use common::{ }; use dot_vox::DotVoxData; use hashbrown::HashMap; -use log::{error, warn}; use serde_derive::{Deserialize, Serialize}; use std::{fs::File, io::BufReader, sync::Arc}; +use tracing::{error, warn}; use vek::*; fn load_segment(mesh_name: &str) -> Segment { diff --git a/voxygen/src/scene/figure/mod.rs b/voxygen/src/scene/figure/mod.rs index 0408cbc275..eb5ed03ddc 100644 --- a/voxygen/src/scene/figure/mod.rs +++ b/voxygen/src/scene/figure/mod.rs @@ -30,8 +30,8 @@ use common::{ vol::RectRasterableVol, }; use hashbrown::HashMap; -use log::trace; use specs::{Entity as EcsEntity, Join, WorldExt}; +use tracing::trace; use treeculler::{BVol, BoundingSphere}; use vek::*; diff --git a/voxygen/src/scene/simple.rs b/voxygen/src/scene/simple.rs index 22e971d1ed..e210493bef 100644 --- a/voxygen/src/scene/simple.rs +++ b/voxygen/src/scene/simple.rs @@ -21,7 +21,7 @@ use common::{ terrain::BlockKind, vol::{BaseVol, ReadVol, Vox}, }; -use log::error; +use tracing::error; use vek::*; #[derive(PartialEq, Eq, Copy, Clone)] diff --git a/voxygen/src/session.rs b/voxygen/src/session.rs index 8afd79201b..5052536989 100644 --- a/voxygen/src/session.rs +++ b/voxygen/src/session.rs @@ -21,9 +21,9 @@ use common::{ vol::ReadVol, ChatType, }; -use log::{error, info}; use specs::{Join, WorldExt}; use std::{cell::RefCell, rc::Rc, time::Duration}; +use tracing::{error, info}; use vek::*; /// The action to perform after a tick @@ -761,7 +761,7 @@ impl PlayState for SessionState { global_state.profile.save_to_file_warn(); - log::info!("Event! -> ChangedHotbarState") + info!("Event! -> ChangedHotbarState") }, HudEvent::Ability3(state) => self.inputs.ability3.set_state(state), HudEvent::ChangeFOV(new_fov) => { diff --git a/voxygen/src/settings.rs b/voxygen/src/settings.rs index 290e97bcd4..ef16948655 100644 --- a/voxygen/src/settings.rs +++ b/voxygen/src/settings.rs @@ -8,9 +8,9 @@ use crate::{ use directories::{ProjectDirs, UserDirs}; use glutin::{MouseButton, VirtualKeyCode}; use hashbrown::{HashMap, HashSet}; -use log::warn; use serde_derive::{Deserialize, Serialize}; use std::{fs, io::prelude::*, path::PathBuf}; +use tracing::warn; // ControlSetting-like struct used by Serde, to handle not serializing/building // post-deserializing the inverse_keybindings hashmap @@ -718,13 +718,13 @@ impl Settings { match ron::de::from_reader(file) { Ok(s) => return s, Err(e) => { - log::warn!("Failed to parse setting file! Fallback to default. {}", e); + warn!("Failed to parse setting file! Fallback to default. {}", e); // Rename the corrupted settings file let mut new_path = path.to_owned(); new_path.pop(); new_path.push("settings.invalid.ron"); if let Err(err) = std::fs::rename(path, new_path) { - log::warn!("Failed to rename settings file. {}", err); + warn!("Failed to rename settings file. {}", err); } }, } @@ -761,7 +761,7 @@ impl Settings { if settings.exists() || settings.parent().map(|x| x.exists()).unwrap_or(false) { return settings; } - log::warn!("VOXYGEN_CONFIG points to invalid path."); + warn!("VOXYGEN_CONFIG points to invalid path."); } let proj_dirs = ProjectDirs::from("net", "veloren", "voxygen") diff --git a/voxygen/src/singleplayer.rs b/voxygen/src/singleplayer.rs index b9c833fed6..aee967caf4 100644 --- a/voxygen/src/singleplayer.rs +++ b/voxygen/src/singleplayer.rs @@ -1,7 +1,6 @@ use client::Client; use common::clock::Clock; use crossbeam::channel::{unbounded, Receiver, Sender, TryRecvError}; -use log::info; use server::{Event, Input, Server, ServerSettings}; use std::{ sync::{ @@ -11,6 +10,7 @@ use std::{ thread::{self, JoinHandle}, time::Duration, }; +use tracing::info; const TPS: u64 = 30; diff --git a/voxygen/src/ui/graphic/mod.rs b/voxygen/src/ui/graphic/mod.rs index acb3aa5be3..78c534036e 100644 --- a/voxygen/src/ui/graphic/mod.rs +++ b/voxygen/src/ui/graphic/mod.rs @@ -8,9 +8,9 @@ use common::figure::Segment; use guillotiere::{size2, SimpleAtlasAllocator}; use hashbrown::{hash_map::Entry, HashMap}; use image::{DynamicImage, RgbaImage}; -use log::warn; use pixel_art::resize_pixel_art; use std::sync::Arc; +use tracing::warn; use vek::*; #[derive(Clone)] diff --git a/voxygen/src/ui/mod.rs b/voxygen/src/ui/mod.rs index c46a438b5b..21d490c799 100644 --- a/voxygen/src/ui/mod.rs +++ b/voxygen/src/ui/mod.rs @@ -44,7 +44,6 @@ use conrod_core::{ Rect, UiBuilder, UiCell, }; use graphic::{Rotation, TexId}; -use log::{error, warn}; use std::{ f32, f64, fs::File, @@ -53,6 +52,7 @@ use std::{ sync::Arc, time::Duration, }; +use tracing::{error, warn}; use vek::*; #[derive(Debug)] diff --git a/voxygen/src/window.rs b/voxygen/src/window.rs index 5e9e8b2ed8..e8740663de 100644 --- a/voxygen/src/window.rs +++ b/voxygen/src/window.rs @@ -8,9 +8,9 @@ use gilrs::{EventType, Gilrs}; use hashbrown::HashMap; use crossbeam::channel; -use log::{error, warn}; use serde_derive::{Deserialize, Serialize}; use std::fmt; +use tracing::{error, warn}; use vek::*; /// Represents a key that the game recognises after input mapping.