Logging system info (#279)

* Add Git hash to version info, display version on startup, remove ms from log timestamp

* Add startup info
This commit is contained in:
Commandcracker
2024-11-15 23:06:40 +01:00
committed by GitHub
parent 7b64ca10c3
commit e4190459ed
5 changed files with 69 additions and 16 deletions

View File

@@ -1,4 +1,6 @@
FROM rust:1-alpine3.20 AS builder
ARG GIT_VERSION=Docker
ENV GIT_VERSION=$GIT_VERSION
ENV RUSTFLAGS="-C target-feature=-crt-static -C target-cpu=native"
RUN apk add --no-cache musl-dev

View File

@@ -68,9 +68,12 @@ png = "0.17.14"
# logging
simple_logger = { version = "5.0.0", features = ["threads"] }
time = "0.3.36"
sys-info = "0.9.1"
# commands
async-trait = "0.1.83"
[build-dependencies]
winresource = "0.1.17"
git-version = "0.3.9"

View File

@@ -1,8 +1,18 @@
fn main() {
if cfg!(target_os = "windows") {
let mut res = winresource::WindowsResource::new();
res.set_icon("../assets/icon.ico");
res.set_language(0x0009); // English
res.compile().unwrap();
}
}
use git_version::git_version;
use std::env;
fn main() {
if cfg!(target_os = "windows") {
let mut res = winresource::WindowsResource::new();
res.set_icon("../assets/icon.ico");
res.set_language(0x0009); // English
res.compile().unwrap();
}
let version = git_version!(fallback = "unknown");
let git_version = match version {
"unknown" => env::var("GIT_VERSION").unwrap_or("unknown".to_string()),
_ => version.to_string(),
};
println!("cargo:rustc-env=GIT_VERSION={}", git_version);
}

View File

@@ -7,6 +7,7 @@ use crate::{
args::ConsumedArgs, tree::CommandTree, CommandError, CommandExecutor, CommandSender,
},
server::CURRENT_MC_VERSION,
GIT_VERSION,
};
const NAMES: [&str; 2] = ["pumpkin", "version"];
@@ -15,6 +16,9 @@ const DESCRIPTION: &str = "Display information about Pumpkin.";
struct PumpkinExecutor;
const CARGO_PKG_VERSION: &str = env!("CARGO_PKG_VERSION");
const CARGO_PKG_DESCRIPTION: &str = env!("CARGO_PKG_DESCRIPTION");
#[async_trait]
impl CommandExecutor for PumpkinExecutor {
async fn execute<'a>(
@@ -23,13 +27,12 @@ impl CommandExecutor for PumpkinExecutor {
_server: &crate::server::Server,
_args: &ConsumedArgs<'a>,
) -> Result<(), CommandError> {
let version = env!("CARGO_PKG_VERSION");
let description = env!("CARGO_PKG_DESCRIPTION");
sender.send_message(TextComponent::text(
&format!("Pumpkin {version}, {description} (Minecraft {CURRENT_MC_VERSION}, Protocol {CURRENT_MC_PROTOCOL})")
).color_named(NamedColor::Green)).await;
sender
.send_message(
TextComponent::text(&format!("Pumpkin {CARGO_PKG_VERSION} ({GIT_VERSION}), {CARGO_PKG_DESCRIPTION} (Minecraft {CURRENT_MC_VERSION}, Protocol {CURRENT_MC_PROTOCOL})", ))
.color_named(NamedColor::Green),
)
.await;
Ok(())
}
}

View File

@@ -30,11 +30,12 @@ use tokio::signal::unix::{signal, SignalKind};
use std::sync::Arc;
use crate::server::CURRENT_MC_VERSION;
use pumpkin_config::{ADVANCED_CONFIG, BASIC_CONFIG};
use pumpkin_core::text::{color::NamedColor, TextComponent};
use pumpkin_protocol::CURRENT_MC_PROTOCOL;
use rcon::RCONServer;
use std::time::Instant;
// Setup some tokens to allow us to identify which event is for which socket.
pub mod client;
@@ -62,6 +63,9 @@ fn init_logger() {
use pumpkin_config::ADVANCED_CONFIG;
if ADVANCED_CONFIG.logging.enabled {
let mut logger = simple_logger::SimpleLogger::new();
logger = logger.with_timestamp_format(time::macros::format_description!(
"[year]-[month]-[day] [hour]:[minute]:[second]"
));
if !ADVANCED_CONFIG.logging.timestamp {
logger = logger.without_timestamps();
@@ -90,9 +94,40 @@ const fn convert_logger_filter(level: pumpkin_config::logging::LevelFilter) -> L
}
}
const CARGO_PKG_VERSION: &str = env!("CARGO_PKG_VERSION");
fn log_system_info() {
let os_type = sys_info::os_type().unwrap();
let os_release = sys_info::os_release().unwrap();
let arch = std::env::consts::ARCH;
if cfg!(target_os = "linux") {
if let Some(linux_release) = sys_info::linux_os_release().unwrap().pretty_name {
log::info!(
"Running on {} ({}) {} ({})",
os_type,
linux_release,
os_release,
arch
);
return;
}
}
log::info!("Running on {} {} ({})", os_type, os_release, arch);
}
const GIT_VERSION: &str = env!("GIT_VERSION");
#[tokio::main]
async fn main() -> io::Result<()> {
init_logger();
log_system_info();
log::info!("Starting Pumpkin {CARGO_PKG_VERSION} ({GIT_VERSION}) for Minecraft {CURRENT_MC_VERSION} (Protocol {CURRENT_MC_PROTOCOL})",);
log::warn!("Pumpkin is currently under heavy development!");
log::info!("Report Issues on https://github.com/Snowiiii/Pumpkin/issues");
log::info!("Join our Discord for community support https://discord.com/invite/wT8XjrjKkf");
//log::info!("CPU {} Cores {}MHz", sys_info::cpu_num().unwrap(), sys_info::cpu_speed().unwrap());
// let rt = tokio::runtime::Builder::new_multi_thread()
// .enable_all()
// .build()