diff --git a/server-cli/Cargo.toml b/server-cli/Cargo.toml index 2f46bb8e13..96d761b3e3 100644 --- a/server-cli/Cargo.toml +++ b/server-cli/Cargo.toml @@ -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"] } diff --git a/server-cli/Dockerfile b/server-cli/Dockerfile index 319362c180..3cb85181f9 100644 --- a/server-cli/Dockerfile +++ b/server-cli/Dockerfile @@ -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" ] diff --git a/server-cli/docker-compose.yml b/server-cli/docker-compose.yml index 19b946f0f1..8c81a5c7ef 100644 --- a/server-cli/docker-compose.yml +++ b/server-cli/docker-compose.yml @@ -10,8 +10,10 @@ services: restart: on-failure:0 volumes: - "./saves:/opt/saves" + environment: + - RUST_LOG=debug,common::net=info watchtower: image: containrrr/watchtower volumes: - /var/run/docker.sock:/var/run/docker.sock - command: --interval 30 --cleanup veloren-game-server-master \ No newline at end of file + command: --interval 30 --cleanup veloren-game-server-master diff --git a/server-cli/src/main.rs b/server-cli/src/main.rs index 9e02da5b59..d790383a1e 100644 --- a/server-cli/src/main.rs +++ b/server-cli/src/main.rs @@ -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...");