From 71f200cf07dafa5efd410fa29d05f5e0f772880c Mon Sep 17 00:00:00 2001 From: Felix Obenhuber Date: Wed, 10 Jul 2024 09:03:47 +0200 Subject: [PATCH] Filter on level --- README.md | 16 ++++++++-------- src/cli.rs | 7 +++++-- src/filter.rs | 15 +++++++++++---- src/main.rs | 2 +- src/reader.rs | 23 +++++++++++++++++++++++ 5 files changed, 48 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index c3cb0d3..6d33d3d 100644 --- a/README.md +++ b/README.md @@ -99,7 +99,7 @@ Write message "some text" into the device log buffer (e.g annotations during man Set level and tag or read from `stdin`: -``` +```sh rogcat-log Add log message(s) log buffer @@ -120,8 +120,8 @@ ARGS: ## Fuchsia -`rogcat` can be used to read logs from a `Fuchsia` device. Use the `--ffx` switch to run `ffx` instead of `adb logcat`. -The default `ffx` command is `ffx log --no-color`. +`rogcat` can be used to read logs from a `Fuchsia` device. Use the `--fx` switch to run `ffx` instead of `adb logcat`. +The default `ffx` command is `ffx log --no-color --severity debug`. Of course `ffx` can be invoked manually with eg. `ffx log --no-color | rogcat -` or `rogcat "ffx log --no-color"`. @@ -129,7 +129,7 @@ Of course `ffx` can be invoked manually with eg. `ffx log --no-color | rogcat -` Building `rogcat` requires Rust 2018 edition: -``` +```sh cargo install --path . ``` @@ -157,7 +157,7 @@ on device power cycles or disconnect/reconnects. A `Windows 7` bug prevents `rog The default behavior of `rogcat` is to dump `all` logcat buffers. This can be overwritten by selecting specific buffers in the `rogcat` configuration file. e.g: -``` +```toml buffer = ["main", "events"] ``` @@ -165,7 +165,7 @@ buffer = ["main", "events"] Some parameters of the `human` format are adjustable via the config file: -``` +```sh terminal_bright_colors = false terminal_color = never terminal_hide_timestamp = true @@ -190,7 +190,7 @@ The environment variable overrules the default path. See `rogcat profiles --help Example: -``` +```toml [profile.a] comment = "Messages starting with A or a" message_ignore_case = ["^A.*"] @@ -230,7 +230,7 @@ You can create a special profile named `default` which will be used when no othe ## Usage -``` +```sh rogcat 0.4.3-alpha.0 Felix Obenhuber A 'adb logcat' wrapper and log processor. Your config directory is "/Users/felix/Library/Preferences/rogcat". diff --git a/src/cli.rs b/src/cli.rs index a522f79..b898ea8 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -186,6 +186,11 @@ pub fn cli() -> App<'static, 'static> { .takes_value(true) .conflicts_with_all(&["input", "COMMAND", "restart"]) .help("Dump only the most recent lines (implies --dump)")) + .arg(Arg::with_name("fuchsia") + .long("ffx") + .takes_value(false) + .conflicts_with_all(&["dev", "input", "COMMAND", "restart", "tail"]) + .help("Use ffx log instead of adb logcat")) .arg(Arg::with_name("COMMAND") .help( "Optional command to run and capture stdout and stdderr from. Pass \"-\" to d capture stdin'. If omitted, rogcat will run \"adb logcat -b all\" and restarts this commmand if 'adb' terminates",)) .subcommand(SubCommand::with_name("bugreport") @@ -223,6 +228,4 @@ pub fn cli() -> App<'static, 'static> { .possible_values(&[ "trace", "debug", "info", "warn", "error", "fatal", "assert", "T", "D", "I", "W", "E", "F", "A" ],) .help("Log on level")) .arg_from_usage("[MESSAGE] 'Log message. Pass \"-\" to read from stdin'.")) - .subcommand(SubCommand::with_name("fx") - .about("Start fx log (fuchsia")) } diff --git a/src/filter.rs b/src/filter.rs index a99660a..b3e8fb7 100644 --- a/src/filter.rs +++ b/src/filter.rs @@ -27,7 +27,7 @@ use rogcat::record::{Level, Record}; /// Configured filters #[derive(Debug)] pub struct Filter { - level: Level, + level: Option, tag: FilterGroup, tag_ignore_case: FilterGroup, message: FilterGroup, @@ -41,8 +41,13 @@ pub fn from_args_profile(args: &ArgMatches<'_>, profile: &Profile) -> Result, profile: &Profile) -> Result bool { - if record.level < self.level { - return false; + if let Some(ref level) = self.level { + if record.level < *level { + return false; + } } self.message.filter(&record.message) diff --git a/src/main.rs b/src/main.rs index a98acc7..984510a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -55,7 +55,7 @@ fn run() -> Result<(), Error> { let source = { if args.is_present("input") { reader::files(&args)? - } else if args.subcommand().0 == "fx" { + } else if args.is_present("fuchsia") { reader::fuchsia(&args)? } else { match args.value_of("COMMAND") { diff --git a/src/reader.rs b/src/reader.rs index e02fe77..19a318d 100644 --- a/src/reader.rs +++ b/src/reader.rs @@ -26,6 +26,7 @@ use crate::{ use clap::{value_t, ArgMatches}; use failure::{err_msg, format_err, Error}; use futures::{stream::iter_ok, Async, Future, Stream}; +use rogcat::record::Level; #[cfg(target_os = "linux")] use rogcat::record::{Record, Timestamp}; use std::{ @@ -188,6 +189,28 @@ pub fn fuchsia(args: &ArgMatches) -> Result { cmd.push("--dump"); } + if let Some(tags) = args.values_of("tag") { + tags.for_each(|tag| { + cmd.push("--tag"); + cmd.push(tag); + }); + } + + if let Some(level) = args.value_of("level") { + cmd.push("--severity"); + let level = Level::from(level); + match level { + Level::Verbose | Level::Trace => cmd.push("trace"), + Level::None | Level::Debug => cmd.push("debug"), + Level::Info => cmd.push("info"), + Level::Warn => cmd.push("warn"), + Level::Error => cmd.push("error"), + Level::Fatal | Level::Assert => cmd.push("fatal"), + }; + } else { + cmd.extend(["--severity", "debug"]); + } + let cmd = cmd.iter().map(ToString::to_string).collect(); Ok(Box::new(Process::with_cmd(cmd, false)))