diff options
author | FxQnLr <[email protected]> | 2024-06-17 12:04:44 +0200 |
---|---|---|
committer | GitHub <[email protected]> | 2024-06-17 12:04:44 +0200 |
commit | 38025a3e35c960ed03f520f911b40608b9f9abd3 (patch) | |
tree | 6ee75dc72f1e2401bce4664ec5bae68aaf1e7df0 /src | |
parent | c6baa076dc41dd43b3888d713fcf39fa901d2cd3 (diff) | |
parent | 45724c4a8b293e8696ef487368f72f90a5c7a01d (diff) | |
download | webol-38025a3e35c960ed03f520f911b40608b9f9abd3.tar webol-38025a3e35c960ed03f520f911b40608b9f9abd3.tar.gz webol-38025a3e35c960ed03f520f911b40608b9f9abd3.zip |
Merge pull request #38 from FxQnLr/time
Time
Diffstat (limited to 'src')
-rw-r--r-- | src/config.rs | 1 | ||||
-rw-r--r-- | src/main.rs | 27 |
2 files changed, 15 insertions, 13 deletions
diff --git a/src/config.rs b/src/config.rs index 7c91c08..18c3bab 100644 --- a/src/config.rs +++ b/src/config.rs | |||
@@ -8,7 +8,6 @@ pub struct Config { | |||
8 | pub serveraddr: String, | 8 | pub serveraddr: String, |
9 | pub pingtimeout: i64, | 9 | pub pingtimeout: i64, |
10 | pub pingthreshold: u64, | 10 | pub pingthreshold: u64, |
11 | pub timeoffset: i8, | ||
12 | pub auth: Auth, | 11 | pub auth: Auth, |
13 | } | 12 | } |
14 | 13 | ||
diff --git a/src/main.rs b/src/main.rs index 204c318..b550dd8 100644 --- a/src/main.rs +++ b/src/main.rs | |||
@@ -1,5 +1,8 @@ | |||
1 | use crate::{ | 1 | use crate::{ |
2 | config::Config, routes::{device, start, status}, services::ping::{BroadcastCommand, StatusMap}, storage::Device | 2 | config::Config, |
3 | routes::{device, start, status}, | ||
4 | services::ping::{BroadcastCommand, StatusMap}, | ||
5 | storage::Device, | ||
3 | }; | 6 | }; |
4 | use axum::{ | 7 | use axum::{ |
5 | middleware::from_fn_with_state, | 8 | middleware::from_fn_with_state, |
@@ -8,14 +11,9 @@ use axum::{ | |||
8 | }; | 11 | }; |
9 | use dashmap::DashMap; | 12 | use dashmap::DashMap; |
10 | use std::{env, sync::Arc}; | 13 | use std::{env, sync::Arc}; |
11 | use time::UtcOffset; | ||
12 | use tokio::sync::broadcast::{channel, Sender}; | 14 | use tokio::sync::broadcast::{channel, Sender}; |
13 | use tracing::{info, level_filters::LevelFilter, trace}; | 15 | use tracing::{info, level_filters::LevelFilter, trace}; |
14 | use tracing_subscriber::{ | 16 | use tracing_subscriber::{fmt, prelude::*, EnvFilter}; |
15 | fmt::{self, time::OffsetTime}, | ||
16 | prelude::*, | ||
17 | EnvFilter, | ||
18 | }; | ||
19 | use utoipa::{ | 17 | use utoipa::{ |
20 | openapi::security::{ApiKey, ApiKeyValue, SecurityScheme}, | 18 | openapi::security::{ApiKey, ApiKeyValue, SecurityScheme}, |
21 | Modify, OpenApi, | 19 | Modify, OpenApi, |
@@ -24,10 +22,10 @@ use utoipa_swagger_ui::SwaggerUi; | |||
24 | 22 | ||
25 | mod auth; | 23 | mod auth; |
26 | mod config; | 24 | mod config; |
27 | mod storage; | ||
28 | mod error; | 25 | mod error; |
29 | mod routes; | 26 | mod routes; |
30 | mod services; | 27 | mod services; |
28 | mod storage; | ||
31 | mod wol; | 29 | mod wol; |
32 | 30 | ||
33 | #[derive(OpenApi)] | 31 | #[derive(OpenApi)] |
@@ -73,15 +71,20 @@ async fn main() -> color_eyre::eyre::Result<()> { | |||
73 | 71 | ||
74 | let config = Config::load()?; | 72 | let config = Config::load()?; |
75 | 73 | ||
76 | let time_format = | 74 | let writer_time = |
77 | time::macros::format_description!("[year]-[month]-[day] [hour]:[minute]:[second]"); | 75 | tracing_subscriber::fmt::time::ChronoLocal::new("%Y-%m-%d %H:%M:%S%.6f%:z".to_string()); |
78 | let time = OffsetTime::new(UtcOffset::from_hms(config.timeoffset, 0, 0)?, time_format); | 76 | let time = tracing_subscriber::fmt::time::ChronoLocal::new("%Y-%m-%d %H:%M:%S%:z".to_string()); |
79 | 77 | ||
80 | let file_appender = tracing_appender::rolling::daily("logs", "webol.log"); | 78 | let file_appender = tracing_appender::rolling::daily("logs", "webol.log"); |
81 | let (non_blocking, _guard) = tracing_appender::non_blocking(file_appender); | 79 | let (non_blocking, _guard) = tracing_appender::non_blocking(file_appender); |
82 | 80 | ||
83 | tracing_subscriber::registry() | 81 | tracing_subscriber::registry() |
84 | .with(fmt::layer().with_writer(non_blocking).with_ansi(false)) | 82 | .with( |
83 | fmt::layer() | ||
84 | .with_timer(writer_time) | ||
85 | .with_writer(non_blocking) | ||
86 | .with_ansi(false), | ||
87 | ) | ||
85 | .with(fmt::layer().with_timer(time)) | 88 | .with(fmt::layer().with_timer(time)) |
86 | .with( | 89 | .with( |
87 | EnvFilter::builder() | 90 | EnvFilter::builder() |