Always print the entire log for failures in eval and build

This makes it easier to debug configuration issues without -v.

Fixes #14.
This commit is contained in:
Zhaofeng Li 2021-02-17 22:48:26 -08:00
parent d16a13654c
commit e32e130621

View file

@ -156,31 +156,34 @@ impl DeploymentResult {
match &self.stage { match &self.stage {
Evaluate(nodes) => { Evaluate(nodes) => {
self.print_failed_nodes("Evaluation of", &nodes); self.print_failed_nodes("Evaluation of", &nodes, true);
} }
Build(nodes) => { Build(nodes) => {
self.print_failed_nodes("Build of", &nodes); self.print_failed_nodes("Build of", &nodes, true);
} }
Apply(node) => { Apply(node) => {
self.print_failed_nodes("Deployment to", &vec![node.clone()]); self.print_failed_nodes("Deployment to", &vec![node.clone()], false);
} }
} }
} }
fn print_failed_nodes(&self, prefix: &'static str, nodes: &Vec<String>) { fn print_failed_nodes(&self, prefix: &'static str, nodes: &Vec<String>, full_logs: bool) {
let last_lines: Option<Vec<String>> = self.logs.as_ref().map(|logs| {
logs.split("\n").collect::<Vec<&str>>().iter().rev().take(10).rev()
.map(|line| line.to_string()).collect()
});
let msg = if nodes.len() == 1 { let msg = if nodes.len() == 1 {
format!("{} {} failed.", prefix, nodes[0]) format!("{} {} failed.", prefix, nodes[0])
} else { } else {
format!("{} {} nodes failed.", prefix, nodes.len()) format!("{} {} nodes failed.", prefix, nodes.len())
}; };
if let Some(lines) = last_lines { if let Some(logs) = self.logs.as_ref() {
log::error!("{} Last {} lines of logs:", msg, lines.len()); let mut lines = logs.split("\n").collect::<Vec<&str>>();
if full_logs {
log::error!("{} Logs:", msg);
} else {
lines = lines.drain(..).rev().take(10).rev().collect();
log::error!("{} Last {} lines of logs:", msg, lines.len());
}
for line in lines { for line in lines {
log::error!("{}", line); log::error!("{}", line);
} }