Logging #26

Open
leon wants to merge 33 commits from Logging into main
3 changed files with 53 additions and 69 deletions
Showing only changes of commit cbfa4cbfdf - Show all commits

View File

@ -5,15 +5,13 @@
use getset::Getters;
/**
* A immutable record of all the information needed to connect to the SQL database.
*/
#[allow(clippy::module_name_repetitions)]
#[derive(Clone, PartialEq, Eq, Getters, Debug)]
#[getset(get = "pub")]
pub struct DbConfig
{
pub struct DbConfig {
/// Database connection address.
/// Is an option to allow constructing a default config during compile time.<br>
addr: String,
@ -21,13 +19,11 @@ pub struct DbConfig
port: u16,
}
impl Default for DbConfig
{
fn default() -> Self
{
impl Default for DbConfig {
fn default() -> Self {
Self {
addr: String::from("localhost"),
port: 6969
port: 6969,
}
}
}
@ -38,27 +34,23 @@ impl Default for DbConfig
#[derive(Default, Debug)]
pub struct DbConfigBuilder(DbConfig);
impl DbConfigBuilder
{
impl DbConfigBuilder {
/// Get a new [`DbConfigBuilder`]
#[must_use]
pub fn new() -> Self
{
pub fn new() -> Self {
Self::default()
}
/// Set the address to the location of the database.
#[must_use]
pub fn set_addr(mut self, addr: impl Into<String>) -> Self
{
pub fn set_addr(mut self, addr: impl Into<String>) -> Self {
self.0.addr = addr.into();
self
}
/// Set the port to the port the database uses.
#[must_use]
pub fn set_port(mut self, port: impl Into<u16>) -> Self
{
pub fn set_port(mut self, port: impl Into<u16>) -> Self {
self.0.port = port.into();
self
}

View File

@ -2,8 +2,8 @@
* Containing all singleton and thread-safe structs related to configuring `WANessa`.
*/
pub mod log;
pub mod db;
pub mod log;
use crate::db::DbConfig;
use crate::log::LogSettings;
@ -18,4 +18,5 @@ use once_cell::sync::Lazy;
pub static DB_CONFIG: Lazy<Arc<DbConfig>> = Lazy::new(|| Arc::new(DbConfig::default()));
/// Singelton [`LogSettings`].
pub static LOG_SETTINGS: Lazy<RwLock<LogSettings>> = Lazy::new(|| RwLock::new(LogSettings::default()));
pub static LOG_SETTINGS: Lazy<RwLock<LogSettings>> =
Lazy::new(|| RwLock::new(LogSettings::default()));

View File

@ -12,16 +12,13 @@ use std::path::PathBuf;
use getset::Getters;
use getset::Setters;
/**
* All settings relating to how the project logs information.
*/
#[allow(clippy::struct_excessive_bools)]
#[derive(Clone, PartialEq, Eq, Getters, Setters, Debug)]
#[getset(get = "pub", set = "pub")]
pub struct LogSettings
{
pub struct LogSettings {
/// See [`LogVerbosity`].<br>
verbosity: LogVerbosity,
/// Logs UTC time and date of message, if true.<br>
@ -40,26 +37,21 @@ pub struct LogSettings
stderr: bool,
}
impl LogSettings
{
impl LogSettings {
/// Setter for log path, including syntactic sugar for the [Option] enum.
pub fn set_path(&mut self, path: impl Into<Option<PathBuf>>)
{
pub fn set_path(&mut self, path: impl Into<Option<PathBuf>>) {
self.path = path.into();
}
/// Getter for the log path.
#[must_use]
pub fn path(&self) -> Option<&Path>
{
pub fn path(&self) -> Option<&Path> {
self.path.as_deref()
}
}
impl Default for LogSettings
{
fn default() -> Self
{
impl Default for LogSettings {
fn default() -> Self {
Self {
verbosity: Warning,
time: false,
@ -104,4 +96,3 @@ impl Ord for LogVerbosity {
(*self as usize).cmp(&(*other as usize))
}
}