11use async_graphql:: { EmptyMutation , EmptySubscription , Schema } ;
2+ use axum:: extract:: Path ;
23use axum:: http:: StatusCode ;
34use axum:: response:: { Html , IntoResponse } ;
45use axum:: routing:: { get, post} ;
@@ -18,17 +19,24 @@ use serde_json::json;
1819use tokio:: select;
1920use tokio:: signal:: unix:: { SignalKind , signal} ;
2021use tracing:: info;
22+ use tracing:: level_filters:: LevelFilter ;
23+ use tracing_subscriber:: layer:: SubscriberExt as _;
24+ use tracing_subscriber:: util:: SubscriberInitExt ;
25+ use tracing_subscriber:: { Registry , fmt, reload} ;
2126use url:: Url ;
2227
2328use crate :: clients:: TiledClient ;
24- use crate :: config:: GlazedConfig ;
29+ use crate :: config:: { GlazedConfig , LogLevel } ;
2530use crate :: handlers:: { download_handler, graphiql_handler, graphql_handler} ;
2631use crate :: model:: TiledQuery ;
2732
2833#[ tokio:: main]
2934async fn main ( ) -> Result < ( ) , Box < dyn std:: error:: Error > > {
30- let subscriber = tracing_subscriber:: FmtSubscriber :: new ( ) ;
31- tracing:: subscriber:: set_global_default ( subscriber) ?;
35+ let ( filter, filter_reload) = reload:: Layer :: new ( LevelFilter :: INFO ) ;
36+ tracing_subscriber:: registry ( )
37+ . with ( filter)
38+ . with ( fmt:: Layer :: default ( ) )
39+ . init ( ) ;
3240
3341 let cli = Cli :: init ( ) ;
3442 let config;
@@ -41,15 +49,21 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
4149 info ! ( "Using default config" ) ;
4250 config = GlazedConfig :: default ( ) ;
4351 }
52+ filter_reload
53+ . modify ( |f| * f = config. log_level . into ( ) )
54+ . unwrap ( ) ;
4455 match cli. command {
45- Commands :: Serve => serve ( config) . await ,
56+ Commands :: Serve => serve ( config, filter_reload ) . await ,
4657 }
4758}
4859
4960#[ derive( Clone ) ]
5061pub struct RootAddress ( Url ) ;
5162
52- async fn serve ( config : GlazedConfig ) -> Result < ( ) , Box < dyn std:: error:: Error > > {
63+ async fn serve (
64+ config : GlazedConfig ,
65+ reload : reload:: Handle < LevelFilter , Registry > ,
66+ ) -> Result < ( ) , Box < dyn std:: error:: Error > > {
5367 let client = TiledClient :: new ( config. tiled_client . address ) ;
5468 let public_address = config
5569 . public_address
@@ -72,6 +86,12 @@ async fn serve(config: GlazedConfig) -> Result<(), Box<dyn std::error::Error>> {
7286 get ( Json ( json ! ( { "version" : env!( "CARGO_PKG_VERSION" ) } ) ) ) ,
7387 )
7488 . route ( "/asset/{run}/{stream}/{det}/{id}" , get ( download_handler) )
89+ . route (
90+ "/loglevel/{level}" ,
91+ post ( |level : Path < LogLevel > | async move {
92+ reload. clone ( ) . modify ( |f| * f = level. 0 . into ( ) ) . unwrap ( ) ;
93+ } ) ,
94+ )
7595 . with_state ( client)
7696 . fallback ( (
7797 StatusCode :: NOT_FOUND ,
0 commit comments