switch log behavior for env variable and removed gfx spam by default

This commit is contained in:
Marcel Märtens 2020-06-22 15:34:35 +02:00
parent f2f3cd2f28
commit 79feb6dceb
4 changed files with 59 additions and 18 deletions

View File

@ -14,7 +14,7 @@ use std::{
path::PathBuf,
sync::{Arc, RwLock},
};
use tracing::{trace, error};
use tracing::{error, trace};
/// The error returned by asset loading functions
#[derive(Debug, Clone)]

View File

@ -5,21 +5,30 @@ use crate::settings::Settings;
use tracing::{error, info};
use tracing_subscriber::{filter::LevelFilter, prelude::*, registry, EnvFilter};
const VOXYGEN_LOG_ENV: &str = "VOXYGEN_LOG";
const RUST_LOG_ENV: &str = "RUST_LOG";
/// Initialise tracing and logging fro the settings.
/// Initialise tracing and logging for 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
/// The logging level is by default set to `INFO`, to change this for any
/// particular crate or module you must use the `RUST_LOG` environment
/// variable.
///
/// For example to set this crate's debug level to `TRACE` you would need the
/// following in your environment.
/// `RUST_LOG="veloren_voxygen=trace"`
///
/// `VOXYGEN_LOG="veloren_voxygen=trace"`
/// more complex tracing can be done by concatenating with a `,` as seperator:
/// - warn for `uvth`, `tiny_http`, `dot_vox`, `gfx_device_gl::factory,
/// `gfx_device_gl::shade` trace for `veloren_voxygen`, info for everything
/// else
/// `RUST_LOG="uvth=warn,tiny_http=warn,dot_vox::parser=warn,gfx_device_gl::
/// factory=warn,gfx_device_gl::shade=warn,veloren_voxygen=trace,info"`
///
/// By default a few directives are set to `warn` by default, until explicitly
/// overwritten! e.g. `RUST_LOG="uvth=debug"`
pub fn init(settings: &Settings) -> Vec<impl Drop> {
// To hold the guards that we create, they will cause the logs to be
// flushed when they're dropped.
@ -28,14 +37,30 @@ pub fn init(settings: &Settings) -> Vec<impl Drop> {
// 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());
// this crate would be veloren_voxygen=debug.
let filter = match std::env::var_os(RUST_LOG_ENV).map(|s| s.into_string()) {
Some(Ok(env)) => {
let mut filter = EnvFilter::new("dot_vox::parser=warn")
.add_directive("gfx_device_gl=warn".parse().unwrap())
.add_directive("uvth=warn".parse().unwrap())
.add_directive("tiny_http=warn".parse().unwrap())
.add_directive(LevelFilter::INFO.into());
for s in env.split(',').into_iter() {
match s.parse() {
Ok(d) => filter = filter.add_directive(d),
Err(err) => println!("WARN ignoring log directive: `{}`: {}", s, err),
};
}
filter
},
_ => EnvFilter::from_env(RUST_LOG_ENV)
.add_directive("dot_vox::parser=warn".parse().unwrap())
.add_directive("gfx_device_gl=warn".parse().unwrap())
.add_directive("uvth=warn".parse().unwrap())
.add_directive("tiny_http=warn".parse().unwrap())
.add_directive(LevelFilter::INFO.into()),
};
// Create the terminal writer layer.
let (non_blocking, _stdio_guard) = tracing_appender::non_blocking(std::io::stdout());

View File

@ -10,7 +10,7 @@ use hashbrown::HashMap;
use crossbeam::channel;
use serde_derive::{Deserialize, Serialize};
use std::fmt;
use tracing::{error, warn};
use tracing::{error, info, warn};
use vek::*;
/// Represents a key that the game recognises after input mapping.
@ -429,6 +429,18 @@ impl Window {
)
.map_err(|err| Error::BackendError(Box::new(err)))?;
let vendor = device.get_info().platform_name.vendor;
let renderer = device.get_info().platform_name.renderer;
let opengl_version = device.get_info().version;
let glsl_version = device.get_info().shading_language;
info!(
?vendor,
?renderer,
?opengl_version,
?glsl_version,
"selected graphics device"
);
let keypress_map = HashMap::new();
let gilrs = match Gilrs::new() {

View File

@ -25,7 +25,7 @@ use fxhash::{FxHasher32, FxHasher64};
use hashbrown::{HashMap, HashSet};
use rand::prelude::*;
use rand_chacha::ChaChaRng;
use tracing::{info, warn};
use tracing::{debug, info, warn};
use vek::*;
const INITIAL_CIV_COUNT: usize = (crate::sim::WORLD_SIZE.x * crate::sim::WORLD_SIZE.y * 3) / 65536; //48 at default scale
@ -77,11 +77,12 @@ impl Civs {
let mut ctx = GenCtx { sim, rng };
for _ in 0..INITIAL_CIV_COUNT {
info!("Creating civilisation...");
debug!("Creating civilisation...");
if this.birth_civ(&mut ctx.reseed()).is_none() {
warn!("Failed to find starting site for civilisation.");
}
}
info!(?INITIAL_CIV_COUNT, "all civilisations created");
for _ in 0..INITIAL_CIV_COUNT * 3 {
attempt(5, || {
@ -160,7 +161,9 @@ impl Civs {
}
// Place sites in world
let mut cnt = 0;
for site in this.sites.iter() {
cnt += 1;
let wpos = site
.center
.map2(Vec2::from(TerrainChunkSize::RECT_SIZE), |e, sz: u32| {
@ -187,8 +190,9 @@ impl Civs {
.get_mut(pos)
.map(|chunk| chunk.sites.push(world_site.clone()));
}
info!(?site.center, "Placed site at location");
debug!(?site.center, "Placed site at location");
}
info!(?cnt, "all sites placed");
//this.display_info();