fix: logging
This commit is contained in:
parent
226045ea4b
commit
2fc1ec2ad5
3 changed files with 33 additions and 39 deletions
6
Cargo.lock
generated
6
Cargo.lock
generated
|
@ -1558,7 +1558,7 @@ dependencies = [
|
|||
[[package]]
|
||||
name = "rocket"
|
||||
version = "0.5.0-dev"
|
||||
source = "git+https://github.com/SergioBenitez/Rocket.git?rev=e1307ddf48dac14e6a37e526098732327bcb86f0#e1307ddf48dac14e6a37e526098732327bcb86f0"
|
||||
source = "git+https://github.com/SergioBenitez/Rocket.git?rev=801e04bd5369eb39e126c75f6d11e1e9597304d8#801e04bd5369eb39e126c75f6d11e1e9597304d8"
|
||||
dependencies = [
|
||||
"async-trait",
|
||||
"atomic",
|
||||
|
@ -1593,7 +1593,7 @@ dependencies = [
|
|||
[[package]]
|
||||
name = "rocket_codegen"
|
||||
version = "0.5.0-dev"
|
||||
source = "git+https://github.com/SergioBenitez/Rocket.git?rev=e1307ddf48dac14e6a37e526098732327bcb86f0#e1307ddf48dac14e6a37e526098732327bcb86f0"
|
||||
source = "git+https://github.com/SergioBenitez/Rocket.git?rev=801e04bd5369eb39e126c75f6d11e1e9597304d8#801e04bd5369eb39e126c75f6d11e1e9597304d8"
|
||||
dependencies = [
|
||||
"devise",
|
||||
"glob",
|
||||
|
@ -1606,7 +1606,7 @@ dependencies = [
|
|||
[[package]]
|
||||
name = "rocket_http"
|
||||
version = "0.5.0-dev"
|
||||
source = "git+https://github.com/SergioBenitez/Rocket.git?rev=e1307ddf48dac14e6a37e526098732327bcb86f0#e1307ddf48dac14e6a37e526098732327bcb86f0"
|
||||
source = "git+https://github.com/SergioBenitez/Rocket.git?rev=801e04bd5369eb39e126c75f6d11e1e9597304d8#801e04bd5369eb39e126c75f6d11e1e9597304d8"
|
||||
dependencies = [
|
||||
"cookie",
|
||||
"either",
|
||||
|
|
|
@ -14,7 +14,7 @@ edition = "2018"
|
|||
[dependencies]
|
||||
# Used to handle requests
|
||||
# TODO: This can become optional as soon as proper configs are supported
|
||||
rocket = { git = "https://github.com/SergioBenitez/Rocket.git", rev = "e1307ddf48dac14e6a37e526098732327bcb86f0", features = ["tls"] } # Used to handle requests
|
||||
rocket = { git = "https://github.com/SergioBenitez/Rocket.git", rev = "801e04bd5369eb39e126c75f6d11e1e9597304d8", features = ["tls"] } # Used to handle requests
|
||||
#rocket = { git = "https://github.com/timokoesters/Rocket.git", branch = "empty_parameters", default-features = false, features = ["tls"] }
|
||||
|
||||
# Used for matrix spec type definitions and helpers
|
||||
|
|
64
src/main.rs
64
src/main.rs
|
@ -30,30 +30,7 @@ use rocket::{
|
|||
use tracing::span;
|
||||
use tracing_subscriber::{prelude::*, Registry};
|
||||
|
||||
async fn setup_rocket() -> (rocket::Rocket<rocket::Build>, Config) {
|
||||
// Force log level off, so we can use our own logger
|
||||
//std::env::set_var("CONDUIT_LOG_LEVEL", "off");
|
||||
|
||||
let config =
|
||||
Figment::from(rocket::Config::release_default())
|
||||
.merge(
|
||||
Toml::file(Env::var("CONDUIT_CONFIG").expect(
|
||||
"The CONDUIT_CONFIG env var needs to be set. Example: /etc/conduit.toml",
|
||||
))
|
||||
.nested(),
|
||||
)
|
||||
.merge(Env::prefixed("CONDUIT_").global());
|
||||
|
||||
let parsed_config = config
|
||||
.extract::<Config>()
|
||||
.expect("It looks like your config is invalid. Please take a look at the error");
|
||||
|
||||
let data = Database::load_or_create(parsed_config.clone())
|
||||
.await
|
||||
.expect("config is valid");
|
||||
|
||||
data.sending.start_handler(&data);
|
||||
|
||||
fn setup_rocket(config: Figment, data: Database) -> rocket::Rocket<rocket::Build> {
|
||||
let rocket = rocket::custom(config)
|
||||
.manage(data)
|
||||
.mount(
|
||||
|
@ -192,12 +169,33 @@ async fn setup_rocket() -> (rocket::Rocket<rocket::Build>, Config) {
|
|||
],
|
||||
);
|
||||
|
||||
(rocket, parsed_config)
|
||||
rocket
|
||||
}
|
||||
|
||||
#[rocket::main]
|
||||
async fn main() {
|
||||
let (rocket, config) = setup_rocket().await;
|
||||
// Force log level off, so we can use our own logger
|
||||
std::env::set_var("CONDUIT_LOG_LEVEL", "off");
|
||||
|
||||
let raw_config =
|
||||
Figment::from(rocket::Config::release_default())
|
||||
.merge(
|
||||
Toml::file(Env::var("CONDUIT_CONFIG").expect(
|
||||
"The CONDUIT_CONFIG env var needs to be set. Example: /etc/conduit.toml",
|
||||
))
|
||||
.nested(),
|
||||
)
|
||||
.merge(Env::prefixed("CONDUIT_").global());
|
||||
|
||||
let config = raw_config
|
||||
.extract::<Config>()
|
||||
.expect("It looks like your config is invalid. Please take a look at the error");
|
||||
|
||||
let db = Database::load_or_create(config.clone())
|
||||
.await
|
||||
.expect("config is valid");
|
||||
|
||||
db.sending.start_handler(&db);
|
||||
|
||||
if config.allow_jaeger {
|
||||
let (tracer, _uninstall) = opentelemetry_jaeger::new_pipeline()
|
||||
|
@ -209,17 +207,13 @@ async fn main() {
|
|||
|
||||
let root = span!(tracing::Level::INFO, "app_start", work_units = 2);
|
||||
let _enter = root.enter();
|
||||
|
||||
rocket.launch().await.unwrap();
|
||||
} else {
|
||||
//std::env::set_var("CONDUIT_LOG", config.log);
|
||||
//pretty_env_logger::init_custom_env("CONDUIT_LOG");
|
||||
|
||||
//let root = span!(tracing::Level::INFO, "app_start", work_units = 2);
|
||||
//let _enter = root.enter();
|
||||
|
||||
rocket.launch().await.unwrap();
|
||||
std::env::set_var("CONDUIT_LOG", config.log);
|
||||
pretty_env_logger::init_custom_env("CONDUIT_LOG");
|
||||
}
|
||||
|
||||
let rocket = setup_rocket(raw_config, db);
|
||||
rocket.launch().await.unwrap();
|
||||
}
|
||||
|
||||
#[catch(404)]
|
||||
|
|
Loading…
Reference in a new issue