If you want such a generic solution, the REST Services module contains a Java action serializeObjectToJson which turns any object into a JSON string. You can easily write this string to a log.
Take a look at this module: https://appstore.home.mendix.com/link/app/138/Mendix/Audittrail
Regards,
Ronald