Installation and setup | laravel-activitylog-rust | Spatie       

 SPATIE  

laravel-activitylog-rust
========================

spatie.be/open-source

  [Docs](https://spatie.be/docs)  [Laravel-activitylog-rust](https://spatie.be/docs/laravel-activitylog-rust/v1)  Installation and setup

 Version   v1      

 Other versions for crawler [v1](https://spatie.be/docs/laravel-activitylog-rust/v1) 

  Installation and setup    
- [ Introduction ](https://spatie.be/docs/laravel-activitylog-rust/v1/introduction)
- [ Support us ](https://spatie.be/docs/laravel-activitylog-rust/v1/support-us)
- [ Requirements ](https://spatie.be/docs/laravel-activitylog-rust/v1/requirements)
- [ Installation and setup ](https://spatie.be/docs/laravel-activitylog-rust/v1/installation-and-setup)
- [ Questions and issues ](https://spatie.be/docs/laravel-activitylog-rust/v1/questions-and-issues)
- [ Changelog ](https://spatie.be/docs/laravel-activitylog-rust/v1/changelog)
- [ Upgrading ](https://spatie.be/docs/laravel-activitylog-rust/v1/upgrading)
- [ About us ](https://spatie.be/docs/laravel-activitylog-rust/v1/about-us)
- [ Testing ](https://spatie.be/docs/laravel-activitylog-rust/v1/testing)

Basic usage
-----------

- [ Logging activity ](https://spatie.be/docs/laravel-activitylog-rust/v1/basic-usage/logging-activity)
- [ Cleaning up the log ](https://spatie.be/docs/laravel-activitylog-rust/v1/basic-usage/cleaning-up-the-log)

Advanced usage
--------------

- [ Logging model events ](https://spatie.be/docs/laravel-activitylog-rust/v1/advanced-usage/logging-model-events)
- [ Log options ](https://spatie.be/docs/laravel-activitylog-rust/v1/advanced-usage/log-options)
- [ Buffering activities ](https://spatie.be/docs/laravel-activitylog-rust/v1/advanced-usage/buffering)
- [ Default causer for a logger ](https://spatie.be/docs/laravel-activitylog-rust/v1/advanced-usage/define-causer-for-runtime)
- [ Using placeholders ](https://spatie.be/docs/laravel-activitylog-rust/v1/advanced-usage/using-placeholders)
- [ Using multiple logs ](https://spatie.be/docs/laravel-activitylog-rust/v1/advanced-usage/using-multiple-logs)
- [ Disabling logging ](https://spatie.be/docs/laravel-activitylog-rust/v1/advanced-usage/disabling-logging)
- [ Custom activity models ](https://spatie.be/docs/laravel-activitylog-rust/v1/advanced-usage/customizing-actions)
- [ Before logging hook ](https://spatie.be/docs/laravel-activitylog-rust/v1/advanced-usage/before-logging-hook)
- [ Causer identity ](https://spatie.be/docs/laravel-activitylog-rust/v1/advanced-usage/causer-resolver)

 Installation and setup
======================

###  On this page 

1. [ A different table or connection ](#content-a-different-table-or-connection)
2. [ Database transactions ](#content-database-transactions)

Install this package from its Git repository. It has `publish = false` and is not on crates.io.

Use Rust 1.99 or newer. Depend on `laravel-rust = "=0.1.0"` with the `database-sqlite`feature and this package through Git or a local path. The framework crate's Rust import is `laravel`.

Register the provider at application boot:

```
use laravel::Application;
use spatie_activitylog::{service_provider, Config};

let app = Application::configure()
    .replace_env(laravel::config::Env::default())
    .with_providers(|providers| { providers.add(service_provider()); })
    .with_config(|config, _| {
        config.set(Config {
            default_log_name: Some("application".into()),
            ..Config::default()
        });
    })
    .create();
assert_eq!(app.config().section::<Config>().clean_after_days, 365);
```

The Cargo package is `spatie-laravel-activitylog`; Rust imports remain `spatie_activitylog`. The provider uses `spatie-laravel-package-tools`, pinned to its reviewed Git revision. CI uses `SPATIE_GITHUB_TOKEN` for Git authentication when set. Public dependencies do not require it.

`ACTIVITYLOG_ENABLED` defaults to true. `ACTIVITYLOG_BUFFER_ENABLED` defaults to false. Invalid environment values fail native environment validation. Global buffering is rejected at boot because transient observers cannot own a shared flush lifecycle. Use an explicit buffer for manual logging. Application `with_config` sections override environment defaults.

Configure the framework's `DB_CONNECTION=sqlite` and `DATABASE_URL`. Run the application's `migrate` command. The provider adds the package's native migration to the normal migrator, which records it in `migrations`. Alternatively, add `spatie_activitylog::migrations()`to your own migration set. Do not register it twice.

`Activity` is a native ORM model over the default `activity_log` table. Properties and changes are JSON; timestamps use `laravel::time::Timestamp`. Polymorphic IDs are text, including integer IDs, UUIDs, ULIDs and string IDs such as `007`.

The provider registers a transient logger. A fresh resolution starts with fresh state, so a previous request's causer or disabled flag cannot leak. Keep and clone one logger within a request when you need shared overrides. To include automatic observers, use `with_causer(actor, future)` or `without_logging(future)`. See [buffering](advanced-usage/buffering).

A different table or connection
-----------------------------------------------------------------------------------------------------------------------------------------------------

Set `Config.table_name` and `Config.database_connection` to select a table and an existing framework connection name. Create that schema with an application migration on the target database. The bundled migration always creates `activity_log` on the connection being migrated. The package query and cleanup methods use the configured destination; `Activity::query()`uses its model's default table and connection. Use the former for custom destinations.

<a id="database-transactions"></a>

Database transactions
-----------------------------------------------------------------------------------------------------------------------

Use `laravel::db::transaction`. Immediate activity writes on the default connection join the transaction and its savepoints. A rollback removes both the model change and its log. Observers run through the native dispatcher's `listen_at_dispatch`, inside the transaction.

Named audit destinations wait for the source transaction's outer commit using `db::after_commit`. Rollbacks discard them. Different databases are not atomic: if an audit insert fails after commit, the model remains committed and the framework reports an after-commit error. Use an application outbox if you require crash-safe cross-database delivery.

 A good
match?
-------------

### What we do best

- All things Laravel
- Custom frontend components
- Building APIs
- AI-powered features
- Simplifying things
- Clean solutions
- Integrating services

### Not our cup of tea

- WordPress themes
- Cutting corners
- Free mockups to win a job
- "Just execute the briefing"

 In short: we'd like to be a **substantial part** of your project.

 [ Get in touch via email ](mailto:info@spatie.be?subject=A%20good%20match%21&body=Tell%20us%20as%20much%20as%20you%20can%20about%0A-%20your%20online%20project%0A-%20your%20planning%0A-%20your%20budget%0A-%20%E2%80%A6%0A%0AAnything%20that%20helps%20us%20to%20start%20straightforward%21)
