Set up info logging even if the server is started with no RUST_LOG variable #17
|
@ -9,7 +9,9 @@ use actix_web::{
|
||||||
web, App, HttpServer,
|
web, App, HttpServer,
|
||||||
};
|
};
|
||||||
use clap::Parser;
|
use clap::Parser;
|
||||||
|
use env_logger::{Env, WriteStyle};
|
||||||
use handlebars::Handlebars;
|
use handlebars::Handlebars;
|
||||||
|
use log::LevelFilter;
|
||||||
|
|
||||||
mod errors;
|
mod errors;
|
||||||
mod main_pages;
|
mod main_pages;
|
||||||
|
@ -28,8 +30,9 @@ struct Config {
|
||||||
/// The address on which to listen
|
/// The address on which to listen
|
||||||
address: SocketAddr,
|
address: SocketAddr,
|
||||||
#[clap(long, action)]
|
#[clap(long, action)]
|
||||||
/// Whether to start the server in dev mode; this enables some
|
/// Whether to start the server in dev mode; this enables some nice
|
||||||
/// nice handlebars features that are not intended for production
|
/// handlebars features that are not intended for production, and enables
|
||||||
|
/// more verbose logs
|
||||||
dev_mode: bool,
|
dev_mode: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -41,10 +44,25 @@ struct SharedData<'a> {
|
||||||
|
|
||||||
#[actix_web::main]
|
#[actix_web::main]
|
||||||
async fn main() -> std::io::Result<()> {
|
async fn main() -> std::io::Result<()> {
|
||||||
|
let config = {
|
||||||
let mut config = Config::parse();
|
let mut config = Config::parse();
|
||||||
config.template_directory = config.template_directory.canonicalize()?;
|
config.template_directory = config.template_directory.canonicalize()?;
|
||||||
|
config
|
||||||
|
};
|
||||||
|
|
||||||
env_logger::init();
|
env_logger::Builder::new()
|
||||||
|
.filter_level(if config.dev_mode {
|
||||||
|
LevelFilter::Info
|
||||||
|
} else {
|
||||||
|
LevelFilter::Debug
|
||||||
|
})
|
||||||
|
.write_style(WriteStyle::Always)
|
||||||
|
.parse_env(
|
||||||
|
Env::new()
|
||||||
|
.filter("TLATERNET_LOG_LEVEL")
|
||||||
|
.write_style("TLATERNET_LOG_STYLE"),
|
||||||
|
)
|
||||||
|
.init();
|
||||||
|
|
||||||
let mut handlebars = Handlebars::new();
|
let mut handlebars = Handlebars::new();
|
||||||
handlebars
|
handlebars
|
||||||
|
|
Loading…
Reference in a new issue