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/v4)  Api  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)

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

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

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

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

- [ Logging model events ](https://spatie.be/docs/laravel-activitylog/v4/advanced-usage/logging-model-events)
- [ Manipulate changes array ](https://spatie.be/docs/laravel-activitylog/v4/advanced-usage/manipulate-changes-array)
- [ Batch Logs ](https://spatie.be/docs/laravel-activitylog/v4/advanced-usage/batch-logs)
- [ Define causer for runtime ](https://spatie.be/docs/laravel-activitylog/v4/advanced-usage/define-causer-for-runtime)
- [ Using placeholders ](https://spatie.be/docs/laravel-activitylog/v4/advanced-usage/using-placeholders)
- [ Using multiple logs ](https://spatie.be/docs/laravel-activitylog/v4/advanced-usage/using-multiple-logs)
- [ Disabling logging ](https://spatie.be/docs/laravel-activitylog/v4/advanced-usage/disabling-logging)

API
---

- [ Log Options ](https://spatie.be/docs/laravel-activitylog/v4/api/log-options)
- [ Log Batch ](https://spatie.be/docs/laravel-activitylog/v4/api/log-batch)
- [ Causer Resolver ](https://spatie.be/docs/laravel-activitylog/v4/api/causer-resolver)
- [ Event Bag ](https://spatie.be/docs/laravel-activitylog/v4/api/event-bag)

      You are viewing the documentation for **an older version** of this package. You can check the version you are using with the following command:

 `                                    composer show spatie/laravel-activitylog                                                                                                                                                                                                                                    `

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

###  On this page

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

Customization of how your models will be logged is controlled when implementing `getActivitylogOptions`. You can start from the defaults and override values as needed.

The most basic example of an Activity logged model would be:

```
use Illuminate\Database\Eloquent\Model;
use Spatie\Activitylog\Traits\LogsActivity;
use Spatie\Activitylog\LogOptions;

class YourModel extends Model
{
    use LogsActivity;

    public function getActivitylogOptions(): LogOptions
    {
        return LogOptions::defaults();
    }
}
```

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

```
public ?string $logName = null;

public bool $submitEmptyLogs = 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(): LogOption;
```

### logAll

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

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

### logUnguarded

This option will respect the wildcard `*`, `->logAll()` and `->logFillable()` methods.

```
/**
 * log changes to all the $guarded attributes of the model
 */
public function logUnguarded(): LogOption;
```

### logFillable

This option will respect the wildcard `*`, `->logAll()` and `->logUnguarded()` methods.

```
/**
 * log changes to all the $fillable attributes of the model
 */
public function logFillable(): LogOption;
```

### dontLogFillable

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

### logOnlyDirty

```
/**
 * Log changes that has actually changed after the update
 */
public function logOnlyDirty(): LogOption;
```

### logOnly

```
/**
 * Log changes only if these attributes changed
 */
public function logOnly(array $attributes): LogOption;
```

### logExcept

Convenient method for `logOnly()`

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

### dontLogIfAttributesChangedOnly

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

### dontSubmitEmptyLogs

```
/**
 * Dont store empty logs. Storing empty logs can happen when you only
 * want to log a certain attribute but only another changes.
 */
public function dontSubmitEmptyLogs(): LogOption;
```

### submitEmptyLogs

```
/**
 * Allow storing empty logs. Storing empty logs can happen when you only
 * want to log a certain attribute but only another changes.
 */
public function submitEmptyLogs(): LogOption;
```

### useLogName

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

### useAttributeRawValues

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

### setDescriptionForEvent

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