setup a dev mode to turn on and off while developing
This commit is contained in:
parent
c830c60e75
commit
1b656dc834
1 changed files with 15 additions and 3 deletions
18
src/main.rs
18
src/main.rs
|
@ -26,13 +26,17 @@ use tracing_subscriber::{layer::SubscriberExt, EnvFilter, Layer};
|
||||||
|
|
||||||
pub struct DomainRootSpanBuilder;
|
pub struct DomainRootSpanBuilder;
|
||||||
|
|
||||||
|
const DEV_MODE: bool = true;
|
||||||
|
|
||||||
impl RootSpanBuilder for DomainRootSpanBuilder {
|
impl RootSpanBuilder for DomainRootSpanBuilder {
|
||||||
fn on_request_start(request: &ServiceRequest) -> Span {
|
fn on_request_start(request: &ServiceRequest) -> Span {
|
||||||
let method = request.method();
|
let method = request.method();
|
||||||
let info = request.connection_info();
|
let info = request.connection_info();
|
||||||
let ip = info.realip_remote_addr().expect("hi");
|
let ip = info.realip_remote_addr().expect("hi");
|
||||||
let location = request.path();
|
let location = request.path();
|
||||||
info!(?method, ip, location);
|
if DEV_MODE {
|
||||||
|
info!(?method, ip, location);
|
||||||
|
}
|
||||||
tracing_actix_web::root_span!(request)
|
tracing_actix_web::root_span!(request)
|
||||||
|
|
||||||
// let client_id: &str = todo!("Somehow extract it from the authorization header");
|
// let client_id: &str = todo!("Somehow extract it from the authorization header");
|
||||||
|
@ -49,7 +53,11 @@ async fn main() -> std::io::Result<()> {
|
||||||
.rotation(Rotation::DAILY)
|
.rotation(Rotation::DAILY)
|
||||||
.filename_prefix("api")
|
.filename_prefix("api")
|
||||||
.filename_suffix("log")
|
.filename_suffix("log")
|
||||||
.build("/tmp/tfcsite")
|
.build(if DEV_MODE {
|
||||||
|
"/tmp/tfcsite"
|
||||||
|
} else {
|
||||||
|
"/storage/logs/tfcsite"
|
||||||
|
})
|
||||||
.expect("Shouldn't");
|
.expect("Shouldn't");
|
||||||
|
|
||||||
let filter = EnvFilter::builder()
|
let filter = EnvFilter::builder()
|
||||||
|
@ -88,7 +96,11 @@ async fn main() -> std::io::Result<()> {
|
||||||
App::new()
|
App::new()
|
||||||
.app_data(data.clone())
|
.app_data(data.clone())
|
||||||
.wrap(TracingLogger::<DomainRootSpanBuilder>::new())
|
.wrap(TracingLogger::<DomainRootSpanBuilder>::new())
|
||||||
.app_data(TempFileConfig::default().directory("/tmp/tfcsite"))
|
.app_data(TempFileConfig::default().directory(if DEV_MODE {
|
||||||
|
"/tmp/tfcsite"
|
||||||
|
} else {
|
||||||
|
"/storage/logs/tfcsite"
|
||||||
|
}))
|
||||||
.service(mt_form)
|
.service(mt_form)
|
||||||
.service(health_form)
|
.service(health_form)
|
||||||
.service(mt_parent_form)
|
.service(mt_parent_form)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue