Skip to main content

Logger

Struct Logger 

Source
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.

Source

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:

  1. Local crash reports: Panics are saved as TOML files to disk
  2. Sentry crash reporting: Panics are uploaded to Sentry (release builds only)
  3. Runtime logging: Structured logging via terminal and Sentry breadcrumbs
§Arguments
  • logging_path - Directory where crash reports will be saved
  • verbose - If true, log Info level messages; if false, only Warn and above
  • set_logger - If true, 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:

  1. Generate a local crash report in logging_path
  2. Upload to Sentry (if in release mode and enabled)
  3. 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 exit
Source

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 handler
  • version - 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().

Source

pub fn save(&self, path: &Path) -> Result<()>

Saves the crash report to a TOML file.

The crash report is saved with a timestamped filename in the format error-report-{timestamp}.toml.

§Arguments
  • path - Directory where the crash report file should be saved
§Returns

Returns Ok if the report was saved successfully, or an error if file I/O fails.

Source

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/description
  • data - 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))
)?;
Source

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 guard
  • game_name - Name of the game the patches are for
  • patches - The data to upload (must implement Serialize)
Source

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 guard
  • game_name - Name of the game the definitions are for
  • definitions - The data to upload (must implement Serialize)

Trait Implementations§

Source§

impl Debug for Logger

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Serialize for Logger

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

§

impl<T> PolicyExt for T
where T: ?Sized,

§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] only if self and other return Action::Follow. Read more
§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] if either self or other returns Action::Follow. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more