nzrd: finally use tracing
This commit is contained in:
parent
f63626489d
commit
6fe1ed02aa
57
Cargo.lock
generated
57
Cargo.lock
generated
|
@ -1046,17 +1046,6 @@ dependencies = [
|
|||
"windows-sys 0.52.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "hostname"
|
||||
version = "0.4.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f9c7c7c8ac16c798734b8a24560c1362120597c40d5e1459f09498f8f6c8f2ba"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"libc",
|
||||
"windows",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "http"
|
||||
version = "1.1.0"
|
||||
|
@ -1532,15 +1521,6 @@ dependencies = [
|
|||
"autocfg",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "num_threads"
|
||||
version = "0.1.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2819ce041d2ee131036f4fc9d6ae7ae125a3a40e97ba64d04fe799ad9dabbb44"
|
||||
dependencies = [
|
||||
"libc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "nzr"
|
||||
version = "0.9.0"
|
||||
|
@ -1607,7 +1587,6 @@ dependencies = [
|
|||
"home",
|
||||
"libc",
|
||||
"libsqlite3-sys",
|
||||
"log",
|
||||
"nix",
|
||||
"nzr-api",
|
||||
"nzr-virt",
|
||||
|
@ -1619,12 +1598,13 @@ dependencies = [
|
|||
"serde_with",
|
||||
"serde_yaml",
|
||||
"stdext",
|
||||
"syslog",
|
||||
"tarpc",
|
||||
"tempfile",
|
||||
"thiserror",
|
||||
"tokio",
|
||||
"tokio-serde 0.9.0",
|
||||
"tracing",
|
||||
"tracing-subscriber",
|
||||
"trait-variant",
|
||||
"uuid",
|
||||
"zerocopy",
|
||||
|
@ -2309,18 +2289,6 @@ version = "1.0.1"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a7065abeca94b6a8a577f9bd45aa0867a2238b74e8eb67cf10d492bc39351394"
|
||||
|
||||
[[package]]
|
||||
name = "syslog"
|
||||
version = "7.0.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "019f1500a13379b7d051455df397c75770de6311a7a188a699499502704d9f10"
|
||||
dependencies = [
|
||||
"hostname",
|
||||
"libc",
|
||||
"log",
|
||||
"time",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tabled"
|
||||
version = "0.15.0"
|
||||
|
@ -2444,9 +2412,7 @@ checksum = "5dfd88e563464686c916c7e46e623e520ddc6d79fa6641390f2e3fa86e83e885"
|
|||
dependencies = [
|
||||
"deranged",
|
||||
"itoa",
|
||||
"libc",
|
||||
"num-conv",
|
||||
"num_threads",
|
||||
"powerfmt",
|
||||
"serde",
|
||||
"time-core",
|
||||
|
@ -2960,25 +2926,6 @@ version = "0.4.0"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
|
||||
|
||||
[[package]]
|
||||
name = "windows"
|
||||
version = "0.52.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e48a53791691ab099e5e2ad123536d0fff50652600abaf43bbf952894110d0be"
|
||||
dependencies = [
|
||||
"windows-core",
|
||||
"windows-targets",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "windows-core"
|
||||
version = "0.52.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "33ab640c8d7e35bf8ba19b884ba838ceb4fba93a4e8c65a9059d08afcfc683d9"
|
||||
dependencies = [
|
||||
"windows-targets",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "windows-sys"
|
||||
version = "0.42.0"
|
||||
|
|
|
@ -26,9 +26,8 @@ tarpc = { version = "0.34", features = [
|
|||
] }
|
||||
|
||||
# Logging
|
||||
# TODO: switch to tracing?
|
||||
log = "0.4.17"
|
||||
syslog = "7"
|
||||
tracing = "0.1"
|
||||
tracing-subscriber = "0.3"
|
||||
|
||||
# Database
|
||||
diesel = { version = "2.2", features = [
|
||||
|
|
|
@ -9,10 +9,10 @@ use super::*;
|
|||
use crate::ctrl::vm::Progress;
|
||||
use crate::ctx::Context;
|
||||
use crate::model::{Instance, Subnet};
|
||||
use log::{debug, info, warn};
|
||||
use nzr_api::net::mac::MacAddr;
|
||||
use nzr_api::{args, model, nzr_event};
|
||||
use std::sync::Arc;
|
||||
use tracing::{debug, info, warn};
|
||||
|
||||
const VIRT_MAC_OUI: &[u8] = &[0x02, 0xf1, 0x0f];
|
||||
|
||||
|
|
|
@ -3,7 +3,6 @@ use diesel::{
|
|||
SqliteConnection,
|
||||
};
|
||||
use diesel_migrations::{embed_migrations, EmbeddedMigrations, MigrationHarness};
|
||||
use log::trace;
|
||||
use nzr_virt::{vol, Connection};
|
||||
use std::ops::Deref;
|
||||
use thiserror::Error;
|
||||
|
@ -67,7 +66,7 @@ impl InnerCtx {
|
|||
baseimg: conn.get_pool(&config.storage.base_image_pool).await?,
|
||||
};
|
||||
|
||||
trace!("Connecting to database");
|
||||
tracing::trace!("Connecting to database");
|
||||
let db_uri = config.db_uri.clone();
|
||||
let sqldb = tokio::task::spawn_blocking(|| {
|
||||
let manager = ConnectionManager::<SqliteConnection>::new(db_uri);
|
||||
|
@ -78,7 +77,7 @@ impl InnerCtx {
|
|||
.unwrap()?;
|
||||
|
||||
{
|
||||
trace!("Running pending migrations");
|
||||
tracing::trace!("Running pending migrations");
|
||||
let mut conn = sqldb.get()?;
|
||||
tokio::task::spawn_blocking(move || {
|
||||
conn.run_pending_migrations(MIGRATIONS)
|
||||
|
|
|
@ -4,23 +4,29 @@ mod ctx;
|
|||
mod model;
|
||||
mod rpc;
|
||||
|
||||
use log::LevelFilter;
|
||||
use log::*;
|
||||
use nzr_api::config;
|
||||
use std::str::FromStr;
|
||||
|
||||
use nzr_api::config;
|
||||
|
||||
#[tokio::main(flavor = "multi_thread")]
|
||||
async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
let cfg: config::Config = config::Config::figment().extract()?;
|
||||
let ctx = ctx::Context::new(cfg).await?;
|
||||
|
||||
syslog::init_unix(
|
||||
syslog::Facility::LOG_DAEMON,
|
||||
LevelFilter::from_str(ctx.config.log_level.as_str())?,
|
||||
)?;
|
||||
let mut bad_loglevel = false;
|
||||
let log_level = tracing::Level::from_str(&ctx.config.log_level).unwrap_or_else(|_| {
|
||||
bad_loglevel = true;
|
||||
tracing::Level::WARN
|
||||
});
|
||||
|
||||
tracing_subscriber::fmt().with_max_level(log_level).init();
|
||||
|
||||
if bad_loglevel {
|
||||
tracing::warn!("Couldn't parse log level from config, defaulting to {log_level}");
|
||||
}
|
||||
|
||||
if let Err(err) = rpc::serve(ctx.clone()).await {
|
||||
error!("Error from RPC: {}", err);
|
||||
tracing::error!("Error from RPC: {}", err);
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
|
|
@ -404,7 +404,7 @@ impl Subnet {
|
|||
// the API.
|
||||
Ok(addr) => Some(addr),
|
||||
Err(err) => {
|
||||
log::error!(
|
||||
tracing::error!(
|
||||
"Error parsing DNS server '{}' for {}: {}",
|
||||
s,
|
||||
&self.name,
|
||||
|
@ -416,7 +416,7 @@ impl Subnet {
|
|||
.collect(),
|
||||
domain_name: self.domain_name.as_ref().map(|s| {
|
||||
Name::from_str(s).unwrap_or_else(|e| {
|
||||
log::error!("Error parsing DNS name for {}: {}", &self.name, e);
|
||||
tracing::error!("Error parsing DNS name for {}: {}", &self.name, e);
|
||||
Name::default()
|
||||
})
|
||||
}),
|
||||
|
|
|
@ -48,7 +48,7 @@ impl<'a, T: Transactable> Drop for Transaction<'a, T> {
|
|||
let ctx = self.ctx.clone();
|
||||
tokio::spawn(async move {
|
||||
if let Err(err) = inner.undo_tx(&ctx).await {
|
||||
log::error!("Error undoing transaction: {err}");
|
||||
tracing::error!("Error undoing transaction: {err}");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
@ -13,8 +13,8 @@ use uuid::Uuid;
|
|||
use crate::cmd;
|
||||
use crate::ctx::Context;
|
||||
use crate::model::{Instance, SshPubkey, Subnet};
|
||||
use log::*;
|
||||
use std::collections::HashMap;
|
||||
use tracing::*;
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct NzrServer {
|
||||
|
|
Loading…
Reference in a new issue