Skip to content

Commit

Permalink
checkpoint tracing
Browse files Browse the repository at this point in the history
  • Loading branch information
DolceTriade committed Mar 6, 2024
1 parent 20d0080 commit 3c5e2ca
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 14 deletions.
15 changes: 11 additions & 4 deletions blade/admin.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use anyhow::Context;
use actix_web::*;
use std::net::SocketAddr;
use anyhow::Context;
use futures::prelude::future::FutureExt;
use std::net::SocketAddr;
use tracing::instrument;

#[instrument]
Expand All @@ -28,8 +28,15 @@ pub async fn run_admin_server(

#[post("/admin/log_filter")]
#[instrument]
async fn set_filter(filter_channel: web::Data<tokio::sync::mpsc::Sender<String>>, body: String) -> impl Responder {
filter_channel.send(body).await.context("failed to set stuff").map_err(|e| error::ErrorInternalServerError(format!("{e}")))?;
async fn set_filter(
filter_channel: web::Data<tokio::sync::mpsc::Sender<String>>,
body: String,
) -> impl Responder {
filter_channel
.send(body)
.await
.context("failed to set stuff")
.map_err(|e| error::ErrorInternalServerError(format!("{e}")))?;
HttpResponse::Ok().await
}

Expand Down
23 changes: 13 additions & 10 deletions blade/main.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
use std::net::SocketAddr;

use cfg_if::cfg_if;
use tracing_subscriber::Registry;
use std::io::IsTerminal;
use tracing::{event, instrument, level_filters::LevelFilter};
use tracing_actix_web::{DefaultRootSpanBuilder, RootSpanBuilder};
use tracing_subscriber::{reload::Handle, EnvFilter};
use tracing_subscriber::{prelude::__tracing_subscriber_SubscriberExt, reload::Handle, EnvFilter, Layer};
use tracing_subscriber::util::SubscriberInitExt;
pub mod components;
pub mod routes;

Expand Down Expand Up @@ -51,23 +53,24 @@ cfg_if! {
session_lock_time: std::time::Duration,
}

fn init_logging() -> Handle<EnvFilter, impl Sized> {
let env_filter = tracing_subscriber::EnvFilter::builder().with_default_directive(LevelFilter::INFO.into()).from_env_lossy();
fn fmt_layer<S>(_show_spans: bool) -> Layer<S> {
let use_ansi = std::io::stdout().is_terminal();
let builder = tracing_subscriber::fmt()
let fmt_layer = tracing_subscriber::fmt::layer()
.with_ansi(use_ansi)
.compact()
.with_file(true)
.with_line_number(true)
.with_env_filter(env_filter)
.with_filter_reloading();
.with_line_number(true);
fmt_layer
}

let handle = builder.reload_handle();
fn init_logging() -> Handle<EnvFilter, impl Sized> {
let env_filter = tracing_subscriber::EnvFilter::builder().with_default_directive(LevelFilter::INFO.into()).from_env_lossy();
let layer = fmt_layer(false);
let (filter, handle) = tracing_subscriber::reload::Layer::new(env_filter);

builder.init();
tracing_subscriber::registry().with(layer).init();

handle

}

#[actix_web::main]
Expand Down

0 comments on commit 3c5e2ca

Please sign in to comment.