Question

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?

Was it helpful?

Solution

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>
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top