Logging #26
@ -5,15 +5,13 @@
|
|||||||
|
|
||||||
use getset::Getters;
|
use getset::Getters;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A immutable record of all the information needed to connect to the SQL database.
|
* A immutable record of all the information needed to connect to the SQL database.
|
||||||
*/
|
*/
|
||||||
#[allow(clippy::module_name_repetitions)]
|
#[allow(clippy::module_name_repetitions)]
|
||||||
#[derive(Clone, PartialEq, Eq, Getters, Debug)]
|
#[derive(Clone, PartialEq, Eq, Getters, Debug)]
|
||||||
#[getset(get = "pub")]
|
#[getset(get = "pub")]
|
||||||
pub struct DbConfig
|
pub struct DbConfig {
|
||||||
{
|
|
||||||
/// Database connection address.
|
/// Database connection address.
|
||||||
/// Is an option to allow constructing a default config during compile time.<br>
|
/// Is an option to allow constructing a default config during compile time.<br>
|
||||||
addr: String,
|
addr: String,
|
||||||
@ -21,15 +19,13 @@ pub struct DbConfig
|
|||||||
port: u16,
|
port: u16,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for DbConfig
|
impl Default for DbConfig {
|
||||||
{
|
fn default() -> Self {
|
||||||
fn default() -> Self
|
Self {
|
||||||
{
|
addr: String::from("localhost"),
|
||||||
Self {
|
port: 6969,
|
||||||
addr: String::from("localhost"),
|
}
|
||||||
port: 6969
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -38,28 +34,24 @@ impl Default for DbConfig
|
|||||||
#[derive(Default, Debug)]
|
#[derive(Default, Debug)]
|
||||||
pub struct DbConfigBuilder(DbConfig);
|
pub struct DbConfigBuilder(DbConfig);
|
||||||
|
|
||||||
impl DbConfigBuilder
|
impl DbConfigBuilder {
|
||||||
{
|
/// Get a new [`DbConfigBuilder`]
|
||||||
/// Get a new [`DbConfigBuilder`]
|
#[must_use]
|
||||||
#[must_use]
|
pub fn new() -> Self {
|
||||||
pub fn new() -> Self
|
Self::default()
|
||||||
{
|
}
|
||||||
Self::default()
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Set the address to the location of the database.
|
/// Set the address to the location of the database.
|
||||||
#[must_use]
|
#[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.0.addr = addr.into();
|
self
|
||||||
self
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/// Set the port to the port the database uses.
|
/// Set the port to the port the database uses.
|
||||||
#[must_use]
|
#[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.0.port = port.into();
|
self
|
||||||
self
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -2,8 +2,8 @@
|
|||||||
* Containing all singleton and thread-safe structs related to configuring `WANessa`.
|
* Containing all singleton and thread-safe structs related to configuring `WANessa`.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
pub mod log;
|
|
||||||
pub mod db;
|
pub mod db;
|
||||||
|
pub mod log;
|
||||||
|
|
||||||
use crate::db::DbConfig;
|
use crate::db::DbConfig;
|
||||||
use crate::log::LogSettings;
|
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()));
|
pub static DB_CONFIG: Lazy<Arc<DbConfig>> = Lazy::new(|| Arc::new(DbConfig::default()));
|
||||||
|
|
||||||
/// Singelton [`LogSettings`].
|
/// 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()));
|
||||||
|
@ -12,16 +12,13 @@ use std::path::PathBuf;
|
|||||||
use getset::Getters;
|
use getset::Getters;
|
||||||
use getset::Setters;
|
use getset::Setters;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* All settings relating to how the project logs information.
|
* All settings relating to how the project logs information.
|
||||||
*/
|
*/
|
||||||
#[allow(clippy::struct_excessive_bools)]
|
#[allow(clippy::struct_excessive_bools)]
|
||||||
#[derive(Clone, PartialEq, Eq, Getters, Setters, Debug)]
|
#[derive(Clone, PartialEq, Eq, Getters, Setters, Debug)]
|
||||||
#[getset(get = "pub", set = "pub")]
|
#[getset(get = "pub", set = "pub")]
|
||||||
pub struct LogSettings
|
pub struct LogSettings {
|
||||||
{
|
|
||||||
/// See [`LogVerbosity`].<br>
|
/// See [`LogVerbosity`].<br>
|
||||||
verbosity: LogVerbosity,
|
verbosity: LogVerbosity,
|
||||||
/// Logs UTC time and date of message, if true.<br>
|
/// Logs UTC time and date of message, if true.<br>
|
||||||
@ -32,7 +29,7 @@ pub struct LogSettings
|
|||||||
/// Logs location in code, where the message was logged, if true.<br>
|
/// Logs location in code, where the message was logged, if true.<br>
|
||||||
location: bool,
|
location: bool,
|
||||||
/// If `Some(path)` tries to also write the log to `path` in addition to stderr/stderr.<br>
|
/// If `Some(path)` tries to also write the log to `path` in addition to stderr/stderr.<br>
|
||||||
#[getset(skip)]
|
#[getset(skip)]
|
||||||
path: Option<PathBuf>,
|
path: Option<PathBuf>,
|
||||||
/// Logs to standard out, if true.<br>
|
/// Logs to standard out, if true.<br>
|
||||||
stdout: bool,
|
stdout: bool,
|
||||||
@ -40,36 +37,31 @@ pub struct LogSettings
|
|||||||
stderr: bool,
|
stderr: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl LogSettings
|
impl LogSettings {
|
||||||
{
|
/// Setter for log path, including syntactic sugar for the [Option] enum.
|
||||||
/// 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();
|
||||||
{
|
}
|
||||||
self.path = path.into();
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Getter for the log path.
|
/// Getter for the log path.
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn path(&self) -> Option<&Path>
|
pub fn path(&self) -> Option<&Path> {
|
||||||
{
|
self.path.as_deref()
|
||||||
self.path.as_deref()
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for LogSettings
|
impl Default for LogSettings {
|
||||||
{
|
fn default() -> Self {
|
||||||
fn default() -> Self
|
Self {
|
||||||
{
|
verbosity: Warning,
|
||||||
Self {
|
time: false,
|
||||||
verbosity: Warning,
|
time_format: String::from("%F-%T:%f"),
|
||||||
time: false,
|
location: false,
|
||||||
time_format: String::from("%F-%T:%f"),
|
stdout: true,
|
||||||
location: false,
|
stderr: true,
|
||||||
stdout: true,
|
path: None,
|
||||||
stderr: true,
|
}
|
||||||
path: None,
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -104,4 +96,3 @@ impl Ord for LogVerbosity {
|
|||||||
(*self as usize).cmp(&(*other as usize))
|
(*self as usize).cmp(&(*other as usize))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user