Skip to content

Commit

Permalink
Merge pull request #20 from tinythings/isbm-concise-option-stdhandler
Browse files Browse the repository at this point in the history
Add "concise" option to the stdhandler
  • Loading branch information
isbm authored Oct 22, 2024
2 parents 983078b + 739949d commit faf8872
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 10 deletions.
12 changes: 11 additions & 1 deletion docs/evthandlers/console_logger.rst
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,22 @@ Options
``prefix``
^^^^^^^^^^

Prefix to the logging message text. Example:
**Optional.** Prefix to the logging message text. Example:

.. code-block:: yaml
:caption: Prefix example
prefix: "Hello"
``concise``
^^^^^^^^^^^

**Optional.** Set logger not to include output data from a certain module.

.. code-block:: yaml
:caption: Mute additional data display
concise: true
Example
-------
Expand All @@ -44,3 +53,4 @@ Example
console-logger:
prefix: "Default event"
concise: false # Also default
1 change: 0 additions & 1 deletion docs/evthandlers/outcome_logger.rst
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ Options
prefix: "Hello"
Example
-------

Expand Down
3 changes: 3 additions & 0 deletions examples/models/router/events/events-config.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ events:
$/$/$/0:
handler:
- console-logger
console-logger:
concise: true
prefix: General flow

$/$/$/$:
handler:
Expand Down
23 changes: 15 additions & 8 deletions libsysinspect/src/reactor/handlers/stdhdl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,22 +30,29 @@ impl EventHandler for StdoutEventHandler {
}

let mut prefix = "".to_string();
let mut verbose = true;
if let Some(config) = self.config() {
if let Some(p) = config.as_string("prefix") {
prefix = format!("{} - ", p.cyan());
}

if let Some(p) = config.as_bool("concise") {
verbose = !p;
}
}

if evt.response.retcode() == 0 {
log::info!("{}{}/{} - {}", prefix, evt.eid().bright_cyan(), evt.aid().bright_cyan(), evt.response.message());
if let Some(data) = evt.response.data() {
log::info!(
"{}{}/{} - Other data:\n{}",
prefix,
evt.eid().bright_cyan(),
evt.aid().bright_cyan(),
KeyValueFormatter::new(data).format()
);
if verbose {
if let Some(data) = evt.response.data() {
log::info!(
"{}{}/{} - Other data:\n{}",
prefix,
evt.eid().bright_cyan(),
evt.aid().bright_cyan(),
KeyValueFormatter::new(data).format()
);
}
}
} else {
log::error!(
Expand Down

0 comments on commit faf8872

Please sign in to comment.