Improve log output.

This commit is contained in:
R-VdP 2023-03-15 14:05:52 +01:00
parent 306e055922
commit ed99b39f6c
No known key found for this signature in database
2 changed files with 31 additions and 3 deletions

View file

@ -17,6 +17,8 @@ use crate::{
}; };
use etc_tree::EtcTree; use etc_tree::EtcTree;
use self::etc_tree::EtcFileStatus;
#[derive(Debug, Clone, Serialize, Deserialize)] #[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")] #[serde(rename_all = "camelCase")]
struct EtcFile { struct EtcFile {
@ -38,6 +40,21 @@ struct EtcFilesConfig {
static_env: StorePath, static_env: StorePath,
} }
impl std::fmt::Display for EtcFilesConfig {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
writeln!(f, "Files in config:")?;
self.entries.values().try_for_each(|entry| {
writeln!(
f,
"target: {}, source:{}, mode:{}",
entry.target.display(),
entry.source,
entry.mode
)
})
}
}
#[derive(Debug, Clone, Serialize, Deserialize)] #[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")] #[serde(rename_all = "camelCase")]
struct CreatedEtcFile { struct CreatedEtcFile {
@ -49,10 +66,10 @@ pub fn activate(store_path: &StorePath, ephemeral: bool) -> Result<()> {
let file = fs::File::open(Path::new(&store_path.store_path).join("etcFiles/etcFiles.json"))?; let file = fs::File::open(Path::new(&store_path.store_path).join("etcFiles/etcFiles.json"))?;
let reader = io::BufReader::new(file); let reader = io::BufReader::new(file);
let config: EtcFilesConfig = serde_json::from_reader(reader)?; let config: EtcFilesConfig = serde_json::from_reader(reader)?;
log::debug!("{:?}", config); log::debug!("{config}");
let etc_dir = etc_dir(ephemeral); let etc_dir = etc_dir(ephemeral);
log::debug!("Storing /etc entries in {}", etc_dir.display()); log::info!("Creating /etc entries in {}", etc_dir.display());
DirBuilder::new().recursive(true).create(&etc_dir)?; DirBuilder::new().recursive(true).create(&etc_dir)?;

View file

@ -19,6 +19,17 @@ struct ServiceConfig {
type Services = HashMap<String, ServiceConfig>; type Services = HashMap<String, ServiceConfig>;
fn print_services(services: &Services) -> Result<String> {
use std::fmt::Write as _;
let mut out = String::new();
writeln!(out, "Services in config:")?;
services
.iter()
.try_for_each(|(name, entry)| writeln!(out, "name: {name}, source:{}", entry.store_path))?;
Ok(out)
}
#[derive(Debug, Clone, Serialize, Deserialize)] #[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")] #[serde(rename_all = "camelCase")]
struct LinkedServiceConfig { struct LinkedServiceConfig {
@ -45,7 +56,6 @@ type LinkedServices = HashMap<String, LinkedServiceConfig>;
pub fn activate(store_path: &StorePath, ephemeral: bool) -> Result<()> { pub fn activate(store_path: &StorePath, ephemeral: bool) -> Result<()> {
let old_linked_services = read_linked_services()?; let old_linked_services = read_linked_services()?;
log::debug!("{:?}", old_linked_services);
log::info!("Reading service definitions..."); log::info!("Reading service definitions...");
let file = fs::File::open( let file = fs::File::open(
@ -55,6 +65,7 @@ pub fn activate(store_path: &StorePath, ephemeral: bool) -> Result<()> {
)?; )?;
let reader = io::BufReader::new(file); let reader = io::BufReader::new(file);
let services: Services = serde_json::from_reader(reader)?; let services: Services = serde_json::from_reader(reader)?;
log::debug!("{}", print_services(&services)?);
let linked_services = link_services(services, ephemeral)?; let linked_services = link_services(services, ephemeral)?;
serialise_linked_services(&linked_services)?; serialise_linked_services(&linked_services)?;