fix: logging

This commit is contained in:
Timo Kösters 2021-04-24 13:34:35 +02:00
parent 226045ea4b
commit 2fc1ec2ad5
No known key found for this signature in database
GPG Key ID: 24DA7517711A2BA4
3 changed files with 33 additions and 39 deletions

6
Cargo.lock generated
View File

@ -1558,7 +1558,7 @@ dependencies = [
[[package]] [[package]]
name = "rocket" name = "rocket"
version = "0.5.0-dev" 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 = [ dependencies = [
"async-trait", "async-trait",
"atomic", "atomic",
@ -1593,7 +1593,7 @@ dependencies = [
[[package]] [[package]]
name = "rocket_codegen" name = "rocket_codegen"
version = "0.5.0-dev" 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 = [ dependencies = [
"devise", "devise",
"glob", "glob",
@ -1606,7 +1606,7 @@ dependencies = [
[[package]] [[package]]
name = "rocket_http" name = "rocket_http"
version = "0.5.0-dev" 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 = [ dependencies = [
"cookie", "cookie",
"either", "either",

View File

@ -14,7 +14,7 @@ edition = "2018"
[dependencies] [dependencies]
# Used to handle requests # Used to handle requests
# TODO: This can become optional as soon as proper configs are supported # 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"] } #rocket = { git = "https://github.com/timokoesters/Rocket.git", branch = "empty_parameters", default-features = false, features = ["tls"] }
# Used for matrix spec type definitions and helpers # Used for matrix spec type definitions and helpers

View File

@ -30,30 +30,7 @@ use rocket::{
use tracing::span; use tracing::span;
use tracing_subscriber::{prelude::*, Registry}; use tracing_subscriber::{prelude::*, Registry};
async fn setup_rocket() -> (rocket::Rocket<rocket::Build>, Config) { fn setup_rocket(config: Figment, data: Database) -> rocket::Rocket<rocket::Build> {
// 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);
let rocket = rocket::custom(config) let rocket = rocket::custom(config)
.manage(data) .manage(data)
.mount( .mount(
@ -192,12 +169,33 @@ async fn setup_rocket() -> (rocket::Rocket<rocket::Build>, Config) {
], ],
); );
(rocket, parsed_config) rocket
} }
#[rocket::main] #[rocket::main]
async fn 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 { if config.allow_jaeger {
let (tracer, _uninstall) = opentelemetry_jaeger::new_pipeline() 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 root = span!(tracing::Level::INFO, "app_start", work_units = 2);
let _enter = root.enter(); let _enter = root.enter();
rocket.launch().await.unwrap();
} else { } else {
//std::env::set_var("CONDUIT_LOG", config.log); std::env::set_var("CONDUIT_LOG", config.log);
//pretty_env_logger::init_custom_env("CONDUIT_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();
} }
let rocket = setup_rocket(raw_config, db);
rocket.launch().await.unwrap();
} }
#[catch(404)] #[catch(404)]