Crate workflow_log

Source
Expand description

github crates.io docs.rs license

workflow_log is a part of the workflow-rs framework, subset of which is designed to function uniformally across multiple environments including native Rust, WASM-browser and Solana OS targets.

When you application is built in the native application environment macros such as log_info!() will invoke println!(), in WASM they will invoke console.log() and under Solana they will invoke sol_log() (used by msg!() macro)

workflow-log macros operate the same way as regular functions such as println!()

The following core macros are available:

  • log_trace!()
  • log_debug!()
  • log_info!()
  • log_warn()
  • log_error!()

§Redirecting log output

This crate allows you to configure a log sink that will receive all log messages from your application. This is useful to route log messages to an external receiver or, for example, store logs to a file.

Log sink can be installed using workflow_log::pipe function and supplying it with an Arc of the workflow_log::Sink trait. The trait function workflow_log::Sink::write should return true to indicate the the text should be outputed to the console, or false to prevent further output (i.e. to consume the log text)

§Example:

use workflow_log::*;
use std::sync::Arc;

pub struct MyStruct;
impl Sink for MyStruct {
    fn write(&self, target: Option<&str>, level:Level, args : &std::fmt::Arguments<'_>) -> bool {
         
        println!("target: {target:?}");
        println!("level: {level:?}");
        println!("args: {args:?}");

        // return true to continue output
        // return false to prevent further output
        true
    }
}

let my_struct = Arc::new(MyStruct{});
workflow_log::pipe(Some(my_struct));
log_trace!("test msg");

To can disable the sink by supplying Option::None to workflow_log::pipe.

Re-exports§

pub use hexplay;

Modules§

color_log
impls
levels
prelude

Macros§

log_debug
Format and log message with Level::Debug
log_error
Format and log message with Level::Error
log_info
Format and log message with Level::Info
log_trace
Format and log message with Level::Trace
log_warn
Format and log message with Level::Warn

Structs§

Buffer
Write colored text to memory.
ColorHexView
HexViewBuilder
A builder for the HexView struct.

Enums§

Level
An enum representing the available verbosity levels of the logger.
LevelFilter
An enum representing the available verbosity level filters of the logger.

Traits§

ColoLogTrace
Sink
A log sink trait that can be installed into the log subsystem using the pipe function and will receive all log messages.

Functions§

format_hex
Returns a string formatted as a hex data dump of the supplied slice argument.
format_hex_with_colors
Formats a hex data dump to contain color ranges
log_level_enabled
Returns true if the current log level is below the currently set LevelFilter
pipe
Receives an Option with an Arced Sink trait reference and installs it as a log sink / receiver. The sink can be later disabled by invoking pipe(None)
set_colors_enabled
set_log_level
Enable filtering of log messages using the LevelFilter
style
Wraps an object for formatting for styling.
trace_hex
Prints (using log_trace) a data slice formatted as a hex data dump.