Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewjstone committed Jan 12, 2024
1 parent a8039a1 commit 60a7abe
Show file tree
Hide file tree
Showing 2 changed files with 168 additions and 135 deletions.
73 changes: 48 additions & 25 deletions dev-tools/oxlog/src/bin/oxlog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
//! Tool for discovering oxide related logfiles on sleds
use clap::{Parser, Subcommand};
use oxlog::{LogFile, Logs};
use oxlog::{LogFile, Zones};

#[derive(Debug, Parser)]
#[command(version)]
Expand All @@ -16,41 +16,54 @@ struct Cli {

#[derive(Debug, Subcommand)]
enum Commands {
/// List all oxide services found on the filesystem
Services {
/// Don't print any table headers or metadata
#[arg(short, long)]
scripted: bool,
},
/// List all zones found on the filesystem
Zones,

/// List logs for a given service
Logs {
// The name of the zone
zone: String,

/// The name of the service to list logs for
service: String,
service: Option<String>,

/// Print available metadata
#[arg(short, long)]
metadata: bool,

/// Print only the current log file
#[arg(short, long)]
current: bool,

/// Print only the archive log files
#[arg(short, long)]
archived: bool,

// Print only the extra log files
#[arg(short, long)]
extra: bool,
},
}

fn main() -> Result<(), anyhow::Error> {
let cli = Cli::parse();

match cli.command {
Commands::Services { scripted } => {
if !scripted {
println!("{:<20} Zone", "Svc");
println!("{:<20} -----", "-----");
}
for (name, svc_logs) in Logs::load()?.svcs.into_iter() {
for (zone, _) in svc_logs {
println!("{:<20} {}", name, zone);
}
Commands::Zones => {
for zone in Zones::load()?.zones.keys() {
println!("{zone}");
}
Ok(())
}
Commands::Logs { service, metadata } => {
let mut logs = Logs::load()?;
Commands::Logs {
zone,
service,
metadata,
current,
archived,
extra,
} => {
let zones = Zones::load()?;
let print_metadata = |f: &LogFile| {
println!(
"{}\t{}\t{}",
Expand All @@ -60,23 +73,34 @@ fn main() -> Result<(), anyhow::Error> {
.map_or_else(|| "-".to_string(), |s| s.to_rfc3339())
);
};
logs.svcs.get_mut(&service).map(|svc_logs_by_zone| {
for (_zone, svc_logs) in svc_logs_by_zone {
svc_logs.archived.sort();

let logs = zones.zone_logs(&zone);
for (svc_name, mut svc_logs) in logs {
if let Some(service) = &service {
if svc_name != service.as_str() {
continue;
}
}
svc_logs.archived.sort();
if current {
if let Some(current) = &svc_logs.current {
if metadata {
print_metadata(current);
} else {
println!("{}", current.path);
}
}
}
if archived {
for f in &svc_logs.archived {
if metadata {
print_metadata(f);
} else {
println!("{}", f.path);
}
}
}
if extra {
for f in &svc_logs.extra {
if metadata {
print_metadata(f);
Expand All @@ -85,9 +109,8 @@ fn main() -> Result<(), anyhow::Error> {
}
}
}
});
}
Ok(())
}
}

Ok(())
}
Loading

0 comments on commit 60a7abe

Please sign in to comment.