summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/config.rs1
-rw-r--r--src/main.rs27
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 @@
1use crate::{ 1use 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};
4use axum::{ 7use axum::{
5 middleware::from_fn_with_state, 8 middleware::from_fn_with_state,
@@ -8,14 +11,9 @@ use axum::{
8}; 11};
9use dashmap::DashMap; 12use dashmap::DashMap;
10use std::{env, sync::Arc}; 13use std::{env, sync::Arc};
11use time::UtcOffset;
12use tokio::sync::broadcast::{channel, Sender}; 14use tokio::sync::broadcast::{channel, Sender};
13use tracing::{info, level_filters::LevelFilter, trace}; 15use tracing::{info, level_filters::LevelFilter, trace};
14use tracing_subscriber::{ 16use tracing_subscriber::{fmt, prelude::*, EnvFilter};
15 fmt::{self, time::OffsetTime},
16 prelude::*,
17 EnvFilter,
18};
19use utoipa::{ 17use 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
25mod auth; 23mod auth;
26mod config; 24mod config;
27mod storage;
28mod error; 25mod error;
29mod routes; 26mod routes;
30mod services; 27mod services;
28mod storage;
31mod wol; 29mod 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()