Lmod provides official support for tracking module usage via the system log. The lmod-ingest utility is used to ingest the resulting syslog entries into a Postgres database. See the project documentation for more details.
lmod-ingest