Skip to content

Commit

Permalink
Logging system info (#279)
Browse files Browse the repository at this point in the history
* Add Git hash to version info, display version on startup, remove ms from log timestamp

* Add startup info
  • Loading branch information
Commandcracker authored Nov 15, 2024
1 parent 7b64ca1 commit e419045
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 16 deletions.
2 changes: 2 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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

Expand Down
3 changes: 3 additions & 0 deletions pumpkin/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
26 changes: 18 additions & 8 deletions pumpkin/build.rs
Original file line number Diff line number Diff line change
@@ -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);
}
17 changes: 10 additions & 7 deletions pumpkin/src/command/commands/cmd_pumpkin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"];
Expand All @@ -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>(
Expand All @@ -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(())
}
}
Expand Down
37 changes: 36 additions & 1 deletion pumpkin/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit e419045

Please sign in to comment.