Skip to content

Basic logging: log entity create/update/delete events#224

Open
strobelm wants to merge 2 commits into
developeregrem:masterfrom
strobelm:feat/logging
Open

Basic logging: log entity create/update/delete events#224
strobelm wants to merge 2 commits into
developeregrem:masterfrom
strobelm:feat/logging

Conversation

@strobelm
Copy link
Copy Markdown
Contributor

Maybe sth. less controversial as first larger PR. My PHP is a bit rusty (pun intended) :), a review would be very helpful.

This PR replaces the unused Log stub with a new schema (auto-id, user FK, username snapshot, datetime, entity class+id, JSON changes, IP).

A Doctrine listener collects changesets in onFlush and writes Log rows via the background EM in postFlush, same as LastActionSubscriber. Updates store only changed fields; creates and deletes store full snapshots.

Password, salt, token, secret, apiKey and privateKey fields are stored as redacted. Log, WorkflowLog, MonthlyStatsSnapshot and User.lastAction are filtered out.

Produces logs like this

id user_id username date entity_class entity_id action changes ip_address
9 1 admin 2026-05-13 08:45:50 App\Entity\InvoiceAppartment 3 delete {"id":[3,null],"number":["7",null],"description":["Doppelzimmer mit Dachfenster",null],"beds":[2,null],"persons":[2,null],"startDate":["2026-05-12T00:00:00+00:00",null],"endDate":["2026-05-13T00:00:00+00:00",null],"price":["42.00",null],"vat":[7.0,null],"includesVat":[true,null],"isFlatPrice":[false,null],"isPerRoom":[false,null]} 172.23.0.1

Closes #19.

@developeregrem
Copy link
Copy Markdown
Owner

Hi @strobelm thanks a lot! Looks quit good at the moment. I will test it in the next few days.
One thing we should keep in mind is log retention. Especially the IP adress is a PII which needs to be handles carefully (GDPR). Therefore, I would suggest maybe a command which deletes old log entries based on a configurable period. This command can be triggered e.g. via cron job.

@strobelm
Copy link
Copy Markdown
Contributor Author

@developeregrem thanks for the feedback.

Good point on the the logging of IP addresses. I re-used the existing workflow purge mechanism and unified it in a app:purge-logs command. Hope this works for you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add Logging

2 participants