fix server-cli tracing accepting RUST_LOG env var and pass RUST_LOG via docker-compose rather than hardcoding it

- however RUST_BACKTRACE=1 is still hardcoded as its probably useful
- dont spam the server-cli with debug
This commit is contained in:
Marcel Märtens 2020-06-29 10:53:43 +02:00
parent 807df57f64
commit c558c9de7c
4 changed files with 30 additions and 8 deletions

View File

@ -13,4 +13,4 @@ server = { package = "veloren-server", path = "../server", default-features = fa
common = { package = "veloren-common", path = "../common" }
tracing = { version = "0.1", default-features = false }
tracing-subscriber = { version = "0.2.3", default-features = false, features = ["fmt", "chrono", "ansi", "smallvec"] }
tracing-subscriber = { version = "0.2.3", default-features = false, features = ["env-filter", "fmt", "chrono", "ansi", "smallvec"] }

View File

@ -13,4 +13,4 @@ COPY ./assets/common /opt/assets/common
COPY ./assets/world /opt/assets/world
WORKDIR /opt
CMD [ "sh", "-c", "RUST_LOG=info,common=debug,common::net=info RUST_BACKTRACE=1 /opt/veloren-server-cli" ]
CMD [ "sh", "-c", "RUST_BACKTRACE=1 /opt/veloren-server-cli" ]

View File

@ -10,6 +10,8 @@ services:
restart: on-failure:0
volumes:
- "./saves:/opt/saves"
environment:
- RUST_LOG=debug,common::net=info
watchtower:
image: containrrr/watchtower
volumes:

View File

@ -4,18 +4,38 @@
use common::clock::Clock;
use server::{Event, Input, Server, ServerSettings};
use std::time::Duration;
use tracing::info;
use tracing::{info, Level};
use tracing_subscriber::{filter::LevelFilter, EnvFilter, FmtSubscriber};
const TPS: u64 = 30;
const RUST_LOG_ENV: &str = "RUST_LOG";
#[allow(clippy::redundant_pattern_matching)] // TODO: Pending review in #587
fn main() {
// Init logging
if let Err(_) = std::env::var("RUST_LOG") {
std::env::set_var("RUST_LOG", "info");
let filter = match std::env::var_os(RUST_LOG_ENV).map(|s| s.into_string()) {
Some(Ok(env)) => {
let mut filter = EnvFilter::new("veloren_world::sim=info")
.add_directive("veloren_world::civ=info".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("veloren_world::sim=info".parse().unwrap())
.add_directive("veloren_world::civ=info".parse().unwrap())
.add_directive(LevelFilter::INFO.into()),
};
tracing_subscriber::fmt::init();
FmtSubscriber::builder()
.with_max_level(Level::ERROR)
.with_env_filter(filter)
.init();
info!("Starting server...");