Skip to content
This repository was archived by the owner on Aug 2, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions src/config.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
use std::env;

pub const DEFAULT_HOST: &str = "127.0.0.1";
pub const DEFAULT_PORT: &str = "3000";

pub const READYZ_ROUTE: &str = "/readyz";
pub const LIVEZ_ROUTE: &str = "/livez";

pub fn get_server_addr() -> String {
let host = env::var("HTTP_HOST").unwrap_or("127.0.0.1".into());
let port = env::var("HTTP_PORT").unwrap_or("3000".into());
let host = env::var("HTTP_HOST").unwrap_or_else(|_| DEFAULT_HOST.into());
let port = env::var("HTTP_PORT").unwrap_or_else(|_| DEFAULT_PORT.into());
format!("{host}:{port}")
}
7 changes: 5 additions & 2 deletions src/logging.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@ use std::env;
use tracing::metadata::LevelFilter;
use tracing_subscriber::{EnvFilter, fmt};

pub const DEFAULT_LOG_ANSI: &str = "1";
pub const DEFAULT_LOG_LEVEL: LevelFilter = LevelFilter::INFO;

pub fn init_logger() {
let use_ansi = env::var("HTTP_LOG_ANSI").unwrap_or("1".to_owned());
let use_ansi = env::var("HTTP_LOG_ANSI").unwrap_or_else(|_| DEFAULT_LOG_ANSI.to_owned());
let use_ansi = !(use_ansi.is_empty() || use_ansi == "0"); // i.e. HTTP_LOG_ANSI=0 turns it off

let format = fmt::format()
Expand All @@ -15,7 +18,7 @@ pub fn init_logger() {
tracing_subscriber::fmt()
.with_env_filter(
EnvFilter::builder()
.with_default_directive(LevelFilter::INFO.into())
.with_default_directive(DEFAULT_LOG_LEVEL.into())
.from_env_lossy(),
)
.event_format(format)
Expand Down