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§
- 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.
- Color
HexView - HexView
Builder - A builder for the HexView struct.
Enums§
- Level
- An enum representing the available verbosity levels of the logger.
- Level
Filter - An enum representing the available verbosity level filters of the logger.
Traits§
- Colo
LogTrace - 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
Arc
edSink
trait reference and installs it as a log sink / receiver. The sink can be later disabled by invokingpipe(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.