pub struct Xlog { /* private fields */ }Expand description
Handle to a Mars Xlog instance.
Cloning the handle is cheap; the underlying instance is reference-counted and released when the last handle is dropped.
Implementations§
Source§impl Xlog
impl Xlog
Sourcepub fn init(config: XlogConfig, level: LogLevel) -> Result<Self, XlogError>
pub fn init(config: XlogConfig, level: LogLevel) -> Result<Self, XlogError>
Initialize or reuse a named Xlog instance (recommended entrypoint).
Behavior is idempotent by name_prefix:
- If no live instance exists for
name_prefix, a new instance is created. - If a live instance exists with the same config, it is reused.
- If a live instance exists with a different config, returns
XlogError::ConfigConflict.
Sourcepub fn instance(&self) -> usize
pub fn instance(&self) -> usize
Returns the raw instance handle used by the underlying C++ library.
Sourcepub fn is_enabled(&self, level: LogLevel) -> bool
pub fn is_enabled(&self, level: LogLevel) -> bool
Returns true if logs at level are enabled for this instance.
Sourcepub fn set_appender_mode(&self, mode: AppenderMode)
pub fn set_appender_mode(&self, mode: AppenderMode)
Switch between async and sync appender modes.
Sourcepub fn set_console_log_open(&self, open: bool)
pub fn set_console_log_open(&self, open: bool)
Enable or disable console logging for this instance (platform dependent).
Sourcepub fn set_max_file_size(&self, max_bytes: i64)
pub fn set_max_file_size(&self, max_bytes: i64)
Set the max log file size in bytes for this instance (0 disables splitting).
Sourcepub fn set_max_alive_time(&self, alive_seconds: i64)
pub fn set_max_alive_time(&self, alive_seconds: i64)
Set the max log file age in seconds for this instance before deletion/rotation.
Sourcepub fn log(&self, level: LogLevel, tag: Option<&str>, msg: impl AsRef<str>)
pub fn log(&self, level: LogLevel, tag: Option<&str>, msg: impl AsRef<str>)
Log a message with caller file/line captured via #[track_caller].
Note: function name is not available here; use xlog! macro or
write_with_meta when you need full metadata.
Sourcepub fn write(&self, level: LogLevel, tag: Option<&str>, msg: &str)
pub fn write(&self, level: LogLevel, tag: Option<&str>, msg: &str)
Compatibility wrapper for older APIs. Prefer log or the macros.
Sourcepub fn write_with_meta(
&self,
level: LogLevel,
tag: Option<&str>,
file: &str,
func: &str,
line: u32,
msg: &str,
)
pub fn write_with_meta( &self, level: LogLevel, tag: Option<&str>, file: &str, func: &str, line: u32, msg: &str, )
Log with explicit metadata (file, function, line).
Use this when callers already provide metadata (for example from JNI).
Sourcepub fn write_with_meta_raw(
&self,
level: LogLevel,
tag: Option<&str>,
file: &str,
func: &str,
line: u32,
msg: &str,
raw_meta: RawLogMeta,
)
pub fn write_with_meta_raw( &self, level: LogLevel, tag: Option<&str>, file: &str, func: &str, line: u32, msg: &str, raw_meta: RawLogMeta, )
Log with explicit metadata and raw pid/tid/trace flags.
This is mainly for low-level platform wrappers that already own thread metadata (for example JNI side thread ids).