Struct bp3d_logger::LogMsg
source · #[repr(C)]pub struct LogMsg { /* private fields */ }Expand description
A log message.
This structure uses a large 1K buffer which stores the entire log message to improve performance.
The repr(C) is used to force the control fields (msg_len, level and target_len) to be before the message buffer and avoid large movs when setting control fields.
§Examples
use log::Level;
use bp3d_logger::LogMsg;
use std::fmt::Write;
let mut msg = LogMsg::new("test", Level::Info);
let _ = write!(msg, "This is a formatted message {}", 42);
assert_eq!(msg.msg(), "This is a formatted message 42");Implementations§
source§impl LogMsg
impl LogMsg
sourcepub fn new(target: &str, level: Level) -> LogMsg
pub fn new(target: &str, level: Level) -> LogMsg
Creates a new instance of log message buffer.
§Arguments
target: the target name this log comes from.level: the Level of the log message.
returns: LogMsg
§Examples
use log::Level;
use bp3d_logger::LogMsg;
let msg = LogMsg::new("test", Level::Info);
assert_eq!(msg.target(), "test");
assert_eq!(msg.level(), Level::Info);sourcepub fn clear(&mut self)
pub fn clear(&mut self)
Clears the log message but keep the target and the level.
§Examples
use log::Level;
use bp3d_logger::LogMsg;
let mut msg = LogMsg::from_msg("test", Level::Info, "this is a test");
msg.clear();
assert_eq!(msg.msg(), "");
assert_eq!(msg.target(), "test");
assert_eq!(msg.level(), Level::Info);sourcepub fn from_msg(target: &str, level: Level, msg: &str) -> LogMsg
pub fn from_msg(target: &str, level: Level, msg: &str) -> LogMsg
Auto-creates a new log message with a pre-defined string message.
This function is the same as calling write after new.
§Arguments
target: the target name this log comes from.level: the Level of the log message.msg: the message string.
returns: LogMsg
§Examples
use log::Level;
use bp3d_logger::LogMsg;
let mut msg = LogMsg::from_msg("test", Level::Info, "this is a test");
assert_eq!(msg.target(), "test");
assert_eq!(msg.level(), Level::Info);
assert_eq!(msg.msg(), "this is a test");sourcepub unsafe fn write(&mut self, buf: &[u8]) -> usize
pub unsafe fn write(&mut self, buf: &[u8]) -> usize
Appends a raw byte buffer at the end of the message buffer.
Returns the number of bytes written.
§Arguments
buf: the raw byte buffer to append.
returns: usize
§Safety
- LogMsg contains only valid UTF-8 strings so buf must contain only valid UTF-8 bytes.
- If buf contains invalid UTF-8 bytes, further operations on the log message buffer may result in UB.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for LogMsg
impl RefUnwindSafe for LogMsg
impl Send for LogMsg
impl Sync for LogMsg
impl Unpin for LogMsg
impl UnwindSafe for LogMsg
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more