From bdc758c5e5ed6cb1d704f4f4c996f39349762aae Mon Sep 17 00:00:00 2001 From: Ludovic Marie <136255825+ludovic111@users.noreply.github.com> Date: Sun, 18 Oct 2026 18:30:25 +0200 Subject: [PATCH] Server log: vanilla's thread in latest.log, and local time on the console A dedicated server printed refused logins on its console as vanilla does ("[Server thread/INFO]: Disconnecting ..."), but wrote them to logs/latest.log under the connection thread's own name ("[horizon-lan-conn/INFO]"): the file logger used the OS thread's name, not the one vanilla logs the line from. The engine's lines now go to the file under the same thread as on the console. The console's times were UTC while logs/latest.log and vanilla's console (Log4j's %d{HH:mm:ss}) use local time, so the two disagreed by the time zone, as did the supervisor's own lines in logs/supervisor.log and the web panel's console. Both now print local time. Backup names keep their UTC time, as documented. Found by the end-to-end install check on the Mac mini and the ThinkPad. Co-Authored-By: Claude Opus 5.5 --- Cargo.lock | 1 + crates/horizon-client/src/game/dedicated.rs | 14 +++++--------- crates/horizon-client/src/logging.rs | 8 ++++++++ crates/horizon-server/Cargo.toml | 2 ++ crates/horizon-server/src/supervisor.rs | 12 ++++-------- 5 files changed, 20 insertions(+), 17 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index aa41f656f..94e2052e3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1556,6 +1556,7 @@ dependencies = [ name = "horizon-server" version = "0.1.0" dependencies = [ + "chrono", "horizon-bench", "horizon-server-files", "libc", diff --git a/crates/horizon-client/src/game/dedicated.rs b/crates/horizon-client/src/game/dedicated.rs index f9c3464dd..905073b31 100644 --- a/crates/horizon-client/src/game/dedicated.rs +++ b/crates/horizon-client/src/game/dedicated.rs @@ -11,9 +11,7 @@ use horizon_client::{ Result, lan::{LoginGate, NetConfig, NetLog, OnlineMode, hub::HubConfig}, server::{ - eula, - java_properties::now_millis, - profiles, + eula, profiles, properties::{GAME_MODES, ServerProperties, SystemEntropy}, user_cache::UserCache, user_lists::{ @@ -84,18 +82,16 @@ fn log_from(thread: &str, level: &str, message: &str) { "ERROR" => ::log::Level::Error, _ => ::log::Level::Info, }; - horizon_client::logging::write_only(file_level, message); + horizon_client::logging::write_as(thread, file_level, message); CAPTURE.with_borrow_mut(|lines| { if let Some(lines) = lines { lines.push(message.to_owned()); } }); - let secs = now_millis().div_euclid(1000).rem_euclid(86_400); + // Log4j's %d{HH:mm:ss}: the local time, as in logs/latest.log. println!( - "[{:02}:{:02}:{:02}] [{thread}/{level}]: {message}", - secs / 3600, - secs / 60 % 60, - secs % 60 + "[{}] [{thread}/{level}]: {message}", + chrono::Local::now().format("%H:%M:%S") ); } diff --git a/crates/horizon-client/src/logging.rs b/crates/horizon-client/src/logging.rs index c434c8efb..cb7638f26 100644 --- a/crates/horizon-client/src/logging.rs +++ b/crates/horizon-client/src/logging.rs @@ -330,6 +330,14 @@ pub fn write_only(level: log::Level, message: &str) { } } +/// Writes `message` to the log file only, under the thread vanilla names for it (`Server thread` for +/// a login refused on a connection's own thread), as the console line beside it shows. +pub fn write_as(thread: &str, level: log::Level, message: &str) { + if let Some(logger) = LOGGER.get() { + logger.write(thread, level, message); + } +} + /// The last lines written, oldest first (for crash reports). pub fn recent_lines() -> Vec { LOGGER.get().map_or_else(Vec::new, |l| { diff --git a/crates/horizon-server/Cargo.toml b/crates/horizon-server/Cargo.toml index c3800b80c..2432cd481 100644 --- a/crates/horizon-server/Cargo.toml +++ b/crates/horizon-server/Cargo.toml @@ -10,6 +10,8 @@ description = "Host a Horizon server: server.toml, the CLI and the supervisor th horizon-server-files = { path = "../horizon-server-files" } # The game process's RAM and CPU (the same probes the benchmark reports use). horizon-bench = { path = "../horizon-bench" } +# The log's local times, as the game prints them. +chrono = { version = "0.4.42", default-features = false, features = ["clock", "std"] } serde = { version = "1", features = ["derive"] } serde_json = "1" toml = "1.1" diff --git a/crates/horizon-server/src/supervisor.rs b/crates/horizon-server/src/supervisor.rs index ad056a77c..0e1cf8a7c 100644 --- a/crates/horizon-server/src/supervisor.rs +++ b/crates/horizon-server/src/supervisor.rs @@ -8,7 +8,6 @@ use crate::{ config::Config, engine, signals, }; -use horizon_server_files::java_properties::now_millis; use serde_json::json; use std::{ fs::File, @@ -29,15 +28,12 @@ const MAX_BACKOFF: Duration = Duration::from_secs(300); /// How long `stop` may take before the game is killed. const STOP_TIMEOUT: Duration = Duration::from_secs(120); -/// A line from the supervisor, in the game's log format (`[HH:mm:ss] [thread/LEVEL]: message`, UTC), on -/// stdout and in the log the API serves. +/// A line from the supervisor, in the game's log format (`[HH:mm:ss] [thread/LEVEL]: message`, local time +/// as the game's own lines), on stdout and in the log the API serves. fn note(shared: &Shared, level: &str, message: &str) { - let secs = now_millis().div_euclid(1000).rem_euclid(86_400); let line = format!( - "[{:02}:{:02}:{:02}] [Supervisor/{level}]: {message}", - secs / 3600, - secs / 60 % 60, - secs % 60 + "[{}] [Supervisor/{level}]: {message}", + chrono::Local::now().format("%H:%M:%S") ); println!("{line}"); shared.log.lock().unwrap().push(line);