pub struct AutoSaveLogger { /* private fields */ }Expand description
Transaction logger with automatic persistence.
Wraps a TxLogger and automatically saves to ~/.ryo/ based on the
configured TxLogMode.
§Example
use ryo_core::storage::{AutoSaveLogger, TxLogMode};
// Create with auto-save on commit
let logger = AutoSaveLogger::new("/my/project", 100, TxLogMode::OnCommit)?;
// Log as usual
logger.log_mutation("Rename", "foo -> bar", 5);
// Trigger save (e.g., called from CodingWorld::commit_changes)
logger.on_commit()?;
// Finish and get the log
let log = logger.finish()?;Implementations§
Source§impl AutoSaveLogger
impl AutoSaveLogger
Sourcepub fn new(
project_path: impl Into<PathBuf>,
file_count: usize,
mode: TxLogMode,
) -> StorageResult<Self>
pub fn new( project_path: impl Into<PathBuf>, file_count: usize, mode: TxLogMode, ) -> StorageResult<Self>
Create a new auto-save logger.
Sourcepub fn with_format(
project_path: impl Into<PathBuf>,
file_count: usize,
mode: TxLogMode,
format: Format,
) -> StorageResult<Self>
pub fn with_format( project_path: impl Into<PathBuf>, file_count: usize, mode: TxLogMode, format: Format, ) -> StorageResult<Self>
Create with a specific storage format.
Sourcepub fn with_storage(
project_path: impl Into<PathBuf>,
file_count: usize,
mode: TxLogMode,
storage: RyoStorage,
) -> Self
pub fn with_storage( project_path: impl Into<PathBuf>, file_count: usize, mode: TxLogMode, storage: RyoStorage, ) -> Self
Create with explicit storage (for testing or custom paths).
Sourcepub fn log_mutation(
&mut self,
mutation_type: &str,
target: &str,
changes: usize,
) -> StorageResult<()>
pub fn log_mutation( &mut self, mutation_type: &str, target: &str, changes: usize, ) -> StorageResult<()>
Log a mutation being applied (legacy API - NOT replayable).
Note: For replayable logging, use record_mutation() instead.
If mode is OnMutation, this will trigger a persist.
Sourcepub fn record_mutation<M>(
&mut self,
mutation: &M,
changes: usize,
) -> StorageResult<()>where
M: Mutation + ToSerializable,
pub fn record_mutation<M>(
&mut self,
mutation: &M,
changes: usize,
) -> StorageResult<()>where
M: Mutation + ToSerializable,
Record a mutation with automatic serialization (REPLAYABLE).
This is the preferred method for logging mutations.
If mode is OnMutation, this will trigger a persist.
Sourcepub fn record_mutation_for_file<M>(
&mut self,
mutation: &M,
changes: usize,
file_path: impl AsRef<Path>,
) -> StorageResult<()>where
M: Mutation + ToSerializable,
pub fn record_mutation_for_file<M>(
&mut self,
mutation: &M,
changes: usize,
file_path: impl AsRef<Path>,
) -> StorageResult<()>where
M: Mutation + ToSerializable,
Record a mutation with file path (REPLAYABLE).
If mode is OnMutation, this will trigger a persist.
Sourcepub fn record_mutation_tracked<M>(
&mut self,
mutation: &M,
changes: usize,
file_path: impl AsRef<Path>,
pre_state: StateRef,
post_state: StateRef,
) -> StorageResult<()>where
M: Mutation + ToSerializable,
pub fn record_mutation_tracked<M>(
&mut self,
mutation: &M,
changes: usize,
file_path: impl AsRef<Path>,
pre_state: StateRef,
post_state: StateRef,
) -> StorageResult<()>where
M: Mutation + ToSerializable,
Record a mutation with full state tracking (REPLAYABLE + VERIFIABLE).
If mode is OnMutation, this will trigger a persist.
Sourcepub fn log_mutation_with_data(
&mut self,
mutation_type: &str,
target: &str,
changes: usize,
data: Value,
) -> StorageResult<()>
pub fn log_mutation_with_data( &mut self, mutation_type: &str, target: &str, changes: usize, data: Value, ) -> StorageResult<()>
Log a mutation with data.
Sourcepub fn log_mutation_batch(
&mut self,
mutations: Vec<MutationRecord>,
total_changes: usize,
) -> StorageResult<()>
pub fn log_mutation_batch( &mut self, mutations: Vec<MutationRecord>, total_changes: usize, ) -> StorageResult<()>
Log a batch of mutations.
Sourcepub fn log_file_loaded(&self, path: &Path, size_bytes: usize)
pub fn log_file_loaded(&self, path: &Path, size_bytes: usize)
Log file loaded.
Sourcepub fn log_file_modified(&self, path: &Path, changes: usize)
pub fn log_file_modified(&self, path: &Path, changes: usize)
Log file modified.
Sourcepub fn log_file_written(&self, path: &Path)
pub fn log_file_written(&self, path: &Path)
Log file written.
Sourcepub fn log_compile_check(&self, success: bool, errors: Vec<String>)
pub fn log_compile_check(&self, success: bool, errors: Vec<String>)
Log compile check result.
Sourcepub fn checkpoint(&self, name: &str)
pub fn checkpoint(&self, name: &str)
Create a checkpoint.
Sourcepub fn log_custom(&self, name: &str, data: Value)
pub fn log_custom(&self, name: &str, data: Value)
Log a custom action.
Sourcepub fn on_commit(&mut self) -> StorageResult<()>
pub fn on_commit(&mut self) -> StorageResult<()>
Called when commit_changes() is invoked.
If mode is OnCommit, this will trigger a persist.
Sourcepub fn persist(&mut self) -> StorageResult<String>
pub fn persist(&mut self) -> StorageResult<String>
Explicitly persist the current log to storage.
This can be called at any time, regardless of mode. Uses incremental save if session already has an ID.
Sourcepub fn finish(self) -> StorageResult<(TxLog, Option<String>)>
pub fn finish(self) -> StorageResult<(TxLog, Option<String>)>
Finish logging and persist the final log.
Returns the complete log and the session ID if persisted.
Sourcepub fn finish_log(self) -> TxLog
pub fn finish_log(self) -> TxLog
Finish and return just the log (for compatibility).
Sourcepub fn elapsed_ms(&self) -> u64
pub fn elapsed_ms(&self) -> u64
Get elapsed time since session start.
Auto Trait Implementations§
impl Freeze for AutoSaveLogger
impl !RefUnwindSafe for AutoSaveLogger
impl Send for AutoSaveLogger
impl Sync for AutoSaveLogger
impl Unpin for AutoSaveLogger
impl UnsafeUnpin for AutoSaveLogger
impl !UnwindSafe for AutoSaveLogger
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
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more