mirror of
https://codeberg.org/icewind/logsmash.git
synced 2026-06-03 10:04:12 +02:00
allow loading multiple files
This commit is contained in:
parent
3917b52905
commit
e52630a487
2 changed files with 37 additions and 18 deletions
|
|
@ -31,6 +31,7 @@ impl From<&usize> for LogLineNumber {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct LogFile {
|
||||
content: String,
|
||||
}
|
||||
|
|
@ -108,6 +109,20 @@ impl LogFile {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn merge<I: IntoIterator<Item = LogFile>>(files: I) -> LogFile {
|
||||
let mut files = files.into_iter();
|
||||
let mut merged = files.next().unwrap_or_default();
|
||||
|
||||
for file in files {
|
||||
if !merged.content.ends_with('\n') {
|
||||
merged.content.push('\n');
|
||||
}
|
||||
merged.content.push_str(&file.content);
|
||||
}
|
||||
|
||||
merged
|
||||
}
|
||||
|
||||
pub fn iter(&self) -> impl Iterator<Item = &str> + Send + '_ {
|
||||
self.content.lines()
|
||||
}
|
||||
|
|
|
|||
26
src/main.rs
26
src/main.rs
|
|
@ -6,6 +6,7 @@ use crate::matcher::{MatchResult, Matcher};
|
|||
use crate::ui::run_ui;
|
||||
use base64::prelude::*;
|
||||
use clap::Parser;
|
||||
use either::Either;
|
||||
use indicatif::{ParallelProgressIterator, ProgressStyle};
|
||||
use logfile::logline::{Exception, FullException, FullLogLine, LogLine, CUSTOM_TIME_FORMAT};
|
||||
use logsmash_data::{default_apps, get_statements, SourceDefinition};
|
||||
|
|
@ -41,8 +42,8 @@ static GLOBAL: Jemalloc = Jemalloc;
|
|||
#[derive(Debug, Parser)]
|
||||
#[command(version, about, long_about = None)]
|
||||
struct Args {
|
||||
/// File to read from, or "-" for stdin
|
||||
file: String,
|
||||
/// Files to read from, or "-" for stdin
|
||||
files: Vec<String>,
|
||||
/// Collect data and exit, intended for profiling
|
||||
#[arg(long)]
|
||||
profile: bool,
|
||||
|
|
@ -68,20 +69,23 @@ fn main() -> MainResult {
|
|||
.expect("Set only once");
|
||||
}
|
||||
|
||||
let log_file = if args.file == "-" {
|
||||
let mut log_files = Vec::new();
|
||||
for path in args.files {
|
||||
let log_file = if path == "-" {
|
||||
let content = read_to_string(stdin()).map_err(|err| LogError::Read {
|
||||
err: ReadError::Io(err),
|
||||
path: args.file,
|
||||
path,
|
||||
})?;
|
||||
LogFile::from_string(content)
|
||||
} else {
|
||||
let file = File::open(&args.file)?;
|
||||
let file = File::open(&path)?;
|
||||
let file = BufReader::new(file);
|
||||
LogFile::open(&args.file, file).map_err(|err| LogError::Read {
|
||||
err,
|
||||
path: args.file,
|
||||
})?
|
||||
LogFile::open(&path, file).map_err(|err| LogError::Read { err, path })?
|
||||
};
|
||||
log_files.push(log_file);
|
||||
}
|
||||
|
||||
let log_file = LogFile::merge(log_files);
|
||||
|
||||
let lines: Vec<_> = log_file
|
||||
.iter()
|
||||
|
|
@ -127,8 +131,8 @@ fn main() -> MainResult {
|
|||
.collect();
|
||||
|
||||
results.sort_by_key(|res| match res {
|
||||
Ok(line) => line.line_number,
|
||||
Err((line_number, _)) => *line_number,
|
||||
Ok(line) => Either::Left(line.time),
|
||||
Err((line_number, _)) => Either::Right(*line_number),
|
||||
});
|
||||
|
||||
let parsed_log: ParsedLogs = results.into_iter().collect();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue