# How to hook into the Lead audit log

**URL:** <https://forum.mautic.org/t/how-to-hook-into-the-lead-audit-log/30538>\
**Category:** Development\
**Created:** [January 17, 2024, 5:43pm UTC](https://forum.mautic.org/t/how-to-hook-into-the-lead-audit-log/30538 "2024-01-17T17:43:12Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![peter\_k](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/peter_k/32/511_2.png) [@peter\_k](https://forum.mautic.org/u/peter_k)\
**Post date:** [January 17, 2024, 5:43pm UTC](https://forum.mautic.org/t/how-to-hook-into-the-lead-audit-log/30538/1 "2024-01-17T17:43:12Z")

</div>

Hey there,

I would like to show data in the lead’s audit log (`/contacts/auditlog/{leadId}`).

It seems that the audit log offers no way to hook into.

- LeadBundle/Controller/AuditlogController.php [fetches the audit log events from](https://github.com/mautic/mautic/blob/a8c2f81324462f73d4192ab19dc43890683d2e7e/app/bundles/LeadBundle/Controller/AuditlogController.php#L47) via the LeadDetailsTrait.
- The trait [fetches the log events from](https://github.com/mautic/mautic/blob/a8c2f81324462f73d4192ab19dc43890683d2e7e/app/bundles/LeadBundle/Controller/LeadDetailsTrait.php#L223) the AuditLogRepository.
- [AuditLogRepository::getAuditLogs()](https://github.com/mautic/mautic/blob/a8c2f81324462f73d4192ab19dc43890683d2e7e/app/bundles/CoreBundle/Entity/AuditLogRepository.php#L51) has hard coded database call.

The [devdocs](https://devdocs.mautic.org/en/5.x/components/contacts.html) only mention hooking into the history.

Is there a way? If so, how?

Kind regards

---

<div class="post-metadata">

**Author:** ![escopecz](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/escopecz/32/370_2.png) [@escopecz](https://forum.mautic.org/u/escopecz)\
**Post date:** [January 18, 2024, 7:58am UTC](https://forum.mautic.org/t/how-to-hook-into-the-lead-audit-log/30538/2 "2024-01-18T07:58:27Z")

</div>

You can listen for the `LeadEvents::TIMELINE_ON_GENERATE` event. Almost all bundles and plugins do so if you’d like more examples:

> <https://github.com/mautic/mautic/blob/a8c2f81324462f73d4192ab19dc43890683d2e7e/app/bundles/AssetBundle/EventListener/LeadSubscriber.php#L28>

---

<div class="post-metadata">

**Author:** ![peter\_k](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/peter_k/32/511_2.png) [@peter\_k](https://forum.mautic.org/u/peter_k)\
**Post date:** [January 18, 2024, 6:04pm UTC](https://forum.mautic.org/t/how-to-hook-into-the-lead-audit-log/30538/3 "2024-01-18T18:04:26Z")

</div>

Thanks for your reply.

I had a short look into the `LeadEvents::TIMELINE_ON_GENERATE` event. I figured it lets you only hook into the contact’s history “log”, but not into the audit log (marked in the screenshot):

 ![image](https://us1.discourse-cdn.com/flex020/uploads/mautic/original/2X/3/3b9703028c1e25e82ed5299fe2a09cf79c080b85.png)

Am I mistaken?

---

<div class="post-metadata">

**Author:** ![escopecz](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/escopecz/32/370_2.png) [@escopecz](https://forum.mautic.org/u/escopecz)\
**Post date:** [January 19, 2024, 9:57am UTC](https://forum.mautic.org/t/how-to-hook-into-the-lead-audit-log/30538/4 "2024-01-19T09:57:00Z")

</div>

Oh, in that tab. It shows all audit log entries that are in the audit\_log table for that contact, right? Why don’t you just store the information you want to see there in that table?

---

<div class="post-metadata">

**Author:** ![peter\_k](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/peter_k/32/511_2.png) [@peter\_k](https://forum.mautic.org/u/peter_k)\
**Post date:** [January 19, 2024, 10:54am UTC](https://forum.mautic.org/t/how-to-hook-into-the-lead-audit-log/30538/5 "2024-01-19T10:54:33Z")

</div>

> [@escopecz](#):
>
> Why don’t you just store the information you want to see there in that table?

I do. 😃

| … | bundle | object | object\_id | … |
| --- | --- | --- | --- | --- |
| … | lead | myplugin | 462 | … |

I guess, since `object!=lead` the entry isn’t picked up. Hence, I asked how to hook into this page/table.

---

<div class="post-metadata">

**Author:** ![escopecz](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/escopecz/32/370_2.png) [@escopecz](https://forum.mautic.org/u/escopecz)\
**Post date:** [January 19, 2024, 11:52am UTC](https://forum.mautic.org/t/how-to-hook-into-the-lead-audit-log/30538/6 "2024-01-19T11:52:51Z")

</div>

Well, of course. Your row must fit the where conditions as you mention in the forum post:

> <https://github.com/mautic/mautic/blob/a8c2f81324462f73d4192ab19dc43890683d2e7e/app/bundles/CoreBundle/Entity/AuditLogRepository.php#L56>

It should only show changes to the lead object. If it’s related to another object then it shouldn’t show up in the lead audit log. I’d re-consider if the entry shouldn’t show up in the timeline as that’s where all events related to the contact show up. But you know better what your use case is.

---

<div class="post-metadata">

**Author:** ![peter\_k](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/peter_k/32/511_2.png) [@peter\_k](https://forum.mautic.org/u/peter_k)\
**Post date:** [January 19, 2024, 12:54pm UTC](https://forum.mautic.org/t/how-to-hook-into-the-lead-audit-log/30538/7 "2024-01-19T12:54:00Z")

</div>

> [@escopecz](#):
>
> It should only show changes to the lead object. If it’s related to another object then it shouldn’t show up in the lead audit log. I’d re-consider if the entry shouldn’t show up in the timeline as that’s where all events related to the contact show up. But you know better what your use case is.

Gotcha. I had a wrong conception of the audit log.

I’ll figure out if a timeline entry is more fitting or changing this to lead event type, so it shows up in the audit log.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex020/uploads/mautic/original/1X/43c63600fe51440378769136903f1fa2a9a34102.png) [@system](https://forum.mautic.org/u/system)\
**Post date:** [January 21, 2024, 12:54am UTC](https://forum.mautic.org/t/how-to-hook-into-the-lead-audit-log/30538/8 "2024-01-21T00:54:29Z")

</div>

This topic was automatically closed 36 hours after the last reply. New replies are no longer allowed.
