Skip to content

Commit

Permalink
add oxlog services to print filterable service names
Browse files Browse the repository at this point in the history
  • Loading branch information
faithanalog committed May 28, 2024
1 parent 8822168 commit b939006
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions dev-tools/oxlog/src/bin/oxlog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use clap::{ArgAction, Args, Parser, Subcommand};
use oxlog::{Filter, LogFile, Zones};
use std::collections::BTreeSet;

#[derive(Debug, Parser)]
#[command(version)]
Expand Down Expand Up @@ -34,6 +35,11 @@ enum Commands {
#[command(flatten)]
filter: FilterArgs,
},

/// List the names of all services on the system, from the perspective of
/// oxlog. Use these names with `oxlog logs` to filter output to logs from a
/// specific service.
Services,
}

#[derive(Args, Debug)]
Expand Down Expand Up @@ -124,5 +130,31 @@ fn main() -> Result<(), anyhow::Error> {
}
Ok(())
}
Commands::Services => {
let zones = Zones::load()?;

// We want all logs that exist, anywhere, so we can find their
// service names.
let filter = Filter {
current: true,
archived: true,
extra: true,
show_empty: true,
};

// Collect a unique set of services, based on the logs in all zones
let services: BTreeSet<String> = zones
.zones
.keys()
.flat_map(|zone| zones.zone_logs(&zone, filter).into_iter())
.map(|(name, _)| name)
.collect();

for svc in services {
println!("{}", svc);
}

Ok(())
}
}
}

0 comments on commit b939006

Please sign in to comment.