Meet Loggastic: an Open Source library for easily tracking and storing user activity logs to Elasticsearch. Built on top of Symfony, Loggastic comes with the API Platform support. We will explore the library’s concepts and the different paths we took before arriving at our current approach.
You’ll learn how to integrate Loggastic into your application, adapt it to your needs, and discover how to scale it for large amounts of data.
5. The goal
Track each change made on data + custom actions not related to database
changes
Ability to define which data should be tracked, including fields from relations
User friendly logs view
Support for large amount of data and fast browsing
Logging should not slow down the response time
6. What should log contain?
Entity name
Action (create, edit, delete)
Datetime
Before/after values
User
10. Loggable behavioural Doctrine extension
Track each change made on data + custom actions not related to changing data
Ability to define which data should be tracked, including fields from relations
User friendly logs view
Support for large amount of data and fast browsing
Logging should not slow down the response time
EXTRA: Ability to rollback the data to the previous state
13. Loggastic - displaying logs
Elastic
Search
Read logs
Expose to
ApiPlatform
endpoint
Expose to Twig
view
14. Loggastic - elastic indexes
<entity_name>_activity_log
<entity_name>_current_data_tracker
Contains current
object data used for
comparing changed
object
Needs to be up to date
with database values
Contains actual
activity logs for
current object
21. 3. Run commands for creating Elastic indexes
bin/console locastic:activity-logs:create-loggable-indexes
bin/console locastic:activity-logs:populate-current-data-trackers
If you already have some data in database:
32. Basic implementation summary
Add Loggable attribute to entity and serialization groups to
properties
Run command for creating indexes
Expose an api endpoint or display logs in twig