Skip to content

Commit

Permalink
Improve logging (#117)
Browse files Browse the repository at this point in the history
* add log formats and ansi handling

* update readme

* fix help indentation

* add `no-color` option

* rename default formatter

* add verbose option

* make fields depend on debug mode

* update help message

* improve control of color output

* improve log messages
  • Loading branch information
morphy2k authored Jun 19, 2023
1 parent cb6965e commit b91d0be
Show file tree
Hide file tree
Showing 9 changed files with 378 additions and 62 deletions.
74 changes: 65 additions & 9 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 10 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,16 @@ rss = { version = "2", default-features = false }
atom_syndication = { version = "0.12", default-features = false }
chrono = { version = "0.4", features = ["serde"], default-features = false }
tracing = "0.1"
tracing-subscriber = "0.3"
tracing-subscriber = { version = "0.3", features = [
"std",
"fmt",
"tracing-log",
"smallvec",
"parking_lot",
"env-filter",
"ansi",
"json",
], default-features = false }
thiserror = "1"
humantime-serde = "1"
toml = "0.7"
Expand Down
9 changes: 6 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,12 @@ See [GitHub container package](https://github.com/morphy2k/rss-forwarder/pkgs/co
USAGE: rss-forwarder [OPTIONS] <CONFIG_FILE>
OPTIONS:
--debug Enables debug mode
-h, --help Show help information
-v, --version Show version info
-f, --format <FORMAT> Log format: full, pretty, compact, json (default: full)
--color <WHEN> Colorize output: auto, always, never (default: auto)
--debug Enables debug mode
--verbose Enables verbose mode
-h, --help Show this help message
-v, --version Show version information
```

[Examples](example)
Expand Down
26 changes: 25 additions & 1 deletion src/feed/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ use self::item::{FeedItem, Item, Source};

use std::{cmp::Reverse, io::BufRead};

use tracing::debug;

#[derive(Debug)]
pub enum Feed {
Rss(rss::Channel),
Expand All @@ -24,10 +26,16 @@ impl<'a> Feed {
let feed = atom_syndication::Feed::read_from(reader)?;
Self::Atom(feed)
}
_ => return Err(e.into()),
_ => return Err(e)?,
},
};

debug!(
format = %if feed.is_rss() { "RSS" } else { "Atom" },
items = feed.items().len(),
"parsed feed"
);

Ok(feed)
}

Expand Down Expand Up @@ -72,4 +80,20 @@ impl<'a> Feed {

items
}

/// Returns `true` if the feed is [`Rss`].
///
/// [`Rss`]: Feed::Rss
#[must_use]
pub fn is_rss(&self) -> bool {
matches!(self, Self::Rss(..))
}

/// Returns `true` if the feed is [`Atom`].
///
/// [`Atom`]: Feed::Atom
#[must_use]
pub fn is_atom(&self) -> bool {
matches!(self, Self::Atom(..))
}
}
Loading

0 comments on commit b91d0be

Please sign in to comment.