Crate workflow_log
source ·Expand description
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§
Macros§
- Format and log message withLevel::Debug
- Format and log message withLevel::Error
- Format and log message withLevel::Info
- Format and log message withLevel::Trace
- Format and log message withLevel::Warn
Structs§
- Write colored text to memory.
- A builder for the HexView struct.
Enums§
- An enum representing the available verbosity levels of the logger.
- An enum representing the available verbosity level filters of the logger.
Traits§
- A log sink trait that can be installed into the log subsystem using thepipefunction and will receive all log messages.
Functions§
- Returns a string formatted as a hex data dump of the supplied slice argument.
- Formats a hex data dump to contain color ranges
- Returns true if the current log level is below the currently setLevelFilter
- Receives an Option with anArcedSinktrait reference and installs it as a log sink / receiver. The sink can be later disabled by invokingpipe(None)
- Enable filtering of log messages using theLevelFilter
- Wraps an object for formatting for styling.
- Prints (usinglog_trace) a data slice formatted as a hex data dump.