Log Options | laravel-activitylog | Spatie

 SPATIE

  Laravel Activity Log
=======================

spatie.be/open-source

  [Docs](https://spatie.be/docs)  [Laravel-activitylog](https://spatie.be/docs/laravel-activitylog/v5)  Advanced-usage  Log Options

 Version   v5   v4   v3   v2   v1

 Other versions for crawler [v5](https://spatie.be/docs/laravel-activitylog/v5) [v4](https://spatie.be/docs/laravel-activitylog/v4) [v3](https://spatie.be/docs/laravel-activitylog/v3) [v2](https://spatie.be/docs/laravel-activitylog/v2) [v1](https://spatie.be/docs/laravel-activitylog/v1)

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

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

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

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

- [ Logging model events ](https://spatie.be/docs/laravel-activitylog/v5/advanced-usage/logging-model-events)
- [ Define causer for runtime ](https://spatie.be/docs/laravel-activitylog/v5/advanced-usage/define-causer-for-runtime)
- [ Using placeholders ](https://spatie.be/docs/laravel-activitylog/v5/advanced-usage/using-placeholders)
- [ Using multiple logs ](https://spatie.be/docs/laravel-activitylog/v5/advanced-usage/using-multiple-logs)
- [ Disabling logging ](https://spatie.be/docs/laravel-activitylog/v5/advanced-usage/disabling-logging)
- [ Customizing actions ](https://spatie.be/docs/laravel-activitylog/v5/advanced-usage/customizing-actions)
- [ Before logging hook ](https://spatie.be/docs/laravel-activitylog/v5/advanced-usage/before-logging-hook)
- [ Buffering activities ](https://spatie.be/docs/laravel-activitylog/v5/advanced-usage/buffering)
- [ Log Options ](https://spatie.be/docs/laravel-activitylog/v5/advanced-usage/log-options)
- [ Causer Resolver ](https://spatie.be/docs/laravel-activitylog/v5/advanced-usage/causer-resolver)

 Log Options
===========

###  On this page

1. [ Options methods ](#content-options-methods)

Customization of how your models will be logged is controlled by implementing `getActivitylogOptions()`. This method is optional. If not implemented, the package uses sensible defaults (logs events but no attribute changes).

The most basic example of an Activity logged model is:

```
use Illuminate\Database\Eloquent\Model;
use Spatie\Activitylog\Models\Concerns\LogsActivity;

class YourModel extends Model
{
    use LogsActivity;
}
```

To customize what gets logged, override `getActivitylogOptions()`:

```
use Illuminate\Database\Eloquent\Model;
use Spatie\Activitylog\Models\Concerns\LogsActivity;
use Spatie\Activitylog\Support\LogOptions;

class YourModel extends Model
{
    use LogsActivity;

    public function getActivitylogOptions(): LogOptions
    {
        return LogOptions::defaults()
        ->logFillable()
        ->logOnlyDirty();
    }
}
```

The call to `LogOptions::defaults()` yields the following default options:

```
public ?string $logName = null;

public bool $logEmptyChanges = true;

public bool $logFillable = false;

public bool $logOnlyDirty = false;

public bool $logUnguarded = false;

public array $logAttributes = [];

public array $logExceptAttributes = [];

public array $dontLogIfAttributesChangedOnly = [];

public array $attributeRawValues = [];

public ?Closure $descriptionForEvent = null;
```

Options methods
-----------------------------------------------------------------------------------------------------

### defaults

```
/**
 * Start configuring model with the default options.
 */
public static function defaults(): LogOptions;
```

### logAll

This method is equivalent to `->logOnly(['*'])`.

```
/**
 * Log all attributes on the model.
 */
public function logAll(): LogOptions;
```

### logUnguarded

```
/**
 * Log changes to all attributes that are not listed in $guarded.
 */
public function logUnguarded(): LogOptions;
```

This can be combined with `->logFillable()` or `->logOnly()`. The final set of logged attributes is the union of all sources.

### logFillable

```
/**
 * Log changes to all the $fillable attributes of the model.
 */
public function logFillable(): LogOptions;
```

This can be combined with `->logUnguarded()` or `->logOnly()`. The final set of logged attributes is the union of all sources.

### dontLogFillable

```
/**
 * Stop logging $fillable attributes of the model.
 */
public function dontLogFillable(): LogOptions;
```

### logOnlyDirty

```
/**
 * Log changes that have actually changed after the update.
 */
public function logOnlyDirty(): LogOptions;
```

### logOnly

```
/**
 * Only log changes to these specific attributes.
 */
public function logOnly(array $attributes): LogOptions;
```

### logExcept

Convenient method for excluding specific attributes from logging.

```
/**
 * Exclude these attributes from being logged.
 */
public function logExcept(array $attributes): LogOptions;
```

### dontLogIfAttributesChangedOnly

```
/**
 * Don't trigger an activity if only these attributes changed.
 */
public function dontLogIfAttributesChangedOnly(array $attributes): LogOptions;
```

### dontLogEmptyChanges

```
/**
 * Don't store empty logs. Empty logs can occur when you're tracking
 * specific attributes but none of them actually changed.
 */
public function dontLogEmptyChanges(): LogOptions;
```

### logEmptyChanges

```
/**
 * Allow storing empty logs.
 */
public function logEmptyChanges(): LogOptions;
```

### useLogName

```
/**
 * Customize log name.
 */
public function useLogName(string $logName): LogOptions;
```

### useAttributeRawValues

```
/**
 * Skip using mutators for these attributes when logged.
 */
public function useAttributeRawValues(array $attributes): LogOptions;
```

### setDescriptionForEvent

```
/**
 * Customize log description using callback.
 */
public function setDescriptionForEvent(Closure $callback): LogOptions;
```

 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)
