1

I'm trying to find out how to add custom event logging in the Magento 2 admin to log actions taken by our employees.

One of the reasons we've upgraded to the Enterprise edition is the addition of action logs, therefore I'd like to implement custom logging events, but I have no clue how to use it. Is there anyone out there who tried to do custom logging of actions?

Example:

One of our sales people updated one of the supplier's information, I'd like to see who did it on the next page:

<domain>/admin/admin/logging/index

How can I implement custom action logging?

2 Answers 2

7

It is possible to simply add Admin Logging to a module by adding a logging.xml and declare a group and afterwards enable this group in the configuration.

Stores > Settings > Configuration > Advanced > Admin > Admin Action Logs > Your Group Name

If you add a new one it will be disabled by default

Example of a logging.xml

<?xml version="1.0"?>
<!--
/**
 * Copyright © 2016 Magento. All rights reserved.
 * See COPYING.txt for license details.
 */
-->
<logging xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Logging:etc/logging.xsd">
    <groups>
        <group name="group_identifier_here">
            <label translate="true">Action Group Label here</label>
            <expected_models>
                <expected_model class="Vendor\Module\Model\Class" />
            </expected_models>
            <events>
                <event controller_action="fullcontroller_actionname_here_save" action_alias="save" />
                <event controller_action="fullcontroller_actionname_here_delete"
                       action_alias="delete" />
            </events>
        </group>
    </groups>
</logging>
2
  • Thanks for the answer, this was the solution! Actually quite a nice solution, I thought it'd be a lot tougher.
    – Merijn
    Commented Aug 31, 2017 at 6:53
  • Thank you for your answer! is there any way we can enable our custom action Group ? Commented Mar 8, 2023 at 13:18
0

app/code/Vendor/AdminLog/etc/logging.xml - you need to put code in logging.xml -Thanks

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.