pub struct Logger { /* private fields */ }Expand description
Crash report data structure.
Contains all information needed to generate a detailed crash report that can be saved locally as a TOML file or uploaded to Sentry. Created automatically when a panic occurs.
Implementations§
Source§impl Logger
Implementation of Logger.
impl Logger
Implementation of Logger.
Sourcepub fn init(
logging_path: &Path,
verbose: bool,
set_logger: bool,
release: Option<Cow<'static, str>>,
) -> Result<ClientInitGuard>
pub fn init( logging_path: &Path, verbose: bool, set_logger: bool, release: Option<Cow<'static, str>>, ) -> Result<ClientInitGuard>
Initializes the logging system with crash reporting and Sentry integration.
This function sets up three logging mechanisms:
- Local crash reports: Panics are saved as TOML files to disk
- Sentry crash reporting: Panics are uploaded to Sentry (release builds only)
- Runtime logging: Structured logging via terminal and Sentry breadcrumbs
§Arguments
logging_path- Directory where crash reports will be savedverbose- Iftrue, logInfolevel messages; iffalse, onlyWarnand aboveset_logger- Iftrue, initialize the global logger (disable for testing)release- Optional release identifier for Sentry (e.g.,"rpfm@5.0.0")
§Returns
Returns a ClientInitGuard that must be kept alive for the duration of the program.
Dropping the guard will shut down Sentry and flush pending events.
§Panics
After initialization, any panic in any thread will:
- Generate a local crash report in
logging_path - Upload to Sentry (if in release mode and enabled)
- Mark the Sentry session as crashed
§Example
let _guard = Logger::init(
Path::new("crash_reports"),
true, // verbose
true, // set global logger
Some("myapp@1.0.0".into())
)?;
// Logger is now active
// Keep _guard alive until program exitSourcepub fn new(panic_info: &PanicHookInfo<'_>, version: &str) -> Self
pub fn new(panic_info: &PanicHookInfo<'_>, version: &str) -> Self
Creates a crash report from panic information.
This function extracts all relevant information from a panic and constructs
a structured crash report. The report is created in memory and must be
explicitly saved with Logger::save().
§Arguments
panic_info- Panic hook information provided by the panic handlerversion- Version string of the program
§Returns
Returns a populated Logger instance containing the crash report data.
§Note
This is typically called automatically by the panic hook installed by Logger::init().
Sourcepub fn send_event(
sentry_guard: &ClientInitGuard,
level: Level,
message: &str,
data: Option<(&str, &[u8])>,
) -> Result<()>
pub fn send_event( sentry_guard: &ClientInitGuard, level: Level, message: &str, data: Option<(&str, &[u8])>, ) -> Result<()>
Sends a custom event to Sentry with optional file attachment.
This function creates and uploads a Sentry event with a message and optional data attachment. Useful for manually reporting errors or uploading diagnostic data.
§Arguments
sentry_guard- The Sentry client guard (must be active)level- Severity level (e.g.,Level::Info,Level::Warning,Level::Error)message- Event message/descriptiondata- Optional tuple of(filename, data_bytes)to attach to the event
§Returns
Returns Ok if the event was sent (or Sentry is disabled), or an error on failure.
§Note
If Sentry is not enabled (debug builds or no DSN), this function does nothing
and returns Ok.
§Example
// Send a simple event
Logger::send_event(sentry_guard, Level::Info, "Schema updated", None)?;
// Send an event with attachment
let patch_data = b"some patch data";
Logger::send_event(
sentry_guard,
Level::Warning,
"Schema patch failed",
Some(("patch.json", patch_data))
)?;Sourcepub fn upload_patches(
sentry_guard: &ClientInitGuard,
game_name: &str,
patches: &impl Serialize,
) -> Result<()>
pub fn upload_patches( sentry_guard: &ClientInitGuard, game_name: &str, patches: &impl Serialize, ) -> Result<()>
Uploads schema patches to Sentry for debugging/analysis.
Serializes the data to RON format and sends it as an informational Sentry event.
§Arguments
sentry_guard- The Sentry client guardgame_name- Name of the game the patches are forpatches- The data to upload (must implementSerialize)
Sourcepub fn upload_definitions(
sentry_guard: &ClientInitGuard,
game_name: &str,
definitions: &impl Serialize,
) -> Result<()>
pub fn upload_definitions( sentry_guard: &ClientInitGuard, game_name: &str, definitions: &impl Serialize, ) -> Result<()>
Uploads schema definitions to Sentry for debugging/analysis.
Serializes the data to RON format and sends it as an informational Sentry event.
§Arguments
sentry_guard- The Sentry client guardgame_name- Name of the game the definitions are fordefinitions- The data to upload (must implementSerialize)