In an extension, what is the best way to create a DB table that has a matching logging table? Do we just have to literally create a matching new table with triggers?

There must be a better way?

3 Answers 3


I happen to be doing this in an extension at the moment... I had the table created normally and stuck

  // Make sure the log table is created if required
  $schema = new CRM_Logging_Schema();

at the end of the civicrm_enable hook. Unless I take care of this, if I install the extension with logging already enabled and try to create one of my new entity with drush right away, I get an error about the log table not existing.


Per Lobo's comment - the logging triggers & tables are automatically created. But, from experience sometimes you have to turn logging off & on to get the tables created. The triggers seem to create & cause lots of errors which stop when you turn logging off & on.

Obviously the function called by turning logging on is more thorough than the enable extension function


All tables that start with "civicrm_" are logged. tables with _temp and _cache in their names are skipped (and a few other tables).

You can check the code at CRM/Logging/Schema.php

Might be good to consider using hook(s) in multiple places so extensions can add to the list of tables to be logged and excluded

Your Answer

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

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