Cleaning up the log | laravel-activitylog-go | Spatie       

 SPATIE  

laravel-activitylog-go
======================

spatie.be/open-source

  [Docs](https://spatie.be/docs)  [Laravel-activitylog-go](https://spatie.be/docs/laravel-activitylog-go/v1)  Basic-usage  Cleaning up the log

 Version   v1      

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

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

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

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

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

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

 Cleaning up the log
===================

###  On this page 

1. [ Define the log to clean ](#content-define-the-log-to-clean)
2. [ Overwrite the days to keep per call ](#content-overwrite-the-days-to-keep-per-call)
3. [ MySQL: rebuild index and reclaim space after clean ](#content-mysql-rebuild-index-and-reclaim-space-after-clean)

After using the package for a while, you might have recorded a lot of activity. This package provides the `activitylog:clean` command to clean the log.

Running this command deletes activity older than `Config.CleanAfterDays`, which defaults to 365:

```
go run . activitylog:clean
```

Use `--force` in production. Without it the command refuses to delete records. Schedule this command with your application's scheduler or deployment platform.

Define the log to clean
-----------------------------------------------------------------------------------------------------------------------------

```
go run . activitylog:clean my_log_channel
```

Overwrite the days to keep per call
-----------------------------------------------------------------------------------------------------------------------------------------------------------------

```
go run . activitylog:clean --days=7
go run . activitylog:clean --days=7 --force my_log_channel
```

Retention must be a positive integer no greater than 3650000. A record exactly at the cutoff survives. The cutoff uses calendar days and the framework clock. You can also call `From(ctx).Clean(ctx, 7, nil)`, or pass a log-name pointer instead of nil.

The configured store and cleanup action apply to both the command and the Go API.

MySQL: rebuild index and reclaim space after clean
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

MySQL administrators may choose to run `OPTIMIZE TABLE activity_log` or `ANALYZE TABLE activity_log` in maintenance mode. These operations can lock reads and writes. The package never runs them automatically.

 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)
