From 00cf62cd09f2e9734ce6b4e2a34eac461d815a80 Mon Sep 17 00:00:00 2001 From: Daniel Sockwell Date: Tue, 9 Jul 2019 20:13:37 -0400 Subject: [PATCH 1/2] Hotfix to correct typo and set default log level to `warn` --- src/.env | 11 ++++++++--- src/config.rs | 19 ++++++++++++------- src/parse_client_request/user/postgres.rs | 1 + src/redis_to_client_stream/client_agent.rs | 2 +- 4 files changed, 22 insertions(+), 11 deletions(-) diff --git a/src/.env b/src/.env index 94e0c32..6fd4480 100644 --- a/src/.env +++ b/src/.env @@ -1,6 +1,11 @@ # Uncomment any of the variables below to customize your enviornment -#SERVER_ADDR= -#REDIS_ADDR= #POSTGRES_ADDR= -CORS_ALLOWED_METHODS="GET OPTIONS" +#REDIS_ADDR= +#SERVER_ADDR= +#SSE_UPDATE_INTERVAL= +#WS_UPDATE_INTERVAL= +#REDIS_POLL_INTERVAL= + +#Possible values for the log level are eror, warn, info, debug, trace +RUST_LOG=warn \ No newline at end of file diff --git a/src/config.rs b/src/config.rs index c7a1aa8..47b2529 100644 --- a/src/config.rs +++ b/src/config.rs @@ -18,14 +18,19 @@ const DEFAULT_WS_UPDATE_INTERVAL: u64 = 100; const DEFAULT_REDIS_POLL_INTERVAL: u64 = 100; lazy_static! { - static ref POSTGRES_ADDR: String = env::var("POSTGRESS_ADDR").unwrap_or_else(|_| { + static ref POSTGRES_ADDR: String = env::var("POSTGRES_ADDR").unwrap_or_else(|_| { let mut postgres_addr = DEFAULT_POSTGRES_ADDR.to_string(); postgres_addr.insert_str(11, - &env::var("USER").unwrap_or_else(|_| { - warn!("No USER env variable set. Connecting to Postgress with default `postgres` user"); - "postgres".to_string() - }).as_str() - ); + match &env::var("USER") { + Err(_) => { + warn!("No USER env variable set. Connecting to Postgress with default `postgres` user"); + "postgres" + }, + Ok(user) => { + warn!("No POSTGRES_ADDR env variable set. Connecting to Postgress with the current user: {}", &user); + user + } + }); postgres_addr }); @@ -64,8 +69,8 @@ pub fn cross_origin_resource_sharing() -> warp::filters::cors::Cors { /// Initialize logging and read values from `src/.env` pub fn logging_and_env() { - pretty_env_logger::init(); dotenv().ok(); + pretty_env_logger::init(); } /// Configure Postgres and return a connection diff --git a/src/parse_client_request/user/postgres.rs b/src/parse_client_request/user/postgres.rs index 50af32b..db56096 100644 --- a/src/parse_client_request/user/postgres.rs +++ b/src/parse_client_request/user/postgres.rs @@ -3,6 +3,7 @@ use crate::config; pub fn query_for_user_data(access_token: &str) -> (i64, Option>, Vec) { let conn = config::postgres(); + let query_result = conn .query( " diff --git a/src/redis_to_client_stream/client_agent.rs b/src/redis_to_client_stream/client_agent.rs index 1f5a972..dcc9cbe 100644 --- a/src/redis_to_client_stream/client_agent.rs +++ b/src/redis_to_client_stream/client_agent.rs @@ -1,5 +1,5 @@ //! Provides an interface between the `Warp` filters and the underlying -//! mechanics of talking with Redis/managing multiple threads. +//! mechanics of talking with Redis/managing multiple threads. //! //! The `ClientAgent`'s interface is very simple. All you can do with it is: //! * Create a totally new `ClientAgent` with no shared data; From 9ec245ccdb007904b2617c2d010721d837e9b15d Mon Sep 17 00:00:00 2001 From: Daniel Sockwell Date: Tue, 9 Jul 2019 22:20:11 -0400 Subject: [PATCH 2/2] Add additional logging for postgres connection/server status --- src/config.rs | 28 +++++++++++++++------------- src/main.rs | 5 +++++ 2 files changed, 20 insertions(+), 13 deletions(-) diff --git a/src/config.rs b/src/config.rs index 47b2529..70511ad 100644 --- a/src/config.rs +++ b/src/config.rs @@ -19,19 +19,20 @@ const DEFAULT_REDIS_POLL_INTERVAL: u64 = 100; lazy_static! { static ref POSTGRES_ADDR: String = env::var("POSTGRES_ADDR").unwrap_or_else(|_| { - let mut postgres_addr = DEFAULT_POSTGRES_ADDR.to_string(); - postgres_addr.insert_str(11, - match &env::var("USER") { - Err(_) => { - warn!("No USER env variable set. Connecting to Postgress with default `postgres` user"); - "postgres" - }, - Ok(user) => { - warn!("No POSTGRES_ADDR env variable set. Connecting to Postgress with the current user: {}", &user); - user - } - }); - postgres_addr + warn!("No POSTGRES_ADDR env variable set; using default postgres address."); + match &env::var("USER") { + Err(_) => { + let addr = DEFAULT_POSTGRES_ADDR.replace("@", format!("{}@", "postgres").as_str()); + warn!("No USER env variable set; using default `postgres` user.\n Using postgres address: {}\n", addr); + addr + }, + Ok(user) => { + let addr = DEFAULT_POSTGRES_ADDR.replace("@", format!("{}@", user).as_str()); + warn!("Connecting to postgres with current user.\n Using postgres address: {}\n", addr); + addr + } + } + }); static ref REDIS_ADDR: String = env::var("REDIS_ADDR").unwrap_or_else(|_| DEFAULT_REDIS_ADDR.to_owned()); @@ -71,6 +72,7 @@ pub fn cross_origin_resource_sharing() -> warp::filters::cors::Cors { pub fn logging_and_env() { dotenv().ok(); pretty_env_logger::init(); + POSTGRES_ADDR.to_string(); } /// Configure Postgres and return a connection diff --git a/src/main.rs b/src/main.rs index c989738..adb55e5 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,3 +1,4 @@ +use log::{log_enabled, Level}; use ragequit::{ any_of, config, parse_client_request::{sse, user, ws}, @@ -12,6 +13,10 @@ fn main() { let client_agent_sse = ClientAgent::blank(); let client_agent_ws = client_agent_sse.clone_with_shared_receiver(); + if log_enabled!(Level::Warn) { + println!("Streaming server initialized and ready to accept connections"); + }; + // Server Sent Events // // For SSE, the API requires users to use different endpoints, so we first filter based on