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 <name> ..."), 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 <noreply@anthropic.com>
This commit is contained in:
Ludovic Marie
2026-10-18 18:30:25 +02:00
parent 73787507d1
commit bdc758c5e5
5 changed files with 20 additions and 17 deletions
Generated
+1
View File
@@ -1556,6 +1556,7 @@ dependencies = [
name = "horizon-server"
version = "0.1.0"
dependencies = [
"chrono",
"horizon-bench",
"horizon-server-files",
"libc",
+5 -9
View File
@@ -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")
);
}
+8
View File
@@ -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<String> {
LOGGER.get().map_or_else(Vec::new, |l| {
+2
View File
@@ -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"
+4 -8
View File
@@ -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);