https://github.com/ossystems/logging_content
Some utilities for logging data and results of operations
https://github.com/ossystems/logging_content
Last synced: 6 months ago
JSON representation
Some utilities for logging data and results of operations
- Host: GitHub
- URL: https://github.com/ossystems/logging_content
- Owner: OSSystems
- License: apache-2.0
- Created: 2021-09-14T18:02:15.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2022-06-06T20:37:33.000Z (almost 4 years ago)
- Last Synced: 2025-02-28T12:34:21.411Z (about 1 year ago)
- Language: Rust
- Size: 11.7 KB
- Stars: 0
- Watchers: 5
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.org
- License: LICENSE
Awesome Lists containing this project
README
#+Title: logging_content
This is a library intendeted for making logging intermediary results of operations simpler,
while also adding context to the current state of operations.
Here are some code samples to show the library could be used:
Start by adding the macro calls to where you wan't it's definition in:
#+BEGIN_SRC rust
logging_content::trait_LogContent!();
logging_content::trait_LogDisplay!();
logging_content::impl_Result!();
#+END_SRC
And define how you wan't kown types to be displayed when logging:
#+BEGIN_SRC rust
impl LogDisplay for E {
fn as_log_display(&self, _: logging_content::Level) -> String {
format!("{} ({:?})", self, self)
}
}
#+END_SRC
Then you can easily add some log calls without changing anything inside your `Result` type.
#+BEGIN_SRC rust
// Import LogContent trait from where it was defined
use utils::log::LogContent;
let mut input = utils::io::timed_buf_reader(
chunk_size,
fs::File::open(source).log_error_msg("failed to open source file")?,
);
input.seek(SeekFrom::Start(skip)).log_error_msg("failed to seek source file")?;
let mut output = utils::io::timed_buf_writer(
chunk_size,
fs::OpenOptions::new()
.read(true)
.write(true)
.truncate(truncate)
.open(device)
.log_error_msg("failed to open output file")?,
);
output.seek(SeekFrom::Start(seek)).log_error_msg("failed to seek output file")?;
#+END_SRC
The [[examples/result_logging.rs][result_logging]] example shows a more self contained example.