Skip to content

Commit

Permalink
Filter on level
Browse files Browse the repository at this point in the history
  • Loading branch information
flxoacn committed Jul 10, 2024
1 parent 725bb8c commit 71f200c
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 15 deletions.
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -120,16 +120,16 @@ 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"`.
## Installation
Building `rogcat` requires Rust 2018 edition:
```
```sh
cargo install --path .
```
Expand Down Expand Up @@ -157,15 +157,15 @@ 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"]
```

### Terminal settings

Some parameters of the `human` format are adjustable via the config file:

```
```sh
terminal_bright_colors = false
terminal_color = never
terminal_hide_timestamp = true
Expand All @@ -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.*"]
Expand Down Expand Up @@ -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 <[email protected]>
A 'adb logcat' wrapper and log processor. Your config directory is "/Users/felix/Library/Preferences/rogcat".
Expand Down
7 changes: 5 additions & 2 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 <COUNT> 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")
Expand Down Expand Up @@ -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"))
}
15 changes: 11 additions & 4 deletions src/filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ use rogcat::record::{Level, Record};
/// Configured filters
#[derive(Debug)]
pub struct Filter {
level: Level,
level: Option<Level>,
tag: FilterGroup,
tag_ignore_case: FilterGroup,
message: FilterGroup,
Expand All @@ -41,8 +41,13 @@ pub fn from_args_profile(args: &ArgMatches<'_>, profile: &Profile) -> Result<Fil
let message = profile.message.iter().map(String::as_str);
let message_ignorecase = profile.message_ignore_case.iter().map(String::as_str);
let regex = profile.regex.iter().map(String::as_str);
// Level is filtered by ffx in case of fuchsia.
let level = (!args.is_present("fuchsia"))
.then(|| args.value_of("level").map(Level::from))
.flatten();
let filter = Filter {
level: Level::from(args.value_of("level").unwrap_or("")),
level,
// TODO: Do not filter here on tag which is already done by fx in case of fuchsia.
tag: FilterGroup::from_args(args, "tag", tag, false)?,
tag_ignore_case: FilterGroup::from_args(args, "tag-ignore-case", tag_ignorecase, true)?,
message: FilterGroup::from_args(args, "message", message, false)?,
Expand All @@ -60,8 +65,10 @@ pub fn from_args_profile(args: &ArgMatches<'_>, profile: &Profile) -> Result<Fil

impl Filter {
pub fn filter(&self, record: &Record) -> 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)
Expand Down
2 changes: 1 addition & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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") {
Expand Down
23 changes: 23 additions & 0 deletions src/reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand Down Expand Up @@ -188,6 +189,28 @@ pub fn fuchsia(args: &ArgMatches) -> Result<LogStream, Error> {
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)))
Expand Down

0 comments on commit 71f200c

Please sign in to comment.