Logging, default to log level info
This commit is contained in:
parent
1c3c59f9f0
commit
1d14f5deb1
13
src/main.rs
13
src/main.rs
|
@ -7,6 +7,8 @@ use axum::{
|
||||||
routing::get,
|
routing::get,
|
||||||
Router,
|
Router,
|
||||||
};
|
};
|
||||||
|
use env_logger::Env;
|
||||||
|
use log::{debug, error, info};
|
||||||
use prometheus::{
|
use prometheus::{
|
||||||
register_gauge_vec, register_int_counter_vec, Encoder, GaugeVec, IntCounterVec, TextEncoder,
|
register_gauge_vec, register_int_counter_vec, Encoder, GaugeVec, IntCounterVec, TextEncoder,
|
||||||
};
|
};
|
||||||
|
@ -160,6 +162,9 @@ fn register_metrics() {
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
async fn main() -> Result<(), ()> {
|
async fn main() -> Result<(), ()> {
|
||||||
|
let env = Env::default().filter_or("LOG_LEVEL", "info");
|
||||||
|
|
||||||
|
env_logger::init_from_env(env);
|
||||||
let content = fs::read_to_string("config.toml").unwrap();
|
let content = fs::read_to_string("config.toml").unwrap();
|
||||||
let mut config: Config = toml::from_str(&content).unwrap();
|
let mut config: Config = toml::from_str(&content).unwrap();
|
||||||
config.vrchat_token = Some(env::var("VRCHAT_AUTH_TOKEN").unwrap());
|
config.vrchat_token = Some(env::var("VRCHAT_AUTH_TOKEN").unwrap());
|
||||||
|
@ -170,7 +175,7 @@ async fn main() -> Result<(), ()> {
|
||||||
.route("/metrics", get(metrics_handler))
|
.route("/metrics", get(metrics_handler))
|
||||||
.with_state(config);
|
.with_state(config);
|
||||||
|
|
||||||
println!("running at 0.0.0.0:6534");
|
info!("running at 0.0.0.0:6534");
|
||||||
let _ = axum::Server::bind(&"0.0.0.0:6534".parse().unwrap())
|
let _ = axum::Server::bind(&"0.0.0.0:6534".parse().unwrap())
|
||||||
.serve(app.into_make_service())
|
.serve(app.into_make_service())
|
||||||
.await;
|
.await;
|
||||||
|
@ -185,7 +190,7 @@ async fn metrics_handler(State(config): State<Config>) -> Result<impl IntoRespon
|
||||||
.body(Full::from(b))
|
.body(Full::from(b))
|
||||||
.unwrap()),
|
.unwrap()),
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
println!("{}", e);
|
error!("{}", e);
|
||||||
Err(StatusCode::INTERNAL_SERVER_ERROR)
|
Err(StatusCode::INTERNAL_SERVER_ERROR)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -205,13 +210,13 @@ async fn metrics(config: Config) -> Result<Vec<u8>, WsError> {
|
||||||
|
|
||||||
if config.groups.is_some() {
|
if config.groups.is_some() {
|
||||||
for (name, group) in config.groups.unwrap() {
|
for (name, group) in config.groups.unwrap() {
|
||||||
println!("scanning group {}", &name);
|
debug!("scanning group {}", &name);
|
||||||
group_metrics(&client, &auth_cookie, name, group).await?;
|
group_metrics(&client, &auth_cookie, name, group).await?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if config.worlds.is_some() {
|
if config.worlds.is_some() {
|
||||||
for (name, id) in config.worlds.unwrap() {
|
for (name, id) in config.worlds.unwrap() {
|
||||||
println!("scanning world {}", &name);
|
debug!("scanning world {}", &name);
|
||||||
world_metrics(&client, &auth_cookie, name, id).await?;
|
world_metrics(&client, &auth_cookie, name, id).await?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue