Make Logging configurable

This commit is contained in:
Snowiiii committed 2024-10-11 16:41:52 +02:00
1 parent 9ac4bdbd50
commit bcbde20623
8 files changed
+141 -15

No files matched your search

+6 -2
View File
@@ -4,11 +4,15 @@ use serde::{Deserialize, Serialize};
pub struct CommandsConfig {
/// Are commands from the Console accepted ?
pub use_console: bool,
// TODO: commands...
/// Should be commands from players be logged in console?
pub log_console: bool, // TODO: commands...
}
impl Default for CommandsConfig {
fn default() -> Self {
Self { use_console: true }
Self {
use_console: true,
log_console: true,
}
}
}
+3
View File
@@ -1,4 +1,5 @@
use log::warn;
use logging::LoggingConfig;
use pumpkin_core::{Difficulty, GameMode};
use serde::{de::DeserializeOwned, Deserialize, Serialize};
@@ -10,6 +11,7 @@ use std::{
};
pub mod auth;
pub mod logging;
pub mod proxy;
pub mod resource_pack;
@@ -46,6 +48,7 @@ pub struct AdvancedConfiguration {
pub commands: CommandsConfig,
pub rcon: RCONConfig,
pub pvp: PVPConfig,
pub logging: LoggingConfig,
}
#[derive(Serialize, Deserialize)]
+40
View File
@@ -0,0 +1,40 @@
use serde::{Deserialize, Serialize};
#[derive(Deserialize, Serialize)]
pub struct LoggingConfig {
pub enabled: bool,
pub level: LevelFilter,
pub env: bool,
pub threads: bool,
pub color: bool,
pub timestamp: bool,
}
impl Default for LoggingConfig {
fn default() -> Self {
Self {
enabled: true,
level: LevelFilter::Info,
env: false,
threads: true,
color: true,
timestamp: true,
}
}
}
#[derive(Deserialize, Serialize, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Debug, Hash)]
pub enum LevelFilter {
/// A level lower than all log levels.
Off,
/// Corresponds to the `Error` log level.
Error,
/// Corresponds to the `Warn` log level.
Warn,
/// Corresponds to the `Info` log level.
Info,
/// Corresponds to the `Debug` log level.
Debug,
/// Corresponds to the `Trace` log level.
Trace,
}
+26
View File
@@ -13,6 +13,31 @@ pub struct RCONConfig {
/// The maximum number of concurrent RCON connections allowed.
/// If 0 there is no limit
pub max_connections: u32,
/// RCON Logging
pub logging: RCONLogging,
}
#[derive(Deserialize, Serialize, Clone, Debug)]
pub struct RCONLogging {
/// Whether successful RCON logins should be logged.
pub log_logged_successfully: bool,
/// Whether failed RCON login attempts with incorrect passwords should be logged.
pub log_wrong_password: bool,
/// Whether all RCON commands, regardless of success or failure, should be logged.
pub log_commands: bool,
/// Whether RCON quit commands should be logged.
pub log_quit: bool,
}
impl Default for RCONLogging {
fn default() -> Self {
Self {
log_logged_successfully: true,
log_wrong_password: true,
log_commands: true,
log_quit: true,
}
}
}
impl Default for RCONConfig {
@@ -22,6 +47,7 @@ impl Default for RCONConfig {
address: SocketAddr::new(Ipv4Addr::new(0, 0, 0, 0).into(), 25575),
password: "".to_string(),
max_connections: 0,
logging: Default::default(),
}
}
}