Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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