mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
move tracing code to own crate
This commit is contained in:
parent
3c19713e63
commit
ccb78eeb5c
25
Cargo.lock
generated
25
Cargo.lock
generated
@ -5342,11 +5342,11 @@ dependencies = [
|
|||||||
"termcolor",
|
"termcolor",
|
||||||
"tokio",
|
"tokio",
|
||||||
"tracing",
|
"tracing",
|
||||||
"tracing-subscriber",
|
|
||||||
"vek",
|
"vek",
|
||||||
"veloren-common",
|
"veloren-common",
|
||||||
"veloren-common-base",
|
"veloren-common-base",
|
||||||
"veloren-common-ecs",
|
"veloren-common-ecs",
|
||||||
|
"veloren-common-frontend",
|
||||||
"veloren-common-net",
|
"veloren-common-net",
|
||||||
"veloren-common-sys",
|
"veloren-common-sys",
|
||||||
"veloren-network",
|
"veloren-network",
|
||||||
@ -5411,6 +5411,19 @@ dependencies = [
|
|||||||
"veloren-common-base",
|
"veloren-common-base",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "veloren-common-frontend"
|
||||||
|
version = "0.9.0"
|
||||||
|
dependencies = [
|
||||||
|
"termcolor",
|
||||||
|
"tracing",
|
||||||
|
"tracing-appender",
|
||||||
|
"tracing-log",
|
||||||
|
"tracing-subscriber",
|
||||||
|
"tracing-tracy",
|
||||||
|
"veloren-common-base",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "veloren-common-net"
|
name = "veloren-common-net"
|
||||||
version = "0.9.0"
|
version = "0.9.0"
|
||||||
@ -5575,14 +5588,12 @@ dependencies = [
|
|||||||
"ron",
|
"ron",
|
||||||
"serde",
|
"serde",
|
||||||
"signal-hook 0.3.7",
|
"signal-hook 0.3.7",
|
||||||
"termcolor",
|
|
||||||
"tokio",
|
"tokio",
|
||||||
"tracing",
|
"tracing",
|
||||||
"tracing-subscriber",
|
|
||||||
"tracing-tracy",
|
|
||||||
"tui",
|
"tui",
|
||||||
"veloren-common",
|
"veloren-common",
|
||||||
"veloren-common-base",
|
"veloren-common-base",
|
||||||
|
"veloren-common-frontend",
|
||||||
"veloren-common-net",
|
"veloren-common-net",
|
||||||
"veloren-server",
|
"veloren-server",
|
||||||
]
|
]
|
||||||
@ -5634,19 +5645,15 @@ dependencies = [
|
|||||||
"serde",
|
"serde",
|
||||||
"specs",
|
"specs",
|
||||||
"specs-idvs",
|
"specs-idvs",
|
||||||
"termcolor",
|
|
||||||
"tokio",
|
"tokio",
|
||||||
"tracing",
|
"tracing",
|
||||||
"tracing-appender",
|
|
||||||
"tracing-log",
|
|
||||||
"tracing-subscriber",
|
|
||||||
"tracing-tracy",
|
|
||||||
"treeculler",
|
"treeculler",
|
||||||
"vek",
|
"vek",
|
||||||
"veloren-client",
|
"veloren-client",
|
||||||
"veloren-common",
|
"veloren-common",
|
||||||
"veloren-common-base",
|
"veloren-common-base",
|
||||||
"veloren-common-ecs",
|
"veloren-common-ecs",
|
||||||
|
"veloren-common-frontend",
|
||||||
"veloren-common-net",
|
"veloren-common-net",
|
||||||
"veloren-common-sys",
|
"veloren-common-sys",
|
||||||
"veloren-server",
|
"veloren-server",
|
||||||
|
@ -7,6 +7,7 @@ members = [
|
|||||||
"common/ecs",
|
"common/ecs",
|
||||||
"common/net",
|
"common/net",
|
||||||
"common/sys",
|
"common/sys",
|
||||||
|
"common/frontend",
|
||||||
"client",
|
"client",
|
||||||
"plugin/api",
|
"plugin/api",
|
||||||
"plugin/derive",
|
"plugin/derive",
|
||||||
|
@ -5,10 +5,10 @@ authors = ["Joshua Barretto <joshua.s.barretto@gmail.com>"]
|
|||||||
edition = "2018"
|
edition = "2018"
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
tracy = ["common/tracy", "common-base/tracy", "common-sys/tracy", "common-net/tracy"]
|
tracy = ["common/tracy", "common-base/tracy", "common-sys/tracy", "common-net/tracy", "common-frontend/tracy"]
|
||||||
simd = ["vek/platform_intrinsics"]
|
simd = ["vek/platform_intrinsics"]
|
||||||
plugins = ["common-sys/plugins"]
|
plugins = ["common-sys/plugins"]
|
||||||
bin_bot = ["common-ecs", "serde", "ron", "clap", "rustyline", "termcolor", "tracing-subscriber", "async-channel"]
|
bin_bot = ["common-ecs", "serde", "ron", "clap", "rustyline", "common-frontend", "async-channel"]
|
||||||
|
|
||||||
default = ["simd"]
|
default = ["simd"]
|
||||||
|
|
||||||
@ -40,13 +40,13 @@ clap = { version = "2.33", optional = true }
|
|||||||
rustyline = { version = "8.0.0", optional = true }
|
rustyline = { version = "8.0.0", optional = true }
|
||||||
## logging
|
## logging
|
||||||
termcolor = { version = "1.1", optional = true }
|
termcolor = { version = "1.1", optional = true }
|
||||||
tracing-subscriber = {version = "0.2.3", default-features = false, features = ["env-filter", "fmt", "chrono", "ansi", "smallvec", "tracing-log"], optional = true }
|
common-frontend = { package = "veloren-common-frontend", path = "../common/frontend", optional = true }
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
tracing-subscriber = { version = "0.2.3", default-features = false, features = ["fmt", "chrono", "ansi", "smallvec"] }
|
|
||||||
|
|
||||||
[[example]]
|
[[example]]
|
||||||
name = "chat-cli"
|
name = "chat-cli"
|
||||||
|
required-features = ["bin_bot"]
|
||||||
|
|
||||||
[[bin]]
|
[[bin]]
|
||||||
name = "bot"
|
name = "bot"
|
||||||
|
@ -27,7 +27,7 @@ fn read_input() -> String {
|
|||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
// Initialize logging.
|
// Initialize logging.
|
||||||
tracing_subscriber::fmt::init();
|
common_frontend::init_stdout(None);
|
||||||
|
|
||||||
info!("Starting chat-cli...");
|
info!("Starting chat-cli...");
|
||||||
|
|
||||||
|
@ -24,7 +24,7 @@ pub struct BotCreds {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn main() {
|
pub fn main() {
|
||||||
tui::init_logging();
|
common_frontend::init_stdout(None);
|
||||||
|
|
||||||
let settings = Settings::load();
|
let settings = Settings::load();
|
||||||
info!("Settings: {:?}", settings);
|
info!("Settings: {:?}", settings);
|
||||||
|
@ -2,21 +2,6 @@ use clap::{App, AppSettings, Arg, SubCommand};
|
|||||||
use std::{thread, time::Duration};
|
use std::{thread, time::Duration};
|
||||||
use tracing::error;
|
use tracing::error;
|
||||||
|
|
||||||
pub fn init_logging() {
|
|
||||||
use termcolor::{ColorChoice, StandardStream};
|
|
||||||
use tracing::Level;
|
|
||||||
use tracing_subscriber::{filter::LevelFilter, EnvFilter, FmtSubscriber};
|
|
||||||
const RUST_LOG_ENV: &str = "RUST_LOG";
|
|
||||||
let filter = EnvFilter::from_env(RUST_LOG_ENV).add_directive(LevelFilter::INFO.into());
|
|
||||||
let subscriber = FmtSubscriber::builder()
|
|
||||||
.with_max_level(Level::ERROR)
|
|
||||||
.with_env_filter(filter);
|
|
||||||
|
|
||||||
subscriber
|
|
||||||
.with_writer(|| StandardStream::stdout(ColorChoice::Auto))
|
|
||||||
.init();
|
|
||||||
}
|
|
||||||
|
|
||||||
pub enum Cmd {
|
pub enum Cmd {
|
||||||
Register {
|
Register {
|
||||||
prefix: String,
|
prefix: String,
|
||||||
|
22
common/frontend/Cargo.toml
Normal file
22
common/frontend/Cargo.toml
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
[package]
|
||||||
|
authors = ["Marcel Märtens <marcel.cochem@googlemail.com>", "Imbris <imbrisf@gmail.com>"]
|
||||||
|
edition = "2018"
|
||||||
|
name = "veloren-common-frontend"
|
||||||
|
description = "common stuff that is used by server-cli and voxygen directly"
|
||||||
|
version = "0.9.0"
|
||||||
|
|
||||||
|
[features]
|
||||||
|
tracy = ["common-base/tracy", "tracing-tracy"]
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
common-base = { package = "veloren-common-base", path = "../base" }
|
||||||
|
|
||||||
|
# Logging
|
||||||
|
termcolor = "1.1"
|
||||||
|
tracing = { version = "0.1", default-features = false }
|
||||||
|
tracing-appender = "0.1"
|
||||||
|
tracing-log = "0.1.1"
|
||||||
|
tracing-subscriber = { version = "0.2.3", default-features = false, features = ["env-filter", "fmt", "chrono", "ansi", "smallvec", "tracing-log"]}
|
||||||
|
|
||||||
|
# Tracy
|
||||||
|
tracing-tracy = { version = "0.6.0", optional = true }
|
@ -1,14 +1,16 @@
|
|||||||
use std::fs;
|
#[cfg(not(feature = "tracy"))] use std::fs;
|
||||||
|
use std::path::Path;
|
||||||
use crate::settings::Settings;
|
|
||||||
|
|
||||||
use termcolor::{ColorChoice, StandardStream};
|
use termcolor::{ColorChoice, StandardStream};
|
||||||
use tracing::{debug, error, info, trace};
|
use tracing::info;
|
||||||
use tracing_subscriber::{filter::LevelFilter, prelude::*, registry, EnvFilter};
|
use tracing_appender::non_blocking::WorkerGuard;
|
||||||
|
use tracing_subscriber::{
|
||||||
|
filter::LevelFilter, fmt::writer::MakeWriter, prelude::*, registry, EnvFilter,
|
||||||
|
};
|
||||||
|
|
||||||
const RUST_LOG_ENV: &str = "RUST_LOG";
|
const RUST_LOG_ENV: &str = "RUST_LOG";
|
||||||
|
|
||||||
/// Initialise tracing and logging for the settings.
|
/// Initialise tracing and logging for the logs_path.
|
||||||
///
|
///
|
||||||
/// This function will attempt to set up both a file and a terminal logger,
|
/// 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.
|
/// falling back to just a terminal logger if the file is unable to be created.
|
||||||
@ -30,10 +32,14 @@ const RUST_LOG_ENV: &str = "RUST_LOG";
|
|||||||
///
|
///
|
||||||
/// By default a few directives are set to `warn` by default, until explicitly
|
/// By default a few directives are set to `warn` by default, until explicitly
|
||||||
/// overwritten! e.g. `RUST_LOG="gfx_device_gl=debug"`
|
/// overwritten! e.g. `RUST_LOG="gfx_device_gl=debug"`
|
||||||
pub fn init(settings: &Settings) -> Vec<impl Drop> {
|
pub fn init<W2>(log_path_file: Option<(&Path, &str)>, terminal: W2) -> Vec<impl Drop>
|
||||||
|
where
|
||||||
|
W2: MakeWriter + 'static,
|
||||||
|
<W2 as MakeWriter>::Writer: Send + Sync,
|
||||||
|
{
|
||||||
// To hold the guards that we create, they will cause the logs to be
|
// To hold the guards that we create, they will cause the logs to be
|
||||||
// flushed when they're dropped.
|
// flushed when they're dropped.
|
||||||
let mut _guards = vec![];
|
let mut _guards: Vec<WorkerGuard> = vec![];
|
||||||
|
|
||||||
// We will do lower logging than the default (INFO) by INCLUSION. This
|
// 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
|
// means that if you need lower level logging for a specific module, then
|
||||||
@ -42,7 +48,11 @@ pub fn init(settings: &Settings) -> Vec<impl Drop> {
|
|||||||
let base_exceptions = |env: EnvFilter| {
|
let base_exceptions = |env: EnvFilter| {
|
||||||
env.add_directive("dot_vox::parser=warn".parse().unwrap())
|
env.add_directive("dot_vox::parser=warn".parse().unwrap())
|
||||||
.add_directive("gfx_device_gl=warn".parse().unwrap())
|
.add_directive("gfx_device_gl=warn".parse().unwrap())
|
||||||
.add_directive("prometheus_hyper=warn".parse().unwrap())
|
.add_directive("veloren_world::sim=info".parse().unwrap())
|
||||||
|
.add_directive("veloren_world::civ=info".parse().unwrap())
|
||||||
|
.add_directive("hyper=info".parse().unwrap())
|
||||||
|
.add_directive("prometheus_hyper=info".parse().unwrap())
|
||||||
|
.add_directive("mio::pool=info".parse().unwrap())
|
||||||
.add_directive("mio::sys::windows=info".parse().unwrap())
|
.add_directive("mio::sys::windows=info".parse().unwrap())
|
||||||
.add_directive("h2=info".parse().unwrap())
|
.add_directive("h2=info".parse().unwrap())
|
||||||
.add_directive("tokio_util=info".parse().unwrap())
|
.add_directive("tokio_util=info".parse().unwrap())
|
||||||
@ -56,7 +66,6 @@ pub fn init(settings: &Settings) -> Vec<impl Drop> {
|
|||||||
.add_directive(LevelFilter::INFO.into())
|
.add_directive(LevelFilter::INFO.into())
|
||||||
};
|
};
|
||||||
|
|
||||||
#[cfg(not(feature = "tracy"))]
|
|
||||||
let filter = match std::env::var_os(RUST_LOG_ENV).map(|s| s.into_string()) {
|
let filter = match std::env::var_os(RUST_LOG_ENV).map(|s| s.into_string()) {
|
||||||
Some(Ok(env)) => {
|
Some(Ok(env)) => {
|
||||||
let mut filter = base_exceptions(EnvFilter::new(""));
|
let mut filter = base_exceptions(EnvFilter::new(""));
|
||||||
@ -71,63 +80,68 @@ pub fn init(settings: &Settings) -> Vec<impl Drop> {
|
|||||||
_ => base_exceptions(EnvFilter::from_env(RUST_LOG_ENV)),
|
_ => base_exceptions(EnvFilter::from_env(RUST_LOG_ENV)),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let registry = registry();
|
||||||
|
#[cfg(not(feature = "tracy"))]
|
||||||
|
let mut file_setup = false;
|
||||||
#[cfg(feature = "tracy")]
|
#[cfg(feature = "tracy")]
|
||||||
let filter = base_exceptions(EnvFilter::new("")).add_directive(LevelFilter::INFO.into());
|
let file_setup = false;
|
||||||
|
#[cfg(feature = "tracy")]
|
||||||
|
let _terminal = terminal;
|
||||||
|
|
||||||
// Create the terminal writer layer.
|
// Create the terminal writer layer.
|
||||||
let (non_blocking, _stdio_guard) =
|
#[cfg(feature = "tracy")]
|
||||||
tracing_appender::non_blocking(StandardStream::stdout(ColorChoice::Auto));
|
let registry = registry.with(tracing_tracy::TracyLayer::new().with_stackdepth(0));
|
||||||
_guards.push(_stdio_guard);
|
#[cfg(not(feature = "tracy"))]
|
||||||
|
let registry = {
|
||||||
|
let (non_blocking, _stdio_guard) = tracing_appender::non_blocking(terminal.make_writer());
|
||||||
|
_guards.push(_stdio_guard);
|
||||||
|
registry.with(tracing_subscriber::fmt::layer().with_writer(non_blocking))
|
||||||
|
};
|
||||||
|
|
||||||
// Try to create the log file's parent folders.
|
// Try to create the log file's parent folders.
|
||||||
let log_folders_created = fs::create_dir_all(&settings.log.logs_path);
|
#[cfg(not(feature = "tracy"))]
|
||||||
const LOG_FILENAME: &str = "voxygen.log";
|
if let Some((path, file)) = log_path_file {
|
||||||
|
match fs::create_dir_all(path) {
|
||||||
|
Ok(_) => {
|
||||||
|
let file_appender = tracing_appender::rolling::daily(path, file);
|
||||||
|
let (non_blocking_file, _file_guard) =
|
||||||
|
tracing_appender::non_blocking(file_appender);
|
||||||
|
_guards.push(_file_guard);
|
||||||
|
file_setup = true;
|
||||||
|
registry
|
||||||
|
.with(tracing_subscriber::fmt::layer().with_writer(non_blocking_file))
|
||||||
|
.with(filter)
|
||||||
|
.init();
|
||||||
|
},
|
||||||
|
Err(e) => {
|
||||||
|
tracing::error!(
|
||||||
|
?e,
|
||||||
|
"Failed to create log file!. Falling back to terminal logging only.",
|
||||||
|
);
|
||||||
|
registry.with(filter).init();
|
||||||
|
},
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
registry.with(filter).init();
|
||||||
|
}
|
||||||
|
#[cfg(feature = "tracy")]
|
||||||
|
registry.with(filter).init();
|
||||||
|
|
||||||
match log_folders_created {
|
if file_setup {
|
||||||
// If the parent folders were created then attach both a terminal and a
|
let (path, file) = log_path_file.unwrap();
|
||||||
// file writer to the registry and init it.
|
info!(?path, ?file, "Setup terminal and file logging.");
|
||||||
Ok(_) => {
|
}
|
||||||
let file_appender =
|
|
||||||
tracing_appender::rolling::daily(&settings.log.logs_path, LOG_FILENAME);
|
if tracing::level_enabled!(tracing::Level::TRACE) {
|
||||||
let (non_blocking_file, _file_guard) = tracing_appender::non_blocking(file_appender);
|
info!("Tracing Level: TRACE");
|
||||||
_guards.push(_file_guard);
|
} else if tracing::level_enabled!(tracing::Level::DEBUG) {
|
||||||
#[cfg(not(feature = "tracy"))]
|
info!("Tracing Level: DEBUG");
|
||||||
registry()
|
|
||||||
.with(tracing_subscriber::fmt::layer().with_writer(non_blocking))
|
|
||||||
.with(tracing_subscriber::fmt::layer().with_writer(non_blocking_file))
|
|
||||||
.with(filter)
|
|
||||||
.init();
|
|
||||||
#[cfg(feature = "tracy")]
|
|
||||||
registry()
|
|
||||||
// NOTE: collecting stacks has a significant overhead (x6 overhead of
|
|
||||||
// starting/stopping a span through the layer interface)
|
|
||||||
.with(tracing_tracy::TracyLayer::new().with_stackdepth(0))
|
|
||||||
.with(filter)
|
|
||||||
.init();
|
|
||||||
let logdir = &settings.log.logs_path;
|
|
||||||
info!(?logdir, "Setup terminal and file logging.");
|
|
||||||
},
|
|
||||||
// Otherwise just add a terminal writer and init it.
|
|
||||||
Err(e) => {
|
|
||||||
error!(
|
|
||||||
?e,
|
|
||||||
"Failed to create log file!. Falling back to terminal logging only.",
|
|
||||||
);
|
|
||||||
#[cfg(not(feature = "tracy"))]
|
|
||||||
registry()
|
|
||||||
.with(tracing_subscriber::fmt::layer().with_writer(non_blocking))
|
|
||||||
.with(filter);
|
|
||||||
#[cfg(feature = "tracy")]
|
|
||||||
registry()
|
|
||||||
.with(tracing_tracy::TracyLayer::new().with_stackdepth(0))
|
|
||||||
.with(filter)
|
|
||||||
.init();
|
|
||||||
info!("Setup terminal logging.");
|
|
||||||
},
|
|
||||||
};
|
};
|
||||||
debug!("Tracing is successfully set to DEBUG or TRACE");
|
|
||||||
trace!("Tracing is successfully set to TRACE");
|
|
||||||
|
|
||||||
// Return the guards
|
// Return the guards
|
||||||
_guards
|
_guards
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn init_stdout(log_path_file: Option<(&Path, &str)>) -> Vec<impl Drop> {
|
||||||
|
init(log_path_file, || StandardStream::stdout(ColorChoice::Auto))
|
||||||
|
}
|
@ -7,7 +7,7 @@ edition = "2018"
|
|||||||
[features]
|
[features]
|
||||||
worldgen = ["server/worldgen"]
|
worldgen = ["server/worldgen"]
|
||||||
default = ["worldgen"]
|
default = ["worldgen"]
|
||||||
tracy = ["common/tracy", "tracing-tracy", "server/tracy", "common-net/tracy"]
|
tracy = ["common/tracy", "server/tracy", "common-net/tracy", "common-frontend/tracy"]
|
||||||
plugins = ["server/plugins"]
|
plugins = ["server/plugins"]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
@ -15,6 +15,7 @@ server = { package = "veloren-server", path = "../server", default-features = fa
|
|||||||
common = { package = "veloren-common", path = "../common" }
|
common = { package = "veloren-common", path = "../common" }
|
||||||
common-base = { package = "veloren-common-base", path = "../common/base" }
|
common-base = { package = "veloren-common-base", path = "../common/base" }
|
||||||
common-net = { package = "veloren-common-net", path = "../common/net" }
|
common-net = { package = "veloren-common-net", path = "../common/net" }
|
||||||
|
common-frontend = { package = "veloren-common-frontend", path = "../common/frontend" }
|
||||||
|
|
||||||
tokio = { version = "1", default-features = false, features = ["rt-multi-thread"] }
|
tokio = { version = "1", default-features = false, features = ["rt-multi-thread"] }
|
||||||
ansi-parser = "0.7"
|
ansi-parser = "0.7"
|
||||||
@ -22,15 +23,10 @@ clap = "2.33"
|
|||||||
crossterm = "0.19"
|
crossterm = "0.19"
|
||||||
lazy_static = "1"
|
lazy_static = "1"
|
||||||
signal-hook = "0.3.6"
|
signal-hook = "0.3.6"
|
||||||
termcolor = "1.1"
|
|
||||||
tracing = { version = "0.1", default-features = false }
|
tracing = { version = "0.1", default-features = false }
|
||||||
tracing-subscriber = { version = "0.2.3", default-features = false, features = ["env-filter", "fmt", "chrono", "ansi", "smallvec"] }
|
|
||||||
ron = {version = "0.6", default-features = false}
|
ron = {version = "0.6", default-features = false}
|
||||||
serde = {version = "1.0", features = [ "rc", "derive" ]}
|
serde = {version = "1.0", features = [ "rc", "derive" ]}
|
||||||
|
|
||||||
# Tracy
|
|
||||||
tracing-tracy = { version = "0.6.0", optional = true }
|
|
||||||
|
|
||||||
[dependencies.tui]
|
[dependencies.tui]
|
||||||
git = "https://github.com/fdehau/tui-rs.git"
|
git = "https://github.com/fdehau/tui-rs.git"
|
||||||
branch="paragraph-scroll"
|
branch="paragraph-scroll"
|
||||||
|
@ -1,68 +0,0 @@
|
|||||||
use crate::tuilog::TuiLog;
|
|
||||||
use termcolor::{ColorChoice, StandardStream};
|
|
||||||
use tracing_subscriber::{filter::LevelFilter, EnvFilter, FmtSubscriber};
|
|
||||||
#[cfg(feature = "tracy")]
|
|
||||||
use tracing_subscriber::{layer::SubscriberExt, prelude::*};
|
|
||||||
|
|
||||||
const RUST_LOG_ENV: &str = "RUST_LOG";
|
|
||||||
|
|
||||||
lazy_static::lazy_static! {
|
|
||||||
pub static ref LOG: TuiLog<'static> = TuiLog::default();
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn init(basic: bool) {
|
|
||||||
// Init logging
|
|
||||||
let base_exceptions = |env: EnvFilter| {
|
|
||||||
env.add_directive("veloren_world::sim=info".parse().unwrap())
|
|
||||||
.add_directive("veloren_world::civ=info".parse().unwrap())
|
|
||||||
.add_directive("hyper=info".parse().unwrap())
|
|
||||||
.add_directive("prometheus_hyper=info".parse().unwrap())
|
|
||||||
.add_directive("mio::pool=info".parse().unwrap())
|
|
||||||
.add_directive("mio::sys::windows=info".parse().unwrap())
|
|
||||||
.add_directive("h2=info".parse().unwrap())
|
|
||||||
.add_directive("tokio_util=info".parse().unwrap())
|
|
||||||
.add_directive("rustls=info".parse().unwrap())
|
|
||||||
.add_directive("veloren_network_protocol=info".parse().unwrap())
|
|
||||||
.add_directive(
|
|
||||||
"veloren_server::persistence::character=info"
|
|
||||||
.parse()
|
|
||||||
.unwrap(),
|
|
||||||
)
|
|
||||||
.add_directive(LevelFilter::INFO.into())
|
|
||||||
};
|
|
||||||
|
|
||||||
let filter = match std::env::var_os(RUST_LOG_ENV).map(|s| s.into_string()) {
|
|
||||||
Some(Ok(env)) => {
|
|
||||||
let mut filter = base_exceptions(EnvFilter::new(""));
|
|
||||||
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
|
|
||||||
},
|
|
||||||
_ => base_exceptions(EnvFilter::from_env(RUST_LOG_ENV)),
|
|
||||||
};
|
|
||||||
|
|
||||||
#[cfg(feature = "tracy")]
|
|
||||||
tracing_subscriber::registry()
|
|
||||||
.with(filter)
|
|
||||||
.with(tracing_tracy::TracyLayer::new().with_stackdepth(0))
|
|
||||||
.init();
|
|
||||||
|
|
||||||
#[cfg(not(feature = "tracy"))]
|
|
||||||
// TODO: when tracing gets per Layer filters re-enable this when the tracy feature is being
|
|
||||||
// used (and do the same in voxygen)
|
|
||||||
{
|
|
||||||
let subscriber = FmtSubscriber::builder().with_env_filter(filter);
|
|
||||||
|
|
||||||
if basic {
|
|
||||||
subscriber
|
|
||||||
.with_writer(|| StandardStream::stdout(ColorChoice::Auto))
|
|
||||||
.init();
|
|
||||||
} else {
|
|
||||||
subscriber.with_writer(|| LOG.clone()).init();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -6,13 +6,13 @@ mod admin;
|
|||||||
/// `server-cli` interface commands not to be confused with the commands sent
|
/// `server-cli` interface commands not to be confused with the commands sent
|
||||||
/// from the client to the server
|
/// from the client to the server
|
||||||
mod cmd;
|
mod cmd;
|
||||||
mod logging;
|
|
||||||
mod settings;
|
mod settings;
|
||||||
mod shutdown_coordinator;
|
mod shutdown_coordinator;
|
||||||
mod tui_runner;
|
mod tui_runner;
|
||||||
mod tuilog;
|
mod tuilog;
|
||||||
|
use crate::{
|
||||||
use crate::{cmd::Message, shutdown_coordinator::ShutdownCoordinator, tui_runner::Tui};
|
cmd::Message, shutdown_coordinator::ShutdownCoordinator, tui_runner::Tui, tuilog::TuiLog,
|
||||||
|
};
|
||||||
use clap::{App, Arg, SubCommand};
|
use clap::{App, Arg, SubCommand};
|
||||||
use common::clock::Clock;
|
use common::clock::Clock;
|
||||||
use common_base::span;
|
use common_base::span;
|
||||||
@ -25,6 +25,9 @@ use std::{
|
|||||||
};
|
};
|
||||||
use tracing::{info, trace};
|
use tracing::{info, trace};
|
||||||
|
|
||||||
|
lazy_static::lazy_static! {
|
||||||
|
pub static ref LOG: TuiLog<'static> = TuiLog::default();
|
||||||
|
}
|
||||||
const TPS: u64 = 30;
|
const TPS: u64 = 30;
|
||||||
|
|
||||||
#[allow(clippy::unnecessary_wraps)]
|
#[allow(clippy::unnecessary_wraps)]
|
||||||
@ -83,7 +86,11 @@ fn main() -> io::Result<()> {
|
|||||||
#[cfg(any(target_os = "linux", target_os = "macos"))]
|
#[cfg(any(target_os = "linux", target_os = "macos"))]
|
||||||
let _ = signal_hook::flag::register(signal_hook::consts::SIGUSR1, Arc::clone(&sigusr1_signal));
|
let _ = signal_hook::flag::register(signal_hook::consts::SIGUSR1, Arc::clone(&sigusr1_signal));
|
||||||
|
|
||||||
logging::init(basic);
|
let (_guards, _guards2) = if basic {
|
||||||
|
(vec![], common_frontend::init_stdout(None))
|
||||||
|
} else {
|
||||||
|
(common_frontend::init(None, || LOG.clone()), vec![])
|
||||||
|
};
|
||||||
|
|
||||||
// Load settings
|
// Load settings
|
||||||
let settings = settings::Settings::load();
|
let settings = settings::Settings::load();
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
use crate::{cmd, logging::LOG, Message};
|
use crate::{cmd, Message, LOG};
|
||||||
use crossterm::{
|
use crossterm::{
|
||||||
event::{DisableMouseCapture, EnableMouseCapture},
|
event::{DisableMouseCapture, EnableMouseCapture},
|
||||||
execute,
|
execute,
|
||||||
|
@ -13,7 +13,7 @@ gl = ["gfx_device_gl", "gfx_gl"]
|
|||||||
hot-anim = ["anim/use-dyn-lib"]
|
hot-anim = ["anim/use-dyn-lib"]
|
||||||
singleplayer = ["server"]
|
singleplayer = ["server"]
|
||||||
simd = ["vek/platform_intrinsics"]
|
simd = ["vek/platform_intrinsics"]
|
||||||
tracy = ["tracing-tracy", "common/tracy", "common-ecs/tracy", "common-net/tracy", "common-sys/tracy", "client/tracy"]
|
tracy = ["common/tracy", "common-ecs/tracy", "common-frontend/tracy", "common-net/tracy", "common-sys/tracy", "client/tracy"]
|
||||||
plugins = ["client/plugins"]
|
plugins = ["client/plugins"]
|
||||||
|
|
||||||
default = ["gl", "singleplayer", "native-dialog", "plugins", "simd"]
|
default = ["gl", "singleplayer", "native-dialog", "plugins", "simd"]
|
||||||
@ -23,6 +23,7 @@ client = {package = "veloren-client", path = "../client"}
|
|||||||
common = {package = "veloren-common", path = "../common"}
|
common = {package = "veloren-common", path = "../common"}
|
||||||
common-base = {package = "veloren-common-base", path = "../common/base"}
|
common-base = {package = "veloren-common-base", path = "../common/base"}
|
||||||
common-ecs = {package = "veloren-common-ecs", path = "../common/ecs"}
|
common-ecs = {package = "veloren-common-ecs", path = "../common/ecs"}
|
||||||
|
common-frontend = {package = "veloren-common-frontend", path = "../common/frontend"}
|
||||||
common-net = {package = "veloren-common-net", path = "../common/net"}
|
common-net = {package = "veloren-common-net", path = "../common/net"}
|
||||||
common-sys = {package = "veloren-common-sys", path = "../common/sys"}
|
common-sys = {package = "veloren-common-sys", path = "../common/sys"}
|
||||||
|
|
||||||
@ -90,14 +91,7 @@ inline_tweak = "1.0.2"
|
|||||||
itertools = "0.10.0"
|
itertools = "0.10.0"
|
||||||
|
|
||||||
# Tracy
|
# Tracy
|
||||||
tracing-tracy = { version = "0.6.0", optional = true }
|
|
||||||
|
|
||||||
# Logging
|
|
||||||
termcolor = "1.1"
|
|
||||||
tracing = "0.1"
|
tracing = "0.1"
|
||||||
tracing-appender = "0.1"
|
|
||||||
tracing-log = "0.1.1"
|
|
||||||
tracing-subscriber = {version = "0.2.3", default-features = false, features = ["env-filter", "fmt", "chrono", "ansi", "smallvec", "tracing-log"]}
|
|
||||||
|
|
||||||
[target.'cfg(target_os = "macos")'.dependencies]
|
[target.'cfg(target_os = "macos")'.dependencies]
|
||||||
dispatch = "0.1.4"
|
dispatch = "0.1.4"
|
||||||
|
@ -641,6 +641,8 @@ impl Show {
|
|||||||
self.settings(true)
|
self.settings(true)
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
#[cfg(not(feature = "singleplayer"))]
|
||||||
|
let _global_state = global_state;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Add self updating key-bindings element
|
// TODO: Add self updating key-bindings element
|
||||||
@ -683,6 +685,8 @@ impl Show {
|
|||||||
#[cfg(feature = "singleplayer")]
|
#[cfg(feature = "singleplayer")]
|
||||||
global_state.pause();
|
global_state.pause();
|
||||||
}
|
}
|
||||||
|
#[cfg(not(feature = "singleplayer"))]
|
||||||
|
let _global_state = global_state;
|
||||||
}
|
}
|
||||||
|
|
||||||
fn open_setting_tab(&mut self, tab: SettingsTab) {
|
fn open_setting_tab(&mut self, tab: SettingsTab) {
|
||||||
|
@ -14,7 +14,6 @@ pub mod error;
|
|||||||
pub mod hud;
|
pub mod hud;
|
||||||
pub mod i18n;
|
pub mod i18n;
|
||||||
pub mod key_state;
|
pub mod key_state;
|
||||||
pub mod logging;
|
|
||||||
pub mod menu;
|
pub mod menu;
|
||||||
pub mod mesh;
|
pub mod mesh;
|
||||||
pub mod profile;
|
pub mod profile;
|
||||||
|
@ -6,7 +6,6 @@
|
|||||||
use veloren_voxygen::{
|
use veloren_voxygen::{
|
||||||
audio::AudioFrontend,
|
audio::AudioFrontend,
|
||||||
i18n::{self, i18n_asset_key, Localization},
|
i18n::{self, i18n_asset_key, Localization},
|
||||||
logging,
|
|
||||||
profile::Profile,
|
profile::Profile,
|
||||||
run,
|
run,
|
||||||
settings::{get_fps, AudioOutput, Settings},
|
settings::{get_fps, AudioOutput, Settings},
|
||||||
@ -34,7 +33,8 @@ fn main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Init logging and hold the guards.
|
// Init logging and hold the guards.
|
||||||
let _guards = logging::init(&settings);
|
const LOG_FILENAME: &str = "voxygen.log";
|
||||||
|
let _guards = common_frontend::init_stdout(Some((&settings.log.logs_path, LOG_FILENAME)));
|
||||||
|
|
||||||
if let Some(path) = veloren_voxygen::settings::voxygen_data_dir().parent() {
|
if let Some(path) = veloren_voxygen::settings::voxygen_data_dir().parent() {
|
||||||
info!("Using userdata dir at: {}", path.display());
|
info!("Using userdata dir at: {}", path.display());
|
||||||
|
@ -29,6 +29,7 @@ pub enum Msg {
|
|||||||
|
|
||||||
pub enum ClientConnArgs {
|
pub enum ClientConnArgs {
|
||||||
Host(String),
|
Host(String),
|
||||||
|
#[allow(dead_code)] //singleplayer
|
||||||
Resolved(ConnectionArgs),
|
Resolved(ConnectionArgs),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -11,10 +11,9 @@ use crate::{
|
|||||||
window::Event,
|
window::Event,
|
||||||
Direction, GlobalState, PlayState, PlayStateResult,
|
Direction, GlobalState, PlayState, PlayStateResult,
|
||||||
};
|
};
|
||||||
use client::{
|
#[cfg(feature = "singleplayer")]
|
||||||
addr::ConnectionArgs,
|
use client::addr::ConnectionArgs;
|
||||||
error::{InitProtocolError, NetworkConnectError, NetworkError},
|
use client::error::{InitProtocolError, NetworkConnectError, NetworkError};
|
||||||
};
|
|
||||||
use client_init::{ClientConnArgs, ClientInit, Error as InitError, Msg as InitMsg};
|
use client_init::{ClientConnArgs, ClientInit, Error as InitError, Msg as InitMsg};
|
||||||
use common::{assets::AssetExt, comp};
|
use common::{assets::AssetExt, comp};
|
||||||
use common_base::span;
|
use common_base::span;
|
||||||
|
Loading…
Reference in New Issue
Block a user